CompCert icon indicating copy to clipboard operation
CompCert copied to clipboard

bad definition/use of variable error

Open monniaux opened this issue 3 years ago • 3 comments

In revision 108d60c0 on x86-64

#include <stdint.h>
void a() { uint64_t b = 0 & 0 ? 0 * 0 && 0 : b; }

produces

error: In function a: bad definition/use of variable 60

I'm actually unsure if this program has a meaning according to the C standard, gcc does compile it without warning though.

monniaux avatar Sep 05 '22 21:09 monniaux

Interesting. One can reduce the input it a little bit:

void a() { long long b = 0 & 0 ? 0 * 0 && 0 : b; }

m-schmidt avatar Sep 05 '22 21:09 m-schmidt

The error seems to be triggered, when e.g. the Cminor representation contains code like this:

'$59' = longofint '$59';

Any modification of the input simplifies the code and such assignments don't happen anymore.

m-schmidt avatar Sep 05 '22 21:09 m-schmidt

Yes, a temporary is being used with two different types (32- and 64-bit int), which is rejected by the Cminor and RTL type-checkers. A similar issue with conditional expressions was fixed a long time ago in https://github.com/AbsInt/CompCert/commit/0d27eae0b07c7c46cb7d4e6d7b0b1145dbdab0c3. Here it comes back as a bad interaction between conditional expressions and the &&/|| operators.

xavierleroy avatar Sep 06 '22 15:09 xavierleroy