public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* -fsanitize=shift compile error
@ 2016-09-26 23:43 Mateusz Tabaka
  2016-09-27  2:32 ` Segher Boessenkool
  2016-09-27  8:04 ` Mason
  0 siblings, 2 replies; 4+ messages in thread
From: Mateusz Tabaka @ 2016-09-26 23:43 UTC (permalink / raw)
  To: gcc-help

Hi,

I'm trying to compile this file:
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?

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: -fsanitize=shift compile error
  2016-09-26 23:43 -fsanitize=shift compile error Mateusz Tabaka
@ 2016-09-27  2:32 ` Segher Boessenkool
  2016-09-27  8:04 ` Mason
  1 sibling, 0 replies; 4+ messages in thread
From: Segher Boessenkool @ 2016-09-27  2:32 UTC (permalink / raw)
  To: Mateusz Tabaka; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: -fsanitize=shift compile error
  2016-09-26 23:43 -fsanitize=shift compile error Mateusz Tabaka
  2016-09-27  2:32 ` Segher Boessenkool
@ 2016-09-27  8:04 ` Mason
  2016-09-27 15:50   ` Mateusz Tabaka
  1 sibling, 1 reply; 4+ messages in thread
From: Mason @ 2016-09-27  8:04 UTC (permalink / raw)
  To: Mateusz Tabaka; +Cc: GCC help

On 27/09/2016 01:43, Mateusz Tabaka wrote:

> I'm trying to compile this file:
> 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):

Try 4u << 29

Do you get the same error?

Regards.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: -fsanitize=shift compile error
  2016-09-27  8:04 ` Mason
@ 2016-09-27 15:50   ` Mateusz Tabaka
  0 siblings, 0 replies; 4+ messages in thread
From: Mateusz Tabaka @ 2016-09-27 15:50 UTC (permalink / raw)
  To: Mason; +Cc: GCC help

On 27.09.2016 10:04, Mason wrote:
> Try 4u << 29

That worked. Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-09-27 15:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-26 23:43 -fsanitize=shift compile error Mateusz Tabaka
2016-09-27  2:32 ` Segher Boessenkool
2016-09-27  8:04 ` Mason
2016-09-27 15:50   ` Mateusz Tabaka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).