<?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>295171</bug_id>
          
          <creation_ts>2025-06-28 23:30:28 -0700</creation_ts>
          <short_desc>Padding bits defeat intended HTMLEntityTableEntry size optimization</short_desc>
          <delta_ts>2025-07-05 23:31:13 -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>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>ASSIGNED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>squeek502</reporter>
          <assigned_to name="Darin Adler">darin</assigned_to>
          <cc>cdumez</cc>
    
    <cc>darin</cc>
    
    <cc>nathan_solomon</cc>
    
    <cc>rreno</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2126561</commentid>
    <comment_count>0</comment_count>
    <who name="">squeek502</who>
    <bug_when>2025-06-28 23:30:28 -0700</bug_when>
    <thetext>In https://github.com/WebKit/WebKit/pull/11089, HTMLEntityTableEntry was converted to a bit-field in order to decrease the size of kStaticEntityTable. HTMLEntityTableEntry theoretically uses 57 bits, but, due to padding bits, the size of HTMLEntityTableEntry is actually 12 bytes instead of 8 bytes (the same size it was before the bit-field change).

Test code:

struct HTMLEntityTableEntry {
    unsigned firstCharacter : 21;
    unsigned optionalSecondCharacter : 16;
    unsigned nameCharactersOffset : 14;
    unsigned nameLengthExcludingSemicolon : 5;
    unsigned nameIncludesTrailingSemicolon : 1;
};
static_assert(sizeof(HTMLEntityTableEntry) == 8);

Clang 20.1.3:

HTMLEntityTableEntry.cpp:8:15: error: static assertion failed due to requirement &apos;sizeof(HTMLEntityTableEntry) == 8&apos;
    8 | static_assert(sizeof(HTMLEntityTableEntry) == 8);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HTMLEntityTableEntry.cpp:8:44: note: expression evaluates to &apos;12 == 8&apos;
    8 | static_assert(sizeof(HTMLEntityTableEntry) == 8);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
1 error generated.

GCC 11.4.0:

HTMLEntityTableEntry.cpp:8:44: error: static assertion failed
    8 | static_assert(sizeof(HTMLEntityTableEntry) == 8);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~

(for context, this was found while I was writing https://www.ryanliptak.com/blog/better-named-character-reference-tokenization/)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2127128</commentid>
    <comment_count>1</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2025-07-01 14:50:14 -0700</bug_when>
    <thetext>I tried moving optionalSecondCharacter to be the last member of the HTMLEntityTableEntry structure and that worked; just have to revise the code that builds the table to write out the members in the right order.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2127998</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-07-05 23:31:13 -0700</bug_when>
    <thetext>&lt;rdar://problem/155138028&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>