quakeforge/tools/qfcc/test/lost-use.r
Bill Currie b6093e0728 [qfcc] Add failing test for lost var use
Storing a variable into a dereference pointer (*p = x) is not marking
the variable as used (due to a mistake while converting to Ruamoko
statement format) resulting in assignments to that variable being
dropped due to it being a dead assignment as the assignment to the
variable and the storing need to be in separate basic blocks (thus the
call in the test, though an if would have worked, I think) for the bug
to trigger.
2022-01-23 01:31:50 +09:00

29 lines
289 B
R

void printf (string fmt, ...) = #0;
int getval(void)
{
return 42;
}
void magic (void)
{
}
void storeval (int *p)
{
int x = getval ();
magic ();
*p = x;
}
int val;
int
main(void)
{
storeval (&val);
if (val != 42) {
printf ("val is dead: %d\n", val);
return 1;
}
return 0;
}