JDK-8307147 : [x86] Dangling pointer warning for Assembler::_attributes
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,17,20,21
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • CPU: x86
  • Submitted: 2023-04-30
  • Updated: 2023-08-07
  • Resolved: 2023-05-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17 JDK 21
17.0.10-oracleFixed 21 b22Fixed
Related Reports
Relates :  
Relates :  
Description
When compiling with gcc13.1 for release we get some -Wdangling-pointer warnings like this (earlier versions of gcc don't warn):

In member function 'void Assembler::set_attributes(InstructionAttr*)',
    inlined from 'int Assembler::vex_prefix_and_encode(int, int, int, VexSimdPrefix, VexOpcode, InstructionAttr*)' at ../../src/hotspot/cpu/x86/assembler_x86.cpp:11491:17,
    inlined from 'void Assembler::vpclmulqdq(XMMRegister, XMMRegister, XMMRegister, int)' at ../../src/hotspot/cpu/x86/assembler_x86.cpp:10823:37:
../../src/hotspot/cpu/x86/assembler_x86.hpp:921:66: warning: storing the address of local variable 'attributes' in '*this.Assembler::_attributes' [-Wdangling-pointer=]
  921 |   void set_attributes(InstructionAttr *attributes) { _attributes = attributes; }
      |                                                      ~~~~~~~~~~~~^~~~~~~~~~~~
../../src/hotspot/cpu/x86/assembler_x86.cpp: In member function 'void Assembler::vpclmulqdq(XMMRegister, XMMRegister, XMMRegister, int)':
../../src/hotspot/cpu/x86/assembler_x86.cpp:10822:19: note: 'attributes' declared here
10822 |   InstructionAttr attributes(AVX_128bit, /* vex_w */ false, /* legacy_mode */ true, /* no_mask_reg */ true, /* uses_vl */ true);
      |                   ^~~~~~~~~~
../../src/hotspot/cpu/x86/assembler_x86.cpp:10820:87: note: 'this' declared here
10820 | void Assembler::vpclmulqdq(XMMRegister dst, XMMRegister nds, XMMRegister src, int mask) {
      |                                                                                       ^

Some places set the _attributes member of the assembler. The attributes object's destructor checks for that situation and clears the assembler's _attributes. So we aren't leaving a dead object in the assembler to be accidentally used later, making this warning "harmless". Since the lifetime of the attributes object doesn't end until it's storage has been released, e.g. after it's destructor is invoked, the warning is a false positive.  However, the structure isn't helping by somewhat obfuscating what's being done.

Comments
Fix request 17u - allows building with GCC 13. Backport is nearly clean and only needs nullptr replaced with NULL. Passes jtreg tier1 and tier2
13-07-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/1575 Date: 2023-07-12 17:24:08 +0000
12-07-2023

Changeset: 3599448a Author: Kim Barrett <kbarrett@openjdk.org> Date: 2023-05-04 02:08:07 +0000 URL: https://git.openjdk.org/jdk/commit/3599448ad833553dd502a4f941dad7295b557d55
04-05-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/13751 Date: 2023-05-02 07:54:00 +0000
02-05-2023

ILW = Dangling pointer warning (harmless - false positive), with gcc13.1, no workaround = LLH = P5
02-05-2023

This looks somewhat similar to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106411 Weirdly, the documentation for `-Wdangling-pointer` seems to have disappeared in gcc13 - it's there in gcc12 (that seems to be the first version containing it, though there's no mention of that option in the release notes for gcc12).
01-05-2023