<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - clang shoudn't ignore packed attribute for bit-field of char type"
   href="https://llvm.org/bugs/show_bug.cgi?id=25575">25575</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang shoudn't ignore packed attribute for bit-field of char type
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dmitry.polukhin@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Test case:
struct S1 {
  char a : 4;
  char b : 8 __attribute__((packed));
  char c : 4;
};

struct S2 {
  char a : 4;
  int b : 8 __attribute__((packed));
  char c : 4;
};

extern int a[sizeof(struct S1) == 2 ? 1 : -1];
extern int b[sizeof(struct S2) == 2 ? 1 : -1];

Clang ignores packed attribute and reports error:
test.c:3:29: warning: 'packed' attribute ignored for field of type 'char'
[-Wignored-attributes]
  char b : 8 __attribute__((packed));
                            ^
test.c:13:14: error: 'a' declared as an array with a negative size
extern int a[sizeof(struct S1) == 2 ? 1 : -1];
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.

GCC 4.4+ only emits warning but compiles successfully:
test.c:5:1: note: offset of packed bit-field â€˜b’ has changed in GCC 4.4
 };
 ^

According to GCC documentation the behavior was changes in 4.4:
Note: The 4.1, 4.2 and 4.3 series of GCC ignore the packed attribute on
bit-fields of type char. This has been fixed in GCC 4.4 but the change can lead
to differences in the structure layout. See the documentation of
-Wpacked-bitfield-compat for more information. 

So clang emulates old GCC behavior that doesn't have much sense and was fixed
in newer GCC versions. Input on why current behavior should be preserved or
changed is very appreciated.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>