public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/60725] New: [-Wreturn-type] false positive in trivial switch
@ 2014-04-01  8:37 skvadrik at gmail dot com
  2014-04-01 13:52 ` [Bug middle-end/60725] " mpolacek at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: skvadrik at gmail dot com @ 2014-04-01  8:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60725

            Bug ID: 60725
           Summary: [-Wreturn-type] false positive in trivial switch
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: skvadrik at gmail dot com

Created attachment 32510
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32510&action=edit
wreturn_false_positive.c

Given this program (see attachment):

  // wreturn_false_positive.c
  enum E { E1 };
  static inline int f1(enum E e) {
      switch (e) {
          case E1: return 1;
      }
  }
  int main () {
      f1(E1);
      return 0;
  }

gcc generates warning:

$ gcc -Wall wreturn_false_positive.c 
wreturn_false_positive.c: In function ‘f1’:
wreturn_false_positive.c:9:1: warning: control reaches end of non-void function
[-Wreturn-type]

If I compile with '-fdump-tree-all', I see that gcc adds 'default' case to
switch very early (in .gimple), and later it cannot get rid of that 'default'
path. Why does gcc add default case?
>From gcc-bugs-return-448001-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Apr 01 08:54:07 2014
Return-Path: <gcc-bugs-return-448001-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 29764 invoked by alias); 1 Apr 2014 08:54:06 -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 29712 invoked by uid 48); 1 Apr 2014 08:54:02 -0000
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug lto/60721] xcoral fails to build with LTO: internal compiler error: verify_flow_info failed
Date: Tue, 01 Apr 2014 08:54:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: lto
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords: lto
X-Bugzilla-Severity: normal
X-Bugzilla-Who: rguenth at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
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-60721-4-4TK0GbvaAS@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60721-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60721-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: 2014-04/txt/msg00021.txt.bz2
Content-length: 276

http://gcc.gnu.org/bugzilla/show_bug.cgi?id`721

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
IMHO we need a flag on each gimple call whether that call instance is supposed
to be 'leaf' or not, similar to how we have noreturn and nothrow flags here.


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

* [Bug middle-end/60725] [-Wreturn-type] false positive in trivial switch
  2014-04-01  8:37 [Bug c/60725] New: [-Wreturn-type] false positive in trivial switch skvadrik at gmail dot com
@ 2014-04-01 13:52 ` mpolacek at gcc dot gnu.org
  2015-09-04 15:26 ` jens.auer at cgi dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-04-01 13:52 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60725

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-04-01
                 CC|                            |mpolacek at gcc dot gnu.org
          Component|c                           |middle-end
     Ever confirmed|0                           |1

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
It adds the default case at the end of the switch so we can jump over the whole
switch body.  But it should do so only if the labels cover the whole range of
the controlling expression of the switch.  Here the switch label seemingly
covers the whole range of the enum, but TYPE_MAX_VALUE of the enum E is
UINT_MAX, while the high value of the case label is 0.


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

* [Bug middle-end/60725] [-Wreturn-type] false positive in trivial switch
  2014-04-01  8:37 [Bug c/60725] New: [-Wreturn-type] false positive in trivial switch skvadrik at gmail dot com
  2014-04-01 13:52 ` [Bug middle-end/60725] " mpolacek at gcc dot gnu.org
@ 2015-09-04 15:26 ` jens.auer at cgi dot com
  2015-09-04 17:41 ` manu at gcc dot gnu.org
  2015-09-04 18:46 ` manu at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jens.auer at cgi dot com @ 2015-09-04 15:26 UTC (permalink / raw)
  To: gcc-bugs

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

Jens Auer <jens.auer at cgi dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jens.auer at cgi dot com

--- Comment #2 from Jens Auer <jens.auer at cgi dot com> ---
This warnings becomes annoying when you also compile with -Wswitch-enum which
forces you to cover all enum values. When they are all covered, I do not need a
default statement, but to prevent Wreturn-type, I have to add a pseudo-default.


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

* [Bug middle-end/60725] [-Wreturn-type] false positive in trivial switch
  2014-04-01  8:37 [Bug c/60725] New: [-Wreturn-type] false positive in trivial switch skvadrik at gmail dot com
  2014-04-01 13:52 ` [Bug middle-end/60725] " mpolacek at gcc dot gnu.org
  2015-09-04 15:26 ` jens.auer at cgi dot com
@ 2015-09-04 17:41 ` manu at gcc dot gnu.org
  2015-09-04 18:46 ` manu at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2015-09-04 17:41 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #1)
> It adds the default case at the end of the switch so we can jump over the
> whole switch body.  But it should do so only if the labels cover the whole
> range of the controlling expression of the switch.  Here the switch label
> seemingly covers the whole range of the enum, but TYPE_MAX_VALUE of the enum
> E is UINT_MAX, while the high value of the case label is 0.

But in C, e can contain any value of the underlying type (unsigned int). Thus
one can legally call f1(10), and then what happens next is probably a bug.

enum E { E1=0 };
static inline int f1(enum E e) {
  switch (e) {
  case E1: return 1;
  }
}
int main () {
  return f1(10);
}

If this is actually undefined behavior, -fsanitize=undefined does not seem to
catch it.
>From gcc-bugs-return-496391-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Sep 04 17:45:57 2015
Return-Path: <gcc-bugs-return-496391-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 79075 invoked by alias); 4 Sep 2015 17:45:57 -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 78969 invoked by uid 48); 4 Sep 2015 17:45:50 -0000
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/60725] [-Wreturn-type] false positive in trivial switch
Date: Fri, 04 Sep 2015 17:45:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 4.8.2
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: manu at gcc dot gnu.org
X-Bugzilla-Status: NEW
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-60725-4-8IUEQFXnU1@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60725-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60725-4@http.gcc.gnu.org/bugzilla/>
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: 2015-09/txt/msg00369.txt.bz2
Content-length: 707

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

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Jens Auer from comment #2)
> This warnings becomes annoying when you also compile with -Wswitch-enum
> which forces you to cover all enum values. When they are all covered, I do
> not need a default statement, but to prevent Wreturn-type, I have to add a
> pseudo-default.

Even if you do not explicitly write one, there is one for the case where the
value is outside the enum values, which is valid in C (but not in C++, as far
as I know, thus the warning would be questionable there). What is not valid is
to reach the end of a non-void function.
>From gcc-bugs-return-496392-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Sep 04 18:14:44 2015
Return-Path: <gcc-bugs-return-496392-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 8880 invoked by alias); 4 Sep 2015 18:14:44 -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 8825 invoked by uid 48); 4 Sep 2015 18:14:40 -0000
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/60725] [-Wreturn-type] false positive in trivial switch
Date: Fri, 04 Sep 2015 18:14:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 4.8.2
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: msebor at gcc dot gnu.org
X-Bugzilla-Status: NEW
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: cc
Message-ID: <bug-60725-4-5XeEhId7fT@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60725-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60725-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-09/txt/msg00370.txt.bz2
Content-length: 745

https://gcc.gnu.org/bugzilla/show_bug.cgi?id`725

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
Not to complicate things too much, but reaching the closing } of a non-void
function is valid in C.  What is not valid (i.e., has undefined behavior) is
calling such a function and using its return value when none was provided (as
in the program in comment #3).  The program in the Description, however, has
well-defined behavior because f1's return value isn't used.


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

* [Bug middle-end/60725] [-Wreturn-type] false positive in trivial switch
  2014-04-01  8:37 [Bug c/60725] New: [-Wreturn-type] false positive in trivial switch skvadrik at gmail dot com
                   ` (2 preceding siblings ...)
  2015-09-04 17:41 ` manu at gcc dot gnu.org
@ 2015-09-04 18:46 ` manu at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2015-09-04 18:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #5)
> The program in the Description, however,
> has well-defined behavior because f1's return value isn't used.

It is also easy to silence the warning by adding an explicit abort() or
__builtin_unreachable() before the closing }.
>From gcc-bugs-return-496402-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Sep 04 20:25:38 2015
Return-Path: <gcc-bugs-return-496402-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 70463 invoked by alias); 4 Sep 2015 20:25:38 -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 70413 invoked by uid 48); 4 Sep 2015 20:25:34 -0000
From: "hjl.tools at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug testsuite/67450] [6 Regression] ERROR: can't unset "et_cache(ia32,value)": no such element in array
Date: Fri, 04 Sep 2015 20:25:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: testsuite
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: hjl.tools at gmail dot com
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Resolution: FIXED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 6.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status resolution target_milestone
Message-ID: <bug-67450-4-O49YiOSSyd@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67450-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67450-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-09/txt/msg00380.txt.bz2
Content-length: 467

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |6.0

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
Fixed.


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

end of thread, other threads:[~2015-09-04 18:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-01  8:37 [Bug c/60725] New: [-Wreturn-type] false positive in trivial switch skvadrik at gmail dot com
2014-04-01 13:52 ` [Bug middle-end/60725] " mpolacek at gcc dot gnu.org
2015-09-04 15:26 ` jens.auer at cgi dot com
2015-09-04 17:41 ` manu at gcc dot gnu.org
2015-09-04 18:46 ` manu 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).