xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/bitfield-layout.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-apple-darwin10
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc #define CHECK_SIZE(name, size) extern int name##1[sizeof(name) == size ? 1 : -1];
4*f4a2713aSLionel Sambuc #define CHECK_ALIGN(name, size) extern int name##2[__alignof(name) == size ? 1 : -1];
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc // Simple tests.
7*f4a2713aSLionel Sambuc struct Test1 {
8*f4a2713aSLionel Sambuc   char c : 9; // expected-warning {{size of bit-field 'c' (9 bits) exceeds the size of its type; value will be truncated to 8 bits}}
9*f4a2713aSLionel Sambuc };
10*f4a2713aSLionel Sambuc CHECK_SIZE(Test1, 2);
11*f4a2713aSLionel Sambuc CHECK_ALIGN(Test1, 1);
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc struct Test2 {
14*f4a2713aSLionel Sambuc   char c : 16; // expected-warning {{size of bit-field 'c' (16 bits) exceeds the size of its type; value will be truncated to 8 bits}}
15*f4a2713aSLionel Sambuc };
16*f4a2713aSLionel Sambuc CHECK_SIZE(Test2, 2);
17*f4a2713aSLionel Sambuc CHECK_ALIGN(Test2, 2);
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc struct Test3 {
20*f4a2713aSLionel Sambuc   char c : 32; // expected-warning {{size of bit-field 'c' (32 bits) exceeds the size of its type; value will be truncated to 8 bits}}
21*f4a2713aSLionel Sambuc };
22*f4a2713aSLionel Sambuc CHECK_SIZE(Test3, 4);
23*f4a2713aSLionel Sambuc CHECK_ALIGN(Test3, 4);
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc struct Test4 {
26*f4a2713aSLionel Sambuc   char c : 64; // expected-warning {{size of bit-field 'c' (64 bits) exceeds the size of its type; value will be truncated to 8 bits}}
27*f4a2713aSLionel Sambuc };
28*f4a2713aSLionel Sambuc CHECK_SIZE(Test4, 8);
29*f4a2713aSLionel Sambuc CHECK_ALIGN(Test4, 8);
30*f4a2713aSLionel Sambuc 
31