Bug 27869 - strict-aliasing warnings in JSFunction.h
: strict-aliasing warnings in JSFunction.h
Status: RESOLVED FIXED
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore
: 528+ (Nightly build)
: PC Linux
: P2 Normal
Assigned To: Nobody
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-07-31 00:32 PDT by Xan Lopez
Modified: 2009-10-28 13:19 PDT (History)
5 users (show)

See Also:


Attachments
aliasing.patch (3.14 KB, patch)
2009-07-31 00:32 PDT, Xan Lopez
no flags Details | Formatted Diff | Diff
Fix using bitwise_cast (2.49 KB, patch)
2009-10-24 08:51 PDT, Martin Robinson
oliver: 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 2009-07-31 00:32:26 PDT
Created attachment 33861 [details]
aliasing.patch

GCC gives me the following warnings when compiling with JSFunction.h:

In file included from ../../JavaScriptCore/runtime/JSFunction.cpp:27,
                 from ../../JavaScriptCore/AllInOneFile.cpp:36:
../../JavaScriptCore/runtime/JSFunction.h: In member function ‘JSC::JSValue (* JSC::JSFunction::nativeFunction())(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&)’:
../../JavaScriptCore/runtime/JSFunction.h:87: warning: dereferencing type-punned pointer will break strict-aliasing rules
../../JavaScriptCore/runtime/JSFunction.h: In member function ‘JSC::ScopeChain& JSC::JSFunction::scopeChain()’:
../../JavaScriptCore/runtime/JSFunction.h:104: warning: dereferencing type-punned pointer will break strict-aliasing rules
../../JavaScriptCore/runtime/JSFunction.h: In member function ‘void JSC::JSFunction::setScopeChain(const JSC::ScopeChain&)’:
../../JavaScriptCore/runtime/JSFunction.h:119: warning: dereferencing type-punned pointer will break strict-aliasing rules
../../JavaScriptCore/runtime/JSFunction.h: In member function ‘void JSC::JSFunction::setNativeFunction(JSC::JSValue (*)(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&))’:
../../JavaScriptCore/runtime/JSFunction.h:123: warning: dereferencing type-punned pointer will break strict-aliasing rules

The problem is that we are accessing a char array as NativeFunction* and ScopeChain*, which GCC deems to be incompatible pointers. Attached is the usual trick-solution for this, which is to use a union type and do all memory access through there. This was done with the help of Maciej on IRC, and he also suggested that we could do further cleanups here, so I'm attaching my current patch for discussion.
Comment 1 Xan Lopez 2009-07-31 00:33:49 PDT
Actually, just looking at the patch now, the array member in the union is not needed anymore (it was used in previous iterations of the patch).
Comment 2 Xan Lopez 2009-07-31 02:47:49 PDT
Comment on attachment 33861 [details]
aliasing.patch

This seems to introduce a crash in the JSFunction destructor (which calls the ScopeChain destructor). Maciej suggested something like this could happen, so this needs further investigation. Removing from the queue.
Comment 3 Martin Robinson 2009-10-24 08:51:30 PDT
Created attachment 41781 [details]
Fix using bitwise_cast

Seems that using bitwise_cast fixes these compiler warnings.
Comment 4 Geoffrey Garen 2009-10-26 15:12:43 PDT
Strange to see this warning. char* is supposed to be able to alias to anything, even under -fstrict-aliasing.
Comment 5 Geoffrey Garen 2009-10-26 15:13:11 PDT
Can you run SunSpider before and after this patch and post the results?
Comment 6 Oliver Hunt 2009-10-28 13:19:49 PDT
Committed r50232