Clean up empty struct/union recognition.
Make use of getTypeSizeInChars to detect structs/unions of zero size. It allows
more accurate detection of types of zero size. It however has a side effect -
sequence of used types may change, that is why the test 'override-layout' was
modified.
llvm-svn: 184088
diff --git a/clang/test/CodeGen/override-layout.c b/clang/test/CodeGen/override-layout.c
index 99c2cd6..8a108a9 100644
--- a/clang/test/CodeGen/override-layout.c
+++ b/clang/test/CodeGen/override-layout.c
@@ -19,24 +19,32 @@
int x[6] PACKED;
};
+void use_X0() { struct X0 x0; x0.x[5] = sizeof(struct X0); };
+
// CHECK: Type: struct X1
struct X1 {
char x[13];
struct X0 y;
} PACKED;
+void use_X1() { struct X1 x1; x1.x[5] = sizeof(struct X1); };
+
// CHECK: Type: struct X2
struct PACKED X2 {
short x;
int y;
};
+void use_X2() { struct X2 x2; x2.y = sizeof(struct X2); };
+
// CHECK: Type: struct X3
struct X3 {
short x PACKED;
int y;
};
+void use_X3() { struct X3 x3; x3.y = sizeof(struct X3); };
+
#pragma pack(push,2)
// CHECK: Type: struct X4
struct X4 {
@@ -45,18 +53,26 @@
};
#pragma pack(pop)
+void use_X4() { struct X4 x4; x4.y = sizeof(struct X4); };
+
// CHECK: Type: struct X5
struct PACKED X5 { double a[19]; signed char b; };
+void use_X5() { struct X5 x5; x5.b = sizeof(struct X5); };
+
// CHECK: Type: struct X6
struct PACKED X6 { long double a; char b; };
+void use_X6() { struct X6 x6; x6.b = sizeof(struct X6); };
+
// CHECK: Type: struct X7
struct X7 {
unsigned x;
unsigned char y;
} PACKED;
+void use_X7() { struct X7 x7; x7.y = x7.x = sizeof(struct X7); }
+
// CHECK: Type: union X8
union X8 {
struct X7 x;
@@ -114,32 +130,6 @@
};
void use_structs() {
- struct X0 x0;
- x0.x[5] = sizeof(struct X0);
-
- struct X1 x1;
- x1.x[5] = sizeof(struct X1);
-
- struct X2 x2;
- x2.y = sizeof(struct X2);
-
- struct X3 x3;
- x3.y = sizeof(struct X3);
-
- struct X4 x4;
- x4.y = sizeof(struct X4);
-
- struct X5 x5;
- x5.b = sizeof(struct X5);
-
- struct X6 x6;
- x6.b = sizeof(struct X6);
-
- struct X7 x7;
- typedef int X7array[sizeof(struct X7)];
- x7.x = sizeof(struct X7);
- x7.y = x7.x;
-
union X8 x8;
typedef int X8array[sizeof(union X8)];
x8.y = sizeof(union X8);