-fsanitize=shift compile error

Segher Boessenkool segher@kernel.crashing.org
Tue Sep 27 02:32:00 GMT 2016


On Tue, Sep 27, 2016 at 01:43:23AM +0200, Mateusz Tabaka wrote:
> int main()
> {
>         int a = 0;
>         switch (a)
>         {
>         case (4 << 29):
>                 break;
>         }
>         return 0;
> }
> 
> and I get this error:
> ./host-x86_64-pc-linux-gnu/gcc/cc1 test.c -quiet -fsanitize=shift
> test.c: In function ‘main’:
> test.c:6:2: error: case label does not reduce to an integer constant
>   case (4 << 29):
>   ^~~~
> 
> If I remove "-fsanitize=shift" (or change the expression to be less than 
> 2^31) I'm able to compile above code without issues.
> It is expected behavior or a known bug?

It is a bug, but a bug in your code: 4 << 29 is undefined behaviour
(see C11 6.5.7/4).


Segher



More information about the Gcc-help mailing list