UnitTests/2003-05-31-CastToBool.c

I think test/Programs/SingleSource/UnitTests/2003-05-31-CastToBool.c
has a problem. Consider:

     void testLong(long long X) {
        printf("%ld ", X);
        testBool(X != 0);
     }

This passes 'long long' value to 'ld' format specifier -- but for that
specifier the parameter should be 'long'. So, the behaviour of the above is
undefined and in fact it produces wrong results with my backend.

Could extra 'l' be added in the format string?

- Volodya

Volodya,

This program is in error. Either the format specifier needs to be %lld
or the argument value X needs to be casted to type long. This will
compile fine but it probably won't work at runtime because printf is
expecting a long, not a long long. I think your backend producing "wrong
results" is actually correct :slight_smile:

Most modern C/C++ compilers will detect this for you at compile time.
What compiler are you using?

Reid.

Reid Spencer wrote:

This program is in error. Either the format specifier needs to be %lld
or the argument value X needs to be casted to type long. This will
compile fine but it probably won't work at runtime because printf is
expecting a long, not a long long. I think your backend producing "wrong
results" is actually correct :slight_smile:

Yea, that's what I'm trying to say.

Most modern C/C++ compilers will detect this for you at compile time.
What compiler are you using?

Well, LLVM gcc frontend :wink: I mean this is *existing* test, not the one I
wrote, and so this is something to be fixed in CVS.

- Volodya

Okay, gotcha .. I'm a little sleepy this morning .. will fix.