<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>144378</bug_id>
          
          <creation_ts>2015-04-28 23:57:50 -0700</creation_ts>
          <short_desc>LazyNeverDestroyed is not thread safe in debug builds, causing assertions</short_desc>
          <delta_ts>2025-08-26 05:23:37 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Template Framework</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alexey Proskuryakov">ap</reporter>
          <assigned_to name="Alexey Proskuryakov">ap</assigned_to>
          <cc>andersca</cc>
    
    <cc>benjamin</cc>
    
    <cc>cdumez</cc>
    
    <cc>cmarcelo</cc>
    
    <cc>commit-queue</cc>
    
    <cc>kling</cc>
    
    <cc>zan</cc>
    
    <cc>zimmermann</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1089910</commentid>
    <comment_count>0</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2015-04-28 23:57:50 -0700</bug_when>
    <thetext>Thread 28 Crashed:: WebCore: Worker
0   com.apple.JavaScriptCore      	0x00000001128509da WTFCrash + 42 (Assertions.cpp:321)

ASSERT(m_isConstructed);

1   com.apple.JavaScriptCore      	0x0000000112862ed2 WTF::LazyNeverDestroyed&lt;std::__1::mutex&gt;::asPtr() + 66 (NeverDestroyed.h:102)
2   com.apple.JavaScriptCore      	0x0000000112862e85 WTF::LazyNeverDestroyed&lt;std::__1::mutex&gt;::operator std::__1::mutex&amp;() + 21 (NeverDestroyed.h:94)
3   com.apple.JavaScriptCore      	0x0000000112862161 WTF::cachedCollatorMutex() + 577 (CollatorICU.cpp:62)
4   com.apple.JavaScriptCore      	0x0000000112861c8b WTF::Collator::Collator(char const*, bool) + 43 (CollatorICU.cpp:120)
5   com.apple.JavaScriptCore      	0x0000000112861c4c WTF::Collator::Collator(char const*, bool) + 44 (CollatorICU.cpp:146)
6   com.apple.JavaScriptCore      	0x0000000112788a4b JSC::stringProtoFuncLocaleCompare(JSC::ExecState*) + 155 (StringPrototype.cpp:1429)

LazyNeverDestroyed has a non-trivial constructor in debug builds, which is obviously wrong to have for the pattern we normally use it with.

static std::mutex&amp; cachedCollatorMutex()
{
    static std::once_flag onceFlag;

    static LazyNeverDestroyed&lt;std::mutex&gt; mutex;
    std::call_once(onceFlag, []{
        mutex.construct();
    });

    return mutex;
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1089940</commentid>
    <comment_count>1</comment_count>
    <who name="Zan Dobersek">zan</who>
    <bug_when>2015-04-29 02:40:36 -0700</bug_when>
    <thetext>Removing the brace initializer for the m_isConstructed member will make it trivial again.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1090044</commentid>
    <comment_count>2</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2015-04-29 10:09:02 -0700</bug_when>
    <thetext>Yes, this class is only used for static variables. I don&apos;t know of a way to assert that though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1090123</commentid>
    <comment_count>3</comment_count>
      <attachid>251979</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2015-04-29 12:39:23 -0700</bug_when>
    <thetext>Created attachment 251979
proposed fix</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1090326</commentid>
    <comment_count>4</comment_count>
      <attachid>251979</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-04-29 20:06:53 -0700</bug_when>
    <thetext>Comment on attachment 251979
proposed fix

Clearing flags on attachment: 251979

Committed r183608: &lt;http://trac.webkit.org/changeset/183608&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1090327</commentid>
    <comment_count>5</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-04-29 20:07:03 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2138785</commentid>
    <comment_count>6</comment_count>
    <who name="Nikolas Zimmermann">zimmermann</who>
    <bug_when>2025-08-26 05:23:37 -0700</bug_when>
    <thetext>10 years later this has hit me:

```
Yes, this class is only used for static variables. I don&apos;t know of a way to assert that though.
```

I&apos;m building WebKit with gcc-14, and it complains:

```
unified-sources/UnifiedSource-2f84417a-14.cpp
In file included from /host/home/nzimmermann/Software/GitRepositories/WebKit/WebKitBuild/WPE/Release/WTF/Headers/wtf/MallocCommon.h:28,
                 from /host/home/nzimmermann/Software/GitRepositories/WebKit/WebKitBuild/WPE/Release/WTF/Headers/wtf/FastMalloc.h:26,
                 from /host/home/nzimmermann/Software/GitRepositories/WebKit/Source/WebCore/config.h:47,
                 from /host/home/nzimmermann/Software/GitRepositories/WebKit/Source/WebCore/css/CSSValue.cpp:29,
                 from /host/home/nzimmermann/Software/GitRepositories/WebKit/WebKitBuild/WPE/Release/WebCore/DerivedSources/unified-sources/UnifiedSource-2f84417a-14.cpp:1:
In member function ‘void WTF::LazyNeverDestroyed&lt; &lt;template-parameter-1-1&gt;, &lt;template-parameter-1-2&gt; &gt;::constructWithoutAccessCheck(Args&amp;&amp; ...) [with Args = {WebCore::CSSValue::StaticCSSValueTag, WebCore::CSSPrimitiveValue::ImplicitInitialValueTag}; T = WebCore::CSSPrimitiveValue; AccessTraits = WTF::AnyThreadsAccessTraits]’,
    inlined from ‘void WTF::LazyNeverDestroyed&lt; &lt;template-parameter-1-1&gt;, &lt;template-parameter-1-2&gt; &gt;::construct(Args&amp;&amp; ...) [with Args = {WebCore::CSSValue::StaticCSSValueTag, WebCore::CSSPrimitiveValue::ImplicitInitialValueTag}; T = WebCore::CSSPrimitiveValue; AccessTraits = WTF::AnyThreadsAccessTraits]’ at /host/home/nzimmermann/Software/GitRepositories/WebKit/WebKitBuild/WPE/Release/WTF/Headers/wtf/NeverDestroyed.h:128:36,
    inlined from ‘WebCore::StaticCSSValuePool::StaticCSSValuePool()’ at /host/home/nzimmermann/Software/GitRepositories/WebKit/Source/WebCore/css/CSSValuePool.cpp:41:37:
/host/home/nzimmermann/Software/GitRepositories/WebKit/WebKitBuild/WPE/Release/WTF/Headers/wtf/NeverDestroyed.h:134:17: error: ‘*(WTF::LazyNeverDestroyed&lt;WebCore::CSSPrimitiveValue, WTF::AnyThreadsAccessTraits&gt;*)this.WTF::LazyNeverDestroyed&lt;WebCore::CSSPrimitiveValue&gt;::m_isConstructed’ is used uninitialized [-Werror=uninitialized]
  134 |         ASSERT(!m_isConstructed);
      |                 ^~~~~~~~~~~~~~~
/host/home/nzimmermann/Software/GitRepositories/WebKit/WebKitBuild/WPE/Release/WTF/Headers/wtf/Assertions.h:384:58: note: in definition of macro ‘UNLIKELY_FOR_C_ASSERTIONS’
  384 | #define UNLIKELY_FOR_C_ASSERTIONS(x) __builtin_expect(!!(x), 0)
      |                                                          ^
/host/home/nzimmermann/Software/GitRepositories/WebKit/WebKitBuild/WPE/Release/WTF/Headers/wtf/NeverDestroyed.h:134:9: note: in expansion of macro ‘ASSERT’
  134 |         ASSERT(!m_isConstructed);
      |         ^~~~~~
cc1plus: all warnings being treated as errors
```

That is because (Static)CSSValuePool is actually using non-static LazyNeverDestroyed objects (stored as members). While StaticCSSValuePool - as the name implies - is static itself, its members aren&apos;t and gcc caught that. Any ideas?</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>251979</attachid>
            <date>2015-04-29 12:39:23 -0700</date>
            <delta_ts>2015-04-29 20:06:53 -0700</delta_ts>
            <desc>proposed fix</desc>
            <filename>LazyNeverDestroyed.txt</filename>
            <type>text/plain</type>
            <size>1128</size>
            <attacher name="Alexey Proskuryakov">ap</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XVEYvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFNvdXJjZS9XVEYvQ2hh
bmdlTG9nCShyZXZpc2lvbiAxODM1NjYpCisrKyBTb3VyY2UvV1RGL0NoYW5nZUxvZwkod29ya2lu
ZyBjb3B5KQpAQCAtMSwzICsxLDEyIEBACisyMDE1LTA0LTI5ICBBbGV4ZXkgUHJvc2t1cnlha292
ICA8YXBAYXBwbGUuY29tPgorCisgICAgICAgIExhenlOZXZlckRlc3Ryb3llZCBpcyBub3QgdGhy
ZWFkIHNhZmUgaW4gZGVidWcgYnVpbGRzLCBjYXVzaW5nIGFzc2VydGlvbnMKKyAgICAgICAgaHR0
cHM6Ly9idWdzLndlYmtpdC5vcmcvc2hvd19idWcuY2dpP2lkPTE0NDM3OAorCisgICAgICAgIFJl
dmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAgICogd3RmL05ldmVyRGVzdHJveWVk
Lmg6CisKIDIwMTUtMDQtMjkgIE15bGVzIEMuIE1heGZpZWxkICA8bW1heGZpZWxkQGFwcGxlLmNv
bT4KIAogICAgICAgICBbT1MgWF0gVXNlIENURm9udENyZWF0ZUZvckNTUyBpbnN0ZWFkIG9mIGRv
aW5nIGZvbnQgc2VhcmNoIG91cnNlbHZlcwpJbmRleDogU291cmNlL1dURi93dGYvTmV2ZXJEZXN0
cm95ZWQuaAo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2UvV1RGL3d0Zi9OZXZlckRlc3Ryb3llZC5oCShy
ZXZpc2lvbiAxODM1MzQpCisrKyBTb3VyY2UvV1RGL3d0Zi9OZXZlckRlc3Ryb3llZC5oCSh3b3Jr
aW5nIGNvcHkpCkBAIC0xMTYsNyArMTE2LDkgQEAgcHJpdmF0ZToKICAgICB9OwogCiAjaWYgIUFT
U0VSVF9ESVNBQkxFRAotICAgIGJvb2wgbV9pc0NvbnN0cnVjdGVkID0gZmFsc2U7CisgICAgLy8g
TGF6eU5ldmVyRGVzdHJveWVkIG9iamVjdHMgYXJlIGFsd2F5cyBzdGF0aWMsIHNvIHRoaXMgdmFy
aWFibGUgaXMgaW5pdGlhbGl6ZWQgdG8gZmFsc2UuCisgICAgLy8gSXQgbXVzdCBub3QgYmUgaW5p
dGlhbGl6ZWQgZHluYW1pY2FsbHksIGJlY2F1c2UgdGhhdCB3b3VsZCBub3QgYmUgdGhyZWFkIHNh
ZmUuCisgICAgYm9vbCBtX2lzQ29uc3RydWN0ZWQ7CiAjZW5kaWYKIH07CiAK
</data>

          </attachment>
      

    </bug>

</bugzilla>