Bug 159765 - REGRESSION(r202975): --minimal build is broken
Summary: REGRESSION(r202975): --minimal build is broken
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks: 159461
  Show dependency treegraph
 
Reported: 2016-07-14 08:09 PDT by Csaba Osztrogonác
Modified: 2016-07-18 11:48 PDT (History)
13 users (show)

See Also:


Attachments
Patch (14.05 KB, patch)
2016-07-14 08:23 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (14.20 KB, patch)
2016-07-14 10:46 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (18.01 KB, patch)
2016-07-18 10:24 PDT, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Csaba Osztrogonác 2016-07-14 08:09:19 PDT
DerivedSources/WebCore/WebCoreJSBuiltinInternals.cpp:125:103: error: no matching function for call to 'ArrayLengthHelperFunction(JSC::JSGlobalObject::GlobalPropertyInfo [0])'
In file included from ../../Source/WTF/wtf/FastMalloc.h:26:0,
                 from ../../Source/WebCore/config.h:75,
                 from DerivedSources/WebCore/WebCoreJSBuiltinInternals.cpp:36:
../../Source/WTF/wtf/StdLibExtras.h:172:42: note: candidate: template<class T, long unsigned int Size> char (& WTF::ArrayLengthHelperFunction(T (&)[Size]))[Size]
../../Source/WTF/wtf/StdLibExtras.h:172:42: note:   template argument deduction/substitution failed:
../../Source/WTF/wtf/StdLibExtras.h:175:29: note: candidate: template<class T> char (& WTF::ArrayLengthHelperFunction(T (&)[0]))[0]
../../Source/WTF/wtf/StdLibExtras.h:175:29: note:   template argument deduction/substitution failed:
DerivedSources/WebCore/WebCoreJSBuiltinInternals.cpp:125:103: note:   template argument '-1' does not match '#'integer_cst' not supported by dump_decl#<declaration error>'


preprocessed DerivedSources/WebCore/WebCoreJSBuiltinInternals.cpp:
-------------------------------------------------------------------
....
    JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {
    };
    globalObject.addStaticGlobals(staticGlobals, sizeof(::WTF::ArrayLengthHelperFunction(staticGlobals)));
....

It seems the new script doesn't handle empty staticGlobals[] properly.
I don't know anything about this code path and don't plan to fix it
myself, I just reported to let you know this build break.
Comment 1 youenn fablet 2016-07-14 08:16:45 PDT
Thanks I'll check that today or tomorrow.

(In reply to comment #0)
> DerivedSources/WebCore/WebCoreJSBuiltinInternals.cpp:125:103: error: no
> matching function for call to
> 'ArrayLengthHelperFunction(JSC::JSGlobalObject::GlobalPropertyInfo [0])'
> In file included from ../../Source/WTF/wtf/FastMalloc.h:26:0,
>                  from ../../Source/WebCore/config.h:75,
>                  from
> DerivedSources/WebCore/WebCoreJSBuiltinInternals.cpp:36:
> ../../Source/WTF/wtf/StdLibExtras.h:172:42: note: candidate: template<class
> T, long unsigned int Size> char (& WTF::ArrayLengthHelperFunction(T
> (&)[Size]))[Size]
> ../../Source/WTF/wtf/StdLibExtras.h:172:42: note:   template argument
> deduction/substitution failed:
> ../../Source/WTF/wtf/StdLibExtras.h:175:29: note: candidate: template<class
> T> char (& WTF::ArrayLengthHelperFunction(T (&)[0]))[0]
> ../../Source/WTF/wtf/StdLibExtras.h:175:29: note:   template argument
> deduction/substitution failed:
> DerivedSources/WebCore/WebCoreJSBuiltinInternals.cpp:125:103: note:  
> template argument '-1' does not match '#'integer_cst' not supported by
> dump_decl#<declaration error>'
> 
> 
> preprocessed DerivedSources/WebCore/WebCoreJSBuiltinInternals.cpp:
> -------------------------------------------------------------------
> ....
>     JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {
>     };
>     globalObject.addStaticGlobals(staticGlobals,
> sizeof(::WTF::ArrayLengthHelperFunction(staticGlobals)));
> ....
> 
> It seems the new script doesn't handle empty staticGlobals[] properly.
> I don't know anything about this code path and don't plan to fix it
> myself, I just reported to let you know this build break.
Comment 2 youenn fablet 2016-07-14 08:23:06 PDT
Created attachment 283643 [details]
Patch
Comment 3 WebKit Commit Bot 2016-07-14 08:24:23 PDT
This patch modifies the JS builtins code generator. Please ensure that you have rebaselined any generator test results (i.e., by running `Tools/Scripts/run-builtins-generator-tests --reset-results`)
Comment 4 Csaba Osztrogonác 2016-07-14 09:26:49 PDT
Comment on attachment 283643 [details]
Patch

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

> Source/JavaScriptCore/Scripts/builtins/builtins_generate_internals_wrapper_implementation.py:136
> -        lines.append("    globalObject.addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));")
> +        lines.append("    if (sizeof(staticGlobals))")
> +        lines.append("        globalObject.addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));")

It doesn't fix the build, error is error inside if too.
Comment 5 youenn fablet 2016-07-14 10:44:42 PDT
Let's backup with sizeof then.
Comment 6 youenn fablet 2016-07-14 10:46:46 PDT
Created attachment 283660 [details]
Patch
Comment 7 Alex Christensen 2016-07-14 13:31:40 PDT
There's a comment in the definition of WTF_ARRAY_LENGTH saying it supports 0-length arrays.  Why doesn't it work in this case?
Comment 8 youenn fablet 2016-07-14 13:49:23 PDT
Didn't have the time to investigate further. I added a fixme in the generator to do follow on this.
Comment 9 Csaba Osztrogonác 2016-07-18 05:07:24 PDT
just a note, I got the same error with clang 3.8: (without the fix)

DerivedSources/WebCore/WebCoreJSBuiltinInternals.cpp:125:50: error: no matching function for call to 'ArrayLengthHelperFunction'
    globalObject.addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../Source/WTF/wtf/StdLibExtras.h:177:40: note: expanded from macro 'WTF_ARRAY_LENGTH'
#define WTF_ARRAY_LENGTH(array) sizeof(::WTF::ArrayLengthHelperFunction(array))
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../Source/WTF/wtf/StdLibExtras.h:172:42: note: candidate template ignored: substitution failure [with T = JSC::JSGlobalObject::GlobalPropertyInfo, Size = 0]: zero-length arrays are not permitted in C++
template<typename T, size_t Size> char (&ArrayLengthHelperFunction(T (&)[Size]))[Size];
                                         ^                                       ~~~~
../../Source/WTF/wtf/StdLibExtras.h:175:29: note: candidate template ignored: substitution failure [with T = JSC::JSGlobalObject::GlobalPropertyInfo]: zero-length arrays are not permitted in C++
template<typename T> char (&ArrayLengthHelperFunction(T (&)[0]))[0];
                            ^                              ~
Comment 10 Csaba Osztrogonác 2016-07-18 05:11:27 PDT
(In reply to comment #7)
> There's a comment in the definition of WTF_ARRAY_LENGTH saying it supports
> 0-length arrays.  Why doesn't it work in this case?

It is a 4 years old comment - https://trac.webkit.org/changeset/114042/trunk/Source/WTF/wtf/StdLibExtras.h

Maybe GCC/Clang change a little bit since then.
Comment 11 Chris Dumez 2016-07-18 09:30:45 PDT
Comment on attachment 283660 [details]
Patch

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

> Source/JavaScriptCore/Scripts/tests/builtins/expected/WebCore-ArbitraryConditionalGuard-Separate.js-result:403
>      JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {

Why do we generate such code at all? Seems to me we should not generate empty arrays.
Comment 12 Alexey Proskuryakov 2016-07-18 09:32:21 PDT
Comment on attachment 283660 [details]
Patch

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

> Source/JavaScriptCore/Scripts/builtins/builtins_generate_internals_wrapper_implementation.py:135
> +        # FIXME: We should use WTF_ARRAY_LENGTH here but it fails on zero-length arrays.

Would the below work?

// Macro that returns a compile time constant with the length of an array, but gives an error if passed a non-array.
template<typename T, size_t Size> char (&ArrayLengthHelperFunction(T (&)[Size]))[Size];
// GCC needs some help to deduce a 0 length array.
-#if COMPILER(GCC_OR_CLANG)
+#if COMPILER(GCC)
template<typename T> char (&ArrayLengthHelperFunction(T (&)[0]))[0];
#endif
#define WTF_ARRAY_LENGTH(array) sizeof(::WTF::ArrayLengthHelperFunction(array))
Comment 13 youenn fablet 2016-07-18 09:32:55 PDT
(In reply to comment #11)
> Comment on attachment 283660 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=283660&action=review
> 
> > Source/JavaScriptCore/Scripts/tests/builtins/expected/WebCore-ArbitraryConditionalGuard-Separate.js-result:403
> >      JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {
> 
> Why do we generate such code at all? Seems to me we should not generate
> empty arrays.

The issue is that arrays are not empty except they have entries that are #ifdefed.
In that case, the generator cannot know beforehand whether array is empty or not.
Comment 14 Chris Dumez 2016-07-18 09:34:10 PDT
(In reply to comment #13)
> (In reply to comment #11)
> > Comment on attachment 283660 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=283660&action=review
> > 
> > > Source/JavaScriptCore/Scripts/tests/builtins/expected/WebCore-ArbitraryConditionalGuard-Separate.js-result:403
> > >      JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {
> > 
> > Why do we generate such code at all? Seems to me we should not generate
> > empty arrays.
> 
> The issue is that arrays are not empty except they have entries that are
> #ifdefed.
> In that case, the generator cannot know beforehand whether array is empty or
> not.

It can if you add the right #ifdefs outside the array declaration.
e.g.
#if ENABLE(...) || ENABLE(...)
//declare array
// add globals
#endif
Comment 15 Chris Dumez 2016-07-18 09:37:53 PDT
(In reply to comment #14)
> (In reply to comment #13)
> > (In reply to comment #11)
> > > Comment on attachment 283660 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=283660&action=review
> > > 
> > > > Source/JavaScriptCore/Scripts/tests/builtins/expected/WebCore-ArbitraryConditionalGuard-Separate.js-result:403
> > > >      JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {
> > > 
> > > Why do we generate such code at all? Seems to me we should not generate
> > > empty arrays.
> > 
> > The issue is that arrays are not empty except they have entries that are
> > #ifdefed.
> > In that case, the generator cannot know beforehand whether array is empty or
> > not.
> 
> It can if you add the right #ifdefs outside the array declaration.
> e.g.
> #if ENABLE(...) || ENABLE(...)
> //declare array
> // add globals
> #endif

JSGlobalObject::addStaticGlobals() is not inlined and therefore we generate a function call for no reason in such cases.
Comment 16 youenn fablet 2016-07-18 09:39:15 PDT
(In reply to comment #14)
> (In reply to comment #13)
> > (In reply to comment #11)
> > > Comment on attachment 283660 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=283660&action=review
> > > 
> > > > Source/JavaScriptCore/Scripts/tests/builtins/expected/WebCore-ArbitraryConditionalGuard-Separate.js-result:403
> > > >      JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {
> > > 
> > > Why do we generate such code at all? Seems to me we should not generate
> > > empty arrays.
> > 
> > The issue is that arrays are not empty except they have entries that are
> > #ifdefed.
> > In that case, the generator cannot know beforehand whether array is empty or
> > not.
> 
> It can if you add the right #ifdefs outside the array declaration.
> e.g.
> #if ENABLE(...) || ENABLE(...)
> //declare array
> // add globals
> #endif

When shipping the fix, we thought that it was not worth the effort to do that.
Maybe we should...
I will prepare a patch accordingly.

> template<typename T, size_t Size> char (&ArrayLengthHelperFunction(T
> (&)[Size]))[Size];
> // GCC needs some help to deduce a 0 length array.
> -#if COMPILER(GCC_OR_CLANG)
> +#if COMPILER(GCC)
> template<typename T> char (&ArrayLengthHelperFunction(T (&)[0]))[0];
> #endif
> #define WTF_ARRAY_LENGTH(array)
> sizeof(::WTF::ArrayLengthHelperFunction(array))

I think I tried and I don't think it was working.
Comment 17 Csaba Osztrogonác 2016-07-18 09:53:40 PDT
(In reply to comment #12)
> Comment on attachment 283660 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=283660&action=review
> 
> > Source/JavaScriptCore/Scripts/builtins/builtins_generate_internals_wrapper_implementation.py:135
> > +        # FIXME: We should use WTF_ARRAY_LENGTH here but it fails on zero-length arrays.
> 
> Would the below work?
> 
> // Macro that returns a compile time constant with the length of an array,
> but gives an error if passed a non-array.
> template<typename T, size_t Size> char (&ArrayLengthHelperFunction(T
> (&)[Size]))[Size];
> // GCC needs some help to deduce a 0 length array.
> -#if COMPILER(GCC_OR_CLANG)
> +#if COMPILER(GCC)
> template<typename T> char (&ArrayLengthHelperFunction(T (&)[0]))[0];
> #endif
> #define WTF_ARRAY_LENGTH(array)
> sizeof(::WTF::ArrayLengthHelperFunction(array))

No, zero sized arrays are broken with Clang and GCC too
with and without ifdef-ed workaround.
Comment 18 Alexey Proskuryakov 2016-07-18 10:10:52 PDT
Given that, the broken workaround should be removed. I agree that fixing WTF_ARRAY_LENGTH is not the best fix for this bug, as we'd have an unneeded function call.
Comment 19 youenn fablet 2016-07-18 10:24:52 PDT
Created attachment 283914 [details]
Patch
Comment 20 Chris Dumez 2016-07-18 10:30:34 PDT
Comment on attachment 283914 [details]
Patch

r=me as long as the bots are happy.
Comment 21 BJ Burg 2016-07-18 10:31:56 PDT
Comment on attachment 283914 [details]
Patch

LGTM too. A test case for a builtin with multiple conditionals would be good to add.
Comment 22 youenn fablet 2016-07-18 10:36:38 PDT
(In reply to comment #21)
> Comment on attachment 283914 [details]
> Patch
> 
> LGTM too. A test case for a builtin with multiple conditionals would be good
> to add.

Yes, we should extend the builtin generator test script to take multiple files at once and concatenate the results, or just output the wrapper files.
Comment 23 Radar WebKit Bug Importer 2016-07-18 11:09:40 PDT
<rdar://problem/27405849>
Comment 24 WebKit Commit Bot 2016-07-18 11:47:56 PDT
Comment on attachment 283914 [details]
Patch

Clearing flags on attachment: 283914

Committed r203353: <http://trac.webkit.org/changeset/203353>
Comment 25 WebKit Commit Bot 2016-07-18 11:48:03 PDT
All reviewed patches have been landed.  Closing bug.