aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-03-18 23:10:25 +0100
committerlemon <lsof@mailbox.org>2026-03-18 23:10:25 +0100
commit1b782f049fa96d7ebccf93ad2b05fc30b938c870 (patch)
treed4048328308d676f05a9312af63e55e09459da8e /test
parent626c927bb70519e630402093ff4fba432d2ac8c5 (diff)
c: fix edge cases with zero sized bitfields and static initializers
Diffstat (limited to 'test')
-rw-r--r--test/17-misc.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/17-misc.c b/test/17-misc.c
index ffd2470..73f09d1 100644
--- a/test/17-misc.c
+++ b/test/17-misc.c
@@ -1,5 +1,6 @@
/* EXPECT:
-1155497588
+S3 =16, f2@8, q@14
*/
typedef unsigned long long uvlong;
@@ -29,11 +30,26 @@ _Static_assert(!__is_constexpr(fn1(0)), "");
#include <stddef.h>
#include <stdint.h>
struct foo { int *a, b[2]; };
+
+static int g_37[3][5] = {{1,2,3,4,5},{11,12,13,14,15}};
static intptr_t offst[] = {
(long)((struct foo *)0)->b,
(long)&((struct foo *)0)->a,
(long)&((struct foo *)0)->b[1],
- (intptr_t)("12" - 5)
+ (intptr_t)("12" - 5),
+};
+static int *g_131 = &g_37[0][4];
+static int *g_132 = &g_37[1][3];
+static int *g_133 = &g_37[2][0];
+
+#include <stdint.h>
+struct S3 {
+ unsigned f0 : 21;
+ volatile unsigned f1 : 13;
+ unsigned f2;
+ unsigned : 0;
+ short f3 : 13;
+ char q;
};
extern int printf(const char *, ...);
@@ -43,4 +59,6 @@ int main() {
assert(offst[0] == offsetof(struct foo, b));
assert(offst[1] == offsetof(struct foo, a));
assert(offst[2] == offsetof(struct foo, b[1]));
+ assert(*g_131 == 5 && *g_132 == 14 && *g_133 == 0);
+ printf("S3 =%d, f2@%d, q@%d\n", (int)sizeof(struct S3), (int)offsetof(struct S3, f2), (int)offsetof(struct S3, q));
}