Some more subtle issues with code suppression: - outputting asms but not their operand setup is broken - but global asms must always be output - statement expressions are transparent to code suppression - vtop can't be transformed from VT_CMP/VT_JMP when nocode_wanted Also remove .exe files from tests2 if they don't fail.
Showing the changes to tests/tests2/88_codeopt.c (1 of 8 files). Show all
Unified · Split
| @@ -0,0 +1,68 @@ | ||
| 1 | +/* Check some way in where code suppression caused various | |
| 2 | + miscompilations. */ | |
| 3 | +extern int printf (const char *, ...); | |
| 4 | +typedef unsigned long size_t; | |
| 5 | + | |
| 6 | +size_t _brk_start, _brk_end; | |
| 7 | +void * extend_brk(size_t size, size_t align) | |
| 8 | +{ | |
| 9 | + size_t mask = align - 1; | |
| 10 | + void *ret = 0; | |
| 11 | + | |
| 12 | + do { | |
| 13 | + if (__builtin_expect(!!(_brk_start == 0), 0)) | |
| 14 | + do { | |
| 15 | + printf("wrong1\n"); | |
| 16 | + } while (0); | |
| 17 | + } while (0); | |
| 18 | + _brk_end = (_brk_end + mask) & ~mask; | |
| 19 | + ret = (void *)_brk_end; | |
| 20 | + _brk_end += size; | |
| 21 | + | |
| 22 | + return ret; | |
| 23 | +} | |
| 24 | + | |
| 25 | +static void get_args (int a, int b) | |
| 26 | +{ | |
| 27 | + if (a != 1) | |
| 28 | + printf("wrong2\n"); | |
| 29 | + else | |
| 30 | + printf("okay\n"); | |
| 31 | +} | |
| 32 | + | |
| 33 | +void bla(void) | |
| 34 | +{ | |
| 35 | + int __ret = 42; | |
| 36 | + ({ | |
| 37 | + if (__builtin_expect(!!(0), 0)) { | |
| 38 | + if (__builtin_expect(!!__ret, 0)) | |
| 39 | + printf("wrong3\n"); | |
| 40 | + int x = !!(__ret); | |
| 41 | + } | |
| 42 | + __ret; | |
| 43 | + }); | |
| 44 | + get_args(!!__ret, sizeof(__ret)); | |
| 45 | +} | |
| 46 | + | |
| 47 | +_Bool chk(unsigned long addr, unsigned long limit, unsigned long size) | |
| 48 | +{ | |
| 49 | + _Bool ret; | |
| 50 | + /* This just needs to compile, no runtime test. (And it doesn't compile | |
| 51 | + only with certain internal checking added that's not committed). */ | |
| 52 | + if (0) | |
| 53 | + ret = 0 != (!!(addr > limit - size)); | |
| 54 | +} | |
| 55 | + | |
| 56 | +int main() | |
| 57 | +{ | |
| 58 | + void *r; | |
| 59 | + _brk_start = 1024; | |
| 60 | + _brk_end = 1024; | |
| 61 | + r = extend_brk (4096, 16); | |
| 62 | + if (!r) | |
| 63 | + printf("wrong4\n"); | |
| 64 | + else | |
| 65 | + printf("okay\n"); | |
| 66 | + bla(); | |
| 67 | + return 0; | |
| 68 | +} | |