Bug 59261 - Compile error with GCC 4.6.0, tries to assign unsigned& to bitfield
Summary: Compile error with GCC 4.6.0, tries to assign unsigned& to bitfield
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-22 17:36 PDT by Xan Lopez
Modified: 2011-05-04 12:59 PDT (History)
3 users (show)

See Also:


Attachments
unaryplus.diff (4.77 KB, patch)
2011-04-22 17:41 PDT, Xan Lopez
no flags Details | Formatted Diff | Diff
Patch for landing (4.15 KB, patch)
2011-05-03 06:21 PDT, Alexis Menard (darktears)
andersca: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Xan Lopez 2011-04-22 17:36:13 PDT
When compiling JSC with GCC 4.6.0:

  CXX    Source/JavaScriptCore/API/libJavaScriptCore_la-JSBase.lo
In file included from ../../Source/JavaScriptCore/runtime/ScopeChain.h:25:0,
                 from ../../Source/JavaScriptCore/runtime/JSObject.h:35,
                 from ../../Source/JavaScriptCore/runtime/JSArray.h:24,
                 from ../../Source/JavaScriptCore/runtime/JSGlobalObject.h:25,
                 from ../../Source/JavaScriptCore/runtime/JSObjectWithGlobalObject.h:29,
                 from ../../Source/JavaScriptCore/runtime/JSFunction.h:27,
                 from ../../Source/JavaScriptCore/runtime/Executable.h:30,
                 from ../../Source/JavaScriptCore/bytecode/EvalCodeCache.h:32,
                 from ../../Source/JavaScriptCore/bytecode/CodeBlock.h:33,
                 from ../../Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:33,
                 from ../../Source/JavaScriptCore/jsc.cpp:25:
../../Source/JavaScriptCore/runtime/Structure.h: In static member function ‘static JSC::StructureTransitionTable::Hash::Key JSC::StructureTransitionTable::keyForWeakGCMapFinalizer(void*, JSC::Structure*)’:
../../Source/JavaScriptCore/runtime/Structure.h:301:94: error: cannot bind bitfield ‘structure->JSC::Structure::m_attributesInPrevious’ to ‘unsigned int&’

the reason for this is explained in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45253, but basically comes down to GCC not being able to fully figure the type of the parameter and defaulting to 'unsigned&', which cannot be assigned to a bitfield. As this seems to be technically correct, and GCC is already doing it, the workaround suggested in the upstream bug report is to use unary '+' to force a proper type detection. The attached patch does this.
Comment 1 Xan Lopez 2011-04-22 17:41:53 PDT
Created attachment 90814 [details]
unaryplus.diff
Comment 2 Alexey Proskuryakov 2011-04-22 21:52:14 PDT
Comment on attachment 90814 [details]
unaryplus.diff

View in context: https://bugs.webkit.org/attachment.cgi?id=90814&action=review

> Source/JavaScriptCore/runtime/Structure.cpp:103
> +        // Use unary '+' for m_attributesInPrevious to force precise
> +        // type detection with GCC >= 4.6.0. See
> +        // https://bugs.webkit.org/show_bug.cgi?id=59261 for more
> +        // details.

Can this be written in one line?

> Source/JavaScriptCore/runtime/Structure.cpp:132
> +    // Use unary '+' for m_attributesInPrevious to force precise
> +    // type detection with GCC >= 4.6.0. See
> +    // https://bugs.webkit.org/show_bug.cgi?id=59261 for more
> +    // details.

Ditto.

> Source/JavaScriptCore/runtime/Structure.h:304
> +        // Use unary '+' for m_attributesInPrevious to force precise
> +        // type detection with GCC >= 4.6.0. See
> +        // https://bugs.webkit.org/show_bug.cgi?id=59261 for more
> +        // details.

Ditto.
Comment 3 Xan Lopez 2011-04-25 16:20:47 PDT
(In reply to comment #2)
> (From update of attachment 90814 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=90814&action=review
> 
> > Source/JavaScriptCore/runtime/Structure.cpp:103
> > +        // Use unary '+' for m_attributesInPrevious to force precise
> > +        // type detection with GCC >= 4.6.0. See
> > +        // https://bugs.webkit.org/show_bug.cgi?id=59261 for more
> > +        // details.
> 
> Can this be written in one line?
> 

Wouldn't that be a lot more difficult to read? No other comment in the file seems to do this when they are long-ish. Are you asking because of the weird line-breaks and the bugzilla URL?
Comment 4 Eric Seidel (no email) 2011-04-26 15:20:23 PDT
@ap, please r+ or r-.
Comment 5 Alexey Proskuryakov 2011-04-26 15:23:59 PDT
static_cast would be my preference, but let's see what Anders or Darin think.
Comment 6 Anders Carlsson 2011-04-26 15:38:12 PDT
Comment on attachment 90814 [details]
unaryplus.diff

The patch looks correct, but I'd prefer a more generic comment; you'll get this error with any compiler whose standard library has an std::make_pair implementation that takes value references. How about something like:

// Newer versions of the STL have an std::make_pair function that takes rvalue references.
// When either of the parameters are bitfields, the C++ compiler will try to bind them as lvalues, which is invalid. To work around this, use unary "+" to make the parameter an rvalue.
// See https://bugs.webkit.org/show_bug.cgi?id=59261 for more details.
Comment 7 Alexis Menard (darktears) 2011-05-03 06:21:47 PDT
Created attachment 92066 [details]
Patch for landing
Comment 8 Alexis Menard (darktears) 2011-05-03 10:34:34 PDT
Committed r85621: <http://trac.webkit.org/changeset/85621>