aboutsummaryrefslogtreecommitdiff
path: root/test/CodeGenCXX/warn-padded-packed.cpp
blob: f2af60865e05a5d250eb5859ebc0e009399224d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify %s -emit-llvm-only

struct S1 {
  char c;
  short s; // expected-warning {{padding struct 'S1' with 1 byte to align 's'}}
  long l; // expected-warning {{padding struct 'S1' with 4 bytes to align 'l'}}
};

struct S2 { // expected-warning {{padding size of 'S2' with 3 bytes to alignment boundary}}
  int i;
  char c;
};

struct S3 {
  char c;
  int i;
} __attribute__((packed));

struct S4 {
  int i; // expected-warning {{packed attribute is unnecessary for 'i'}}
  char c;
} __attribute__((packed));

struct S5 {
  char c;
  union {
    char c;
    int i;
  } u; // expected-warning {{padding struct 'S5' with 3 bytes to align 'u'}}
};

struct S6 { // expected-warning {{padding size of 'S6' with 30 bits to alignment boundary}}
  int i : 2;
};

struct S7 { // expected-warning {{padding size of 'S7' with 7 bytes to alignment boundary}}
  char c;
  virtual void m();
};

struct B {
  char c;
};

struct S8 : B {
  int i; // expected-warning {{padding struct 'S8' with 3 bytes to align 'i'}}
};

struct S9 { // expected-warning {{packed attribute is unnecessary for 'S9'}}
  int x; // expected-warning {{packed attribute is unnecessary for 'x'}}
  int y; // expected-warning {{packed attribute is unnecessary for 'y'}}
} __attribute__((packed));

struct S10 { // expected-warning {{packed attribute is unnecessary for 'S10'}}
  int x; // expected-warning {{packed attribute is unnecessary for 'x'}}
  char a,b,c,d;
} __attribute__((packed));


struct S11 {
  bool x;
  char a,b,c,d;
} __attribute__((packed));

struct S12 {
  bool b : 1;
  char c; // expected-warning {{padding struct 'S12' with 7 bits to align 'c'}}
};

struct S13 { // expected-warning {{padding size of 'S13' with 6 bits to alignment boundary}}
  char c;
  bool b : 10;
};

// The warnings are emitted when the layout of the structs is computed, so we have to use them.
void f(S1*, S2*, S3*, S4*, S5*, S6*, S7*, S8*, S9*, S10*, S11*, S12*, S13*) { }