public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/66880] New: 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99.
@ 2015-07-15 14:16 chefmax at gcc dot gnu.org
  2015-07-15 14:24 ` [Bug sanitizer/66880] " mpolacek at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: chefmax at gcc dot gnu.org @ 2015-07-15 14:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66880

            Bug ID: 66880
           Summary: 'error: case label does not reduce to an integer
                    constant' with -fsanitize=shift -std=gnu99.
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chefmax at gcc dot gnu.org
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org,
                    mpolacek at gcc dot gnu.org, ygribov at gcc dot gnu.org
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu

When compile this testcase with -fsanitize=shift -std=gnu99, such an error
happened:

$ cat test.c

int main (int argc, char **argv) {
  switch (argc) {
    case 0xEB << 24: return 1;
    case 1: return 2;
    default: return 0;
  }
}


$ ~/install/master/bin/gcc  -fsanitize=undefined -std=gnu99 test.c
-static-libubsan

1.c: In function ‘main’:
1.c:3:5: error: case label does not reduce to an integer constant
     case 0xEB << 24: return 1;
     ^
max@max:/tmp$ ~/install/master/bin/gcc  -fsanitize=shift -std=gnu99 1.c
-static-libubsan
1.c: In function ‘main’:
1.c:3:5: error: case label does not reduce to an integer constant
     case 0xEB << 24: return 1;
     ^

$ ~/install/master/bin/gcc  -v
Using built-in specs.
COLLECT_GCC=/home/max/install/master/bin/gcc
COLLECT_LTO_WRAPPER=/home/max/install/master/libexec/gcc/x86_64-unknown-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/max/workspace/downloads/gcc/configure --enable-multilib
--enable-checking --target=x86_64-unknown-linux-gnu
--host=x86_64-unknown-linux-gnu --build=x86_64-unknown-linux-gnu
--prefix=/home/max/install/master --disable-bootstrap --enable-languages=c,c++
CFLAGS='-g -O0' CXXFLAGS='-g -O0'
Thread model: posix
gcc version 6.0.0 20150710 (experimental) (GCC)

This is caused by this:

Breakpoint 1, check_case_value (loc=7699, value=0x7ffff69712a8) at
/home/max/workspace/downloads/gcc/gcc/c-family/c-common.c:3620
3620          error_at (loc, "case label does not reduce to an integer
constant");
(gdb) call debug_tree(value)
 <compound_expr 0x7ffff69712a8
    type <integer_type 0x7ffff682e7e0 int public SI
        size <integer_cst 0x7ffff682aee8 constant 32>
        unit size <integer_cst 0x7ffff682af00 constant 4>
        align 32 symtab 0 alias set -1 canonical type 0x7ffff682e7e0 precision
32 min <integer_cst 0x7ffff682aea0 -2147483648> max <integer_cst 0x7ffff682aeb8
2147483647>
        pointer_to_this <pointer_type 0x7ffff6848930>>
    side-effects
    arg 0 <call_expr 0x7ffff6833a68
        type <void_type 0x7ffff6848150 void VOID
            align 8 symtab 0 alias set -1 canonical type 0x7ffff6848150
            pointer_to_this <pointer_type 0x7ffff68482a0>>
        side-effects
        fn <addr_expr 0x7ffff696fd20 type <pointer_type 0x7ffff6987a80>
            constant arg 0 <function_decl 0x7ffff69202a0
__builtin___ubsan_handle_shift_out_of_bounds>>
        arg 0 <addr_expr 0x7ffff696fd00 type <pointer_type 0x7ffff69879d8>
            constant arg 0 <var_decl 0x7ffff6836cf0 *.Lubsan_data0>
            1.c:3:15>
        arg 1 <integer_cst 0x7ffff6970a80 constant 235>
        arg 2 <integer_cst 0x7ffff6970a68 constant 24>>
    arg 1 <integer_cst 0x7ffff6970840 type <integer_type 0x7ffff682e7e0 int>
constant -352321536>
    1.c:3:15>
(gdb)
>From gcc-bugs-return-492346-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Jul 15 14:18:52 2015
Return-Path: <gcc-bugs-return-492346-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 55554 invoked by alias); 15 Jul 2015 14:18:52 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 55475 invoked by uid 48); 15 Jul 2015 14:18:47 -0000
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/66880] 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99.
Date: Wed, 15 Jul 2015 14:18:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: sanitizer
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jakub at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-66880-4-ugKBLxtpPh@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66880-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66880-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-07/txt/msg01236.txt.bz2
Content-length: 202

https://gcc.gnu.org/bugzilla/show_bug.cgi?idf880

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
And why do you think it is wrong?  0xEB << 24 is undefined behavior in C99 I
think.


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

* [Bug sanitizer/66880] 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99.
  2015-07-15 14:16 [Bug sanitizer/66880] New: 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99 chefmax at gcc dot gnu.org
@ 2015-07-15 14:24 ` mpolacek at gcc dot gnu.org
  2015-07-15 14:32 ` y.gribov at samsung dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-07-15 14:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66880

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Yes; it's not UB only in C89.  (My warning -Wshift-overflow would warn about
this as well, but it's not in yet.)


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

* [Bug sanitizer/66880] 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99.
  2015-07-15 14:16 [Bug sanitizer/66880] New: 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99 chefmax at gcc dot gnu.org
  2015-07-15 14:24 ` [Bug sanitizer/66880] " mpolacek at gcc dot gnu.org
@ 2015-07-15 14:32 ` y.gribov at samsung dot com
  2015-07-15 14:38 ` mpolacek at gcc dot gnu.org
  2015-07-16  7:45 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: y.gribov at samsung dot com @ 2015-07-15 14:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66880

Yury Gribov <y.gribov at samsung dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |y.gribov at samsung dot com

--- Comment #3 from Yury Gribov <y.gribov at samsung dot com> ---
I think Max means that error message may sound a bit unexpected as it mentions
nothing about UBSan.


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

* [Bug sanitizer/66880] 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99.
  2015-07-15 14:16 [Bug sanitizer/66880] New: 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99 chefmax at gcc dot gnu.org
  2015-07-15 14:24 ` [Bug sanitizer/66880] " mpolacek at gcc dot gnu.org
  2015-07-15 14:32 ` y.gribov at samsung dot com
@ 2015-07-15 14:38 ` mpolacek at gcc dot gnu.org
  2015-07-16  7:45 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-07-15 14:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66880

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Yeah, the problem is that a case label value needs to be an integral constant
expression.  0xEB << 24 contains an overflow so we weren't able to fold it,
thus we emit the __builtin___ubsan_handle_shift_out_of_bounds call -- and that
is rejected by the C FE later on.  I'm not sure how to make this better.


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

* [Bug sanitizer/66880] 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99.
  2015-07-15 14:16 [Bug sanitizer/66880] New: 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99 chefmax at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2015-07-15 14:38 ` mpolacek at gcc dot gnu.org
@ 2015-07-16  7:45 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-07-16  7:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66880

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
It would be better to make the C FE reject this as constant expression which
invokes undefined behavior.

IMHO -fsanitize should never sanitize any constant expression - the FE will
reject non-constant ones anyway.


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

end of thread, other threads:[~2015-07-16  7:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-15 14:16 [Bug sanitizer/66880] New: 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99 chefmax at gcc dot gnu.org
2015-07-15 14:24 ` [Bug sanitizer/66880] " mpolacek at gcc dot gnu.org
2015-07-15 14:32 ` y.gribov at samsung dot com
2015-07-15 14:38 ` mpolacek at gcc dot gnu.org
2015-07-16  7:45 ` rguenth at gcc dot gnu.org

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).