cosmopolitan/third_party/chibicc/test/attribute_test.c
Justine Tunney 8da931a7f6 Add chibicc
This program popped up on Hacker News recently. It's the only modern
compiler I've ever seen that doesn't have dependencies and is easily
modified. So I added all of the missing GNU extensions I like to use
which means it might be possible soon to build on non-Linux and have
third party not vendor gcc binaries.
2020-12-06 16:20:21 -08:00

160 lines
3.8 KiB
C

#include "third_party/chibicc/test/test.h"
int main() {
ASSERT(5, ({
struct {
char a;
int b;
} __attribute__((packed)) x;
sizeof(x);
}));
ASSERT(0, offsetof(
struct __attribute__((packed)) {
char a;
int b;
},
a));
ASSERT(1, offsetof(
struct __attribute__((packed)) {
char a;
int b;
},
b));
ASSERT(5, ({
struct __attribute__((packed)) {
char a;
int b;
} x;
sizeof(x);
}));
ASSERT(0, offsetof(
struct {
char a;
int b;
} __attribute__((packed)),
a));
ASSERT(1, offsetof(
struct {
char a;
int b;
} __attribute__((packed)),
b));
ASSERT(9, ({
typedef struct {
char a;
int b[2];
} __attribute__((packed)) T;
sizeof(T);
}));
ASSERT(9, ({
typedef struct __attribute__((packed)) {
char a;
int b[2];
} T;
sizeof(T);
}));
ASSERT(1, offsetof(
struct __attribute__((packed)) T {
char a;
int b[2];
},
b));
ASSERT(1, _Alignof(struct __attribute__((packed)) {
char a;
int b[2];
}));
ASSERT(8, ({
struct __attribute__((aligned(8))) {
int a;
} x;
_Alignof(x);
}));
ASSERT(8, ({
struct {
int a;
} __attribute__((aligned(8))) x;
_Alignof(x);
}));
ASSERT(8, ({
struct __attribute__((aligned(8), packed)) {
char a;
int b;
} x;
_Alignof(x);
}));
ASSERT(8, ({
struct {
char a;
int b;
} __attribute__((aligned(8), packed)) x;
_Alignof(x);
}));
ASSERT(1, offsetof(
struct __attribute__((aligned(8), packed)) {
char a;
int b;
},
b));
ASSERT(1, offsetof(
struct {
char a;
int b;
} __attribute__((aligned(8), packed)),
b));
ASSERT(8, ({
struct __attribute__((aligned(8))) __attribute__((packed)) {
char a;
int b;
} x;
_Alignof(x);
}));
ASSERT(8, ({
struct {
char a;
int b;
} __attribute__((aligned(8))) __attribute__((packed)) x;
_Alignof(x);
}));
ASSERT(1, offsetof(
struct __attribute__((aligned(8))) __attribute__((packed)) {
char a;
int b;
},
b));
ASSERT(1, offsetof(
struct {
char a;
int b;
} __attribute__((aligned(8))) __attribute__((packed)),
b));
ASSERT(8, ({
struct __attribute__((aligned(8))) {
char a;
int b;
} __attribute__((packed)) x;
_Alignof(x);
}));
ASSERT(1, offsetof(
struct __attribute__((aligned(8))) {
char a;
int b;
} __attribute__((packed)),
b));
ASSERT(16, ({
struct __attribute__((aligned(8 + 8))) {
char a;
int b;
} x;
_Alignof(x);
}));
return 0;
}