[llvm-bugs] [Bug 25575] New: clang shoudn't ignore packed attribute for bit-field of char type

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 19 06:43:04 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25575

            Bug ID: 25575
           Summary: clang shoudn't ignore packed attribute for bit-field
                    of char type
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dmitry.polukhin at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151119/66e684f6/attachment.html>


More information about the llvm-bugs mailing list