JDK-8033215 : clang: node.cpp:284 IDX_INIT macro use uninitialized field _out
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-01-30
  • Updated: 2020-02-21
  • Resolved: 2014-02-12
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 8 JDK 9 Other
8u251Fixed 9 b04Fixed openjdk8u252Fixed
Related Reports
Relates :  
Description
The error message as follows, every IDX_INIT called in the initialize list will cause this warning, and I cannot make sense out of the current code.

/home/hjen/ws/9dev/hotspot/src/share/vm/opto/node.cpp:326:10: error: field '_out' is uninitialized when used here [-Werror,-Wuninitialized]
  : _idx(IDX_INIT(req))
         ^
/home/hjen/ws/9dev/hotspot/src/share/vm/opto/node.cpp:284:58: note: expanded from macro 'IDX_INIT'
#define IDX_INIT(req) this->Init((req), (Compile*) this->_out)
                                                         ^                                                         ^

Comments
Not sure we even support building with Clang right now, but patch looks ok to go in.
25-01-2020

Fix request (8u) Needed for parity with Oracle 8u251. Syntax-only change, applies cleanly.
21-01-2020

Changing to using Compile::current() would clean up C2's code quite a bit because then it would look like: diff -r c84312468f5c src/share/vm/opto/mathexactnode.cpp --- a/src/share/vm/opto/mathexactnode.cpp Fri Jan 24 13:06:52 2014 +0100 +++ b/src/share/vm/opto/mathexactnode.cpp Wed Feb 05 18:03:55 2014 -0800 @@ -151,7 +151,7 @@ Node* AddExactINode::Ideal(PhaseGVN* pha } if (type1 == TypeInt::ZERO || type2 == TypeInt::ZERO) { // (Add 0 x) == x - Node* add_result = new (phase->C) AddINode(arg1, arg2); + Node* add_result = new AddINode(arg1, arg2); return no_overflow(phase, add_result); }
06-02-2014

Here is the experiment: diff -r c84312468f5c src/share/vm/opto/node.cpp --- a/src/share/vm/opto/node.cpp Fri Jan 24 13:06:52 2014 +0100 +++ b/src/share/vm/opto/node.cpp Wed Feb 05 18:00:53 2014 -0800 @@ -293,8 +293,9 @@ static void init_node_notes(Compile* C, } // Shared initialization code. -inline int Node::Init(int req, Compile* C) { - assert(Compile::current() == C, "must use operator new(Compile*)"); +inline int Node::Init(int req, Compile* Cx) { +// assert(Compile::current() == C, "must use operator new(Compile*)"); + Compile* C = Compile::current(); int idx = C->next_unique(); // Allocate memory for the necessary number of edges. diff -r c84312468f5c src/share/vm/opto/node.hpp --- a/src/share/vm/opto/node.hpp Fri Jan 24 13:06:52 2014 +0100 +++ b/src/share/vm/opto/node.hpp Wed Feb 05 18:00:53 2014 -0800 @@ -213,7 +213,8 @@ public: // New Operator that takes a Compile pointer, this will eventually // be the "new" New operator. - inline void* operator new( size_t x, Compile* C) throw() { + inline void* operator new( size_t x, Compile* Cx) throw() { + Compile* C = Compile::current(); Node* n = (Node*)C->node_arena()->Amalloc_D(x); #ifdef ASSERT n->_in = (Node**)n; // magic cookie for assertion check
06-02-2014

Vladimir and I talked about this and we did a quick experiment: instead of passing in the Compile* call Compile::current(). There was no measurable performance hit on a SPARC T4 and x86 should be fine anyway. So we are suggesting to push your fix now and we clean this part up later.
06-02-2014

I discussed with other members of our group and we decided to do clean of this code later. For now you can push your fix. Thank you!
06-02-2014

In general, I agree with you that compiler flag problem should be in makefile, not source code. However, in this particular case, it's the implementation of code cause such a warning. We don't want to disable the warning without a good reason, the proposed patch ensure we only disable the warning in place where the code is intended written this way and should have a good comment to explain why the warning is disabled. As such, this is also following the precedent for the msvc warning related to that piece of code.
06-02-2014

Something similar to next code in make/bsd/makefiles/gcc.make ifeq ($(OS_VENDOR), Darwin) CFLAGS_WARN/os_bsd.o = $(CFLAGS_WARN/DEFAULT) -Wno-deprecated-declarations endif
31-01-2014

Yes, it is by design. I am against putting in our code your changes. It is not our problem - it is problem of clang, only one of C++ compilers we use. Usually in such situations we modify make files/build scripts and not source code.
31-01-2014

Thanks for the pointer, I had read that code, and aware there are comment. // This funny expression handshakes with Node::operator new // to pull Compile::current out of the new node's _out field, // and then calls a subroutine which manages most field // initializations. The only one which is tricky is the // _idx field, which is const, and so must be initialized // by a return value, not an assignment. I take that this is by design, but nontheless, if we are sure this is what we do, we should disable the warning. If that's the case, the proposed patch seems to be the right solution to close this bug.
31-01-2014

Node's class operator new() (defined in node.hpp) initializes _out field: inline void* operator new( size_t x, Compile* C) throw() { Node* n = (Node*)C->node_arena()->Amalloc_D(x); #ifdef ASSERT n->_in = (Node**)n; // magic cookie for assertion check #endif n->_out = (Node**)C; return (void*)n; } Please, provide more information if you think it is still problem. Otherwise, please, close this bug.
31-01-2014

Following patch disables the warning before a proper solution is developed. # HG changeset patch # Parent 19537cc1a19be3a5f781260c36598c4451d85557 diff -r 19537cc1a19b src/share/vm/opto/node.cpp --- a/src/share/vm/opto/node.cpp Wed Jan 29 17:10:09 2014 -0800 +++ b/src/share/vm/opto/node.cpp Wed Jan 29 17:11:50 2014 -0800 @@ -285,6 +285,10 @@ #ifdef _MSC_VER // the IDX_INIT hack falls foul of warning C4355 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list #endif +#ifdef __clang__ +#pragma clang diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#endif // Out-of-line code from node constructors. // Executed only when extra debug info. is being passed around. @@ -468,6 +472,10 @@ _in[6] = n6; if (n6 != NULL) n6->add_out((Node *)this); } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + //------------------------------clone------------------------------------------ // Clone a Node.
30-01-2014