mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-28 04:00:06 +08:00
c771cb52fa
we activate code (CODE_ON) only when the target labels are used, which doesn't happen during nocode_wanted regions. So, we cannot just switch off code either during nocode_wanted regions, nothing would switch it on again (except in the happy coincidences when we outright save/restore nocode_wanted). See the testcase for one example, reduced from code generated by yarpgen: in ext = (xxx || 1) // #1 || ((xxx && 1) || 1) // #2 code is first suppressed in #1 normally, then (before this commit) was suppressed via CODE_OFF during #2 (via indirect gjmp), then the suppression from #1 was undone, but nothing undoes the suppression from #2 anymore as everything therein was generated while nocode_wanted was active. So, we would either need to save/restore nocode_wanted around some more expressions, activate CODE_ON also with unused labels (breaks some optimizations we want), or deactivate CODE_OFF only when not already in nocode_wanted state. This does the latter.
81 lines
1.5 KiB
C
81 lines
1.5 KiB
C
/* Check some way in where code suppression caused various
|
|
miscompilations. */
|
|
extern int printf (const char *, ...);
|
|
typedef __SIZE_TYPE__ size_t;
|
|
|
|
size_t _brk_start, _brk_end;
|
|
void * extend_brk(size_t size, size_t align)
|
|
{
|
|
size_t mask = align - 1;
|
|
void *ret = 0;
|
|
|
|
do {
|
|
if (__builtin_expect(!!(_brk_start == 0), 0))
|
|
do {
|
|
printf("wrong1\n");
|
|
} while (0);
|
|
} while (0);
|
|
_brk_end = (_brk_end + mask) & ~mask;
|
|
ret = (void *)_brk_end;
|
|
_brk_end += size;
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void get_args (int a, int b)
|
|
{
|
|
if (a != 1)
|
|
printf("wrong2\n");
|
|
else
|
|
printf("okay\n");
|
|
}
|
|
|
|
void bla(void)
|
|
{
|
|
int __ret = 42;
|
|
({
|
|
if (__builtin_expect(!!(0), 0)) {
|
|
if (__builtin_expect(!!__ret, 0))
|
|
printf("wrong3\n");
|
|
int x = !!(__ret);
|
|
}
|
|
__ret;
|
|
});
|
|
get_args(!!__ret, sizeof(__ret));
|
|
}
|
|
|
|
int ext;
|
|
|
|
void broken_jumpopt (int xxx)
|
|
{
|
|
/* This was broken in 8227db3a2 by code suppression during suppressed
|
|
code :) */
|
|
ext = (xxx || 1) || ((xxx && 1) || 1);
|
|
printf("okay: %d %d\n", xxx, ext);
|
|
}
|
|
|
|
_Bool chk(unsigned long addr, unsigned long limit, unsigned long size)
|
|
{
|
|
_Bool ret;
|
|
/* This just needs to compile, no runtime test. (And it doesn't compile
|
|
only with certain internal checking added that's not committed). */
|
|
if (0)
|
|
ret = 0 != (!!(addr > limit - size));
|
|
return 0;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
void *r;
|
|
_brk_start = 1024;
|
|
_brk_end = 1024;
|
|
r = extend_brk (4096, 16);
|
|
if (!r)
|
|
printf("wrong4\n");
|
|
else
|
|
printf("okay\n");
|
|
bla();
|
|
broken_jumpopt(42);
|
|
return 0;
|
|
}
|