From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14634 invoked by alias); 11 Jun 2014 17:23:02 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 14597 invoked by uid 48); 11 Jun 2014 17:22:56 -0000 From: "gary at intrepid dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/60439] No warning for case overflow in switch statement. Date: Wed, 11 Jun 2014 17:23:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gary at intrepid dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-06/txt/msg00788.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D60439 --- Comment #10 from Gary Funck --- The following test case when compiled against a recent trunk revision (2113= 65 2014-06-08) generates a warning, as intended by the patch described in comm= ent 8. int a, x; int main () { switch (!x) { case 0: a =3D 1; break; case 1: a =3D 2; break; } return 0; } s.c: In function =E2=80=98main=E2=80=99: s.c:8:11: warning: switch condition has boolean value [-Wswitch-bool] switch (!x) ^ However, -Wno-switch-bool does *not* suppress the warning. Looking at gcc/c-family/c.opt, it has an Init(1) clause but no Var() clause= .=20 It seems that if an Init() clause is present that a Var() clause must also = be present for this option to work as expected. This patch fixes the issue. Index: gcc/c-family/c.opt =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/c-family/c.opt (revision 211365) +++ gcc/c-family/c.opt (working copy) @@ -539,7 +539,7 @@ C ObjC C++ ObjC++ Var(warn_switch_enum) Warn about all enumerated switches missing a specific case Wswitch-bool -C ObjC C++ ObjC++ Warning Init(1) +C ObjC C++ ObjC++ Var(warn_switch_bool) Warning Init(1) Warn about switches with boolean controlling expression Wmissing-format-attribute However, I'm not so certain that this option should be enabled by default, = for a few reasons: 1) The test case above shows the use of a boolean value used in the case expression where both alternatives (0 and 1) are accounted for and no other (overflow) cases are mentioned. Adding a cast to (int) will not clarify the code at all and in fact then leaves apparent cases unaccounted for, which m= ight arguably lead to a warning to that effect on some compilers (present or future). 2) If the compiler performed control flow analysis and range analysis to determine that some cases are not accounted for or that some cases are out-of-range, then enabling by default would seem appropriate. In the test case above (in my opinion) no warning should be issued because both cases a= re accounted for. 3) Perhaps this option should only be enabled explicitly or by -Wall. For example, -Wswitch is enabled by -Wall. Wswitch C ObjC C++ ObjC++ Var(warn_switch) Warning LangEnabledBy(C ObjC C++ ObjC++,= Wall ) Warn about enumerated switches, with no default, missing a case >>From gcc-bugs-return-453707-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Jun 11 17:26:20 2014 Return-Path: Delivered-To: listarch-gcc-bugs@gcc.gnu.org Received: (qmail 17890 invoked by alias); 11 Jun 2014 17:26:20 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Delivered-To: mailing list gcc-bugs@gcc.gnu.org Received: (qmail 17856 invoked by uid 48); 11 Jun 2014 17:26:16 -0000 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/61479] wrong code gen with fstack-protector-all for variadic function Date: Wed, 11 Jun 2014 17:26:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: RESOLVED 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: bug_status resolution Message-ID: In-Reply-To: References: 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: 2014-06/txt/msg00789.txt.bz2 Content-length: 541 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61479 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Andrew Pinski --- This code is not just non-portable but it is undefined in c as you accessing outside of the bounds of the "array" of a.