Bug 19583 - [4.0 Regression] Incorrect diagnostic: control may reach end of non-void function '...' being inlined
Summary: [4.0 Regression] Incorrect diagnostic: control may reach end of non-void func...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 minor
Target Milestone: 4.0.0
Assignee: Andrew Pinski
URL:
Keywords: diagnostic, patch
: 19573 19631 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-01-23 05:07 UTC by Zack Weinberg
Modified: 2005-02-09 03:52 UTC (History)
6 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-01-23 05:21:08


Attachments
test case (279 bytes, text/plain)
2005-01-23 05:08 UTC, Zack Weinberg
Details
shorter test case (176 bytes, text/plain)
2005-01-23 05:11 UTC, Zack Weinberg
Details
preprocessed testcase which still gives wrong warnings (125.39 KB, application/octet-stream)
2005-01-27 19:44 UTC, Martin Reinecke
Details
Preprocessed sources showing the problem (62.74 KB, application/x-gzip)
2005-01-29 19:07 UTC, Lars Gullik Bjønnes
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zack Weinberg 2005-01-23 05:07:03 UTC
$ /scratch/zack/i/gcc-vanilla/bin/g++ -v
Using built-in specs.
Configured with: /home/zack/src/gcc/HEAD/vanilla/configure
--prefix=/scratch/zack/i/gcc-vanilla --disable-checking --enable-languages=c,c++
--disable-multilib
Thread model: posix
gcc version 4.0.0 20050122 (experimental)

$ /scratch/zack/i/gcc-vanilla/bin/g++ -S -O2 -W -Wall testcase.cc
testcase.cc: In function ‘void finalize()’:
testcase.cc:29: warning: control may reach end of non-void function ‘bool
N::operator!=(N) const’ being inlined

I will attach the testcase.
Comment 1 Zack Weinberg 2005-01-23 05:08:11 UTC
Created attachment 8039 [details]
test case
Comment 2 Zack Weinberg 2005-01-23 05:11:10 UTC
Created attachment 8040 [details]
shorter test case
Comment 3 Andrew Pinski 2005-01-23 05:21:07 UTC
Here is the simplified testcase:
static inline bool f() throw()
{
  return 0;
}
bool ff()
{
  return f();
}
Comment 4 Andrew Pinski 2005-01-23 05:22:08 UTC
I think the problem is that we don't look passed eh_spec_block trees.
Comment 5 Andrew Pinski 2005-01-23 05:48:57 UTC
The problem is not related eh_spec_block as we are gimple at this point.
Comment 6 Andrew Pinski 2005-01-23 06:05:01 UTC
The problem is that block_may_fallthru does not handle try_catch_expr and eh_filter_expr.
Comment 7 Andrew Pinski 2005-01-23 06:14:48 UTC
Mine. I am testing a patch right now.
Comment 8 Andrew Pinski 2005-01-23 15:45:03 UTC
(In reply to comment #7)
> Mine. I am testing a patch right now.

Hmm, I get a bootstrap failure with the patch:
/Users/pinskia/src/local3/gcc/libstdc++-v3/libsupc++/eh_alloc.cc: In function 'void __cxxabiv1::
__cxa_free_exception(void*)':
/Users/pinskia/src/local3/gcc/libstdc++-v3/libsupc++/eh_alloc.cc:157: error: Fallthru to exit from bb 
12

/Users/pinskia/src/local3/gcc/libstdc++-v3/libsupc++/eh_alloc.cc:157: internal compiler error: 
verify_flow_info failed
Comment 9 Andrew Pinski 2005-01-23 16:22:42 UTC
(In reply to comment #8)
> (In reply to comment #7)
> > Mine. I am testing a patch right now.
> 
> Hmm, I get a bootstrap failure with the patch:
And here is the reduced testcase for that failure:
void f(void);
void g(void) throw()
{
  f();
}

I have to rethink this,  maybe we should skip those trees before passing to block_may_fallthru.
Comment 10 Andrew Pinski 2005-01-23 16:46:11 UTC
(In reply to comment #9)
> I have to rethink this,  maybe we should skip those trees before passing to block_may_fallthru.

Yes that fixes it (I will submit the patch after lunch).
Comment 11 Andrew Pinski 2005-01-23 22:22:03 UTC
All this code will go away for 4.1 anyways which is good (and we will not have false postives any more).

Anyways patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01675.html>.
Comment 12 Hans-Peter Nilsson 2005-01-24 00:34:48 UTC
*** Bug 19573 has been marked as a duplicate of this bug. ***
Comment 13 andre.maute 2005-01-24 12:27:43 UTC
with the following the problem also does occur 
 
---------- O3Wall.cc ------- 
#include <cmath> 
 
double test( double x ) { 
        return fabs(x); 
} 
---------- O3Wall.cc ------- 
 
> g++-4.0-20050123 O3Wall.cc -O3 -Wall -c 
O3Wall.cc: In function 'double test(double)': 
O3Wall.cc:4: warning: control may reach end of non-void function 'double 
fabs(double)' being inlined 
 
> g++-4.0-20050123 -v 
Using built-in specs. 
Configured with: ../gcc-4.0-20050123/configure --prefix=/opt/gcc-4.0-20050123 
--enable-shared --enable-languages=c,c++ --enable-threads=posix 
--enable-__cxa_atexit --enable-clocale=gnu --disable-nls 
--program-suffix=-4.0-20050123 --disable-checking --with-arch=pentium3 
Thread model: posix 
gcc version 4.0.0 20050123 (experimental) 
 
Comment 14 andre.maute 2005-01-24 12:30:00 UTC
oh sorry, i did not read the bug history :-( 
regards andre 
Comment 15 Andrew Pinski 2005-01-25 21:17:57 UTC
*** Bug 19631 has been marked as a duplicate of this bug. ***
Comment 16 andre.maute 2005-01-26 01:20:34 UTC
(In reply to comment #11) 
> Anyways patch here: 
<http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01675.html>. 
 
the patch (used with gcc-4.0-20050123) doesn't fix the following code 
 
---------- O3Wall-2.cc -------  
#include <stack> 
int main() { 
        int x = 3; int* ptr = &x; 
        std::stack<int*> s; 
        s.push(ptr); 
        s.pop(); 
        return 0; 
} 
---------- O3Wall-2.cc -------  
 
> g++-4.0-20050123-1 -O3 -Wall O3Wall-2.cc 
/opt/gcc-4.0-20050123-1/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_deque.h: 
In destructor 'std::_Deque_base<_Tp, _Alloc>::~_Deque_base() [with _Tp = int*, 
_Alloc = std::allocator<int*>]': 
/opt/gcc-4.0-20050123-1/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_deque.h:411: 
warning: control may reach end of non-void function 'typename 
_Alloc::rebind<_Tp*>::other std::_Deque_base<_Tp, 
_Alloc>::_M_get_map_allocator() const [with _Tp = int*, _Alloc = 
std::allocator<int*>]' being inlined 
/opt/gcc-4.0-20050123-1/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/deque.tcc: 
In member function 'void std::deque<_Tp, _Alloc>::_M_reallocate_map(size_t, 
bool) [with _Tp = int*, _Alloc = std::allocator<int*>]': 
/opt/gcc-4.0-20050123-1/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/deque.tcc:750: 
warning: control may reach end of non-void function '_Tp** 
std::_Deque_base<_Tp, _Alloc>::_M_allocate_map(size_t) [with _Tp = int*, 
_Alloc = std::allocator<int*>]' being inlined 
 
> g++-4.0-20050123-1 -v 
Using built-in specs. 
Configured with: ../gcc-4.0-20050123/configure 
--prefix=/opt/gcc-4.0-20050123-1 --enable-shared --enable-languages=c,c++ 
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu 
--disable-nls --program-suffix=-4.0-20050123-1 --disable-checking 
--with-arch=pentium3 
Thread model: posix 
gcc version 4.0.0 20050123 (experimental) 
 
Comment 17 Ian Lance Taylor 2005-01-27 02:47:37 UTC
Another patch here:
    http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01964.html
Comment 18 GCC Commits 2005-01-27 14:36:47 UTC
Subject: Bug 19583

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ian@gcc.gnu.org	2005-01-27 14:36:22

Modified files:
	gcc            : ChangeLog gimple-low.c tree-inline.c 

Log message:
	PR middle-end/19583
	* gimple-low.c (try_catch_may_fallthru): New static function.
	(block_may_fallthru): Handle TRY_CATCH_EXPR.
	* tree-inline.c (expand_call_inline): Don't warn about reaching
	the end of a non-void function being inlined if the function uses
	a return slot.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7305&r2=2.7306
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimple-low.c.diff?cvsroot=gcc&r1=2.19&r2=2.20
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-inline.c.diff?cvsroot=gcc&r1=1.169&r2=1.170

Comment 19 Ian Lance Taylor 2005-01-27 14:38:24 UTC
Fixed.
Comment 20 Martin Reinecke 2005-01-27 19:44:44 UTC
Created attachment 8085 [details]
preprocessed testcase which still gives wrong warnings
Comment 21 GCC Commits 2005-01-28 17:33:05 UTC
Subject: Bug 19583

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ian@gcc.gnu.org	2005-01-28 17:32:58

Modified files:
	gcc            : ChangeLog gimple-low.c 

Log message:
	PR middle-end/16558
	PR middle-end/19583
	* gimple-low.c (block_may_fallthru): TRY_FINALLY_EXPR only falls
	through if both operands fall through.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7319&r2=2.7320
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimple-low.c.diff?cvsroot=gcc&r1=2.20&r2=2.21

Comment 22 Lars Gullik Bjønnes 2005-01-29 19:07:06 UTC
Created attachment 8101 [details]
Preprocessed sources showing the problem

With this preprocessed sources I see the same problem when compiling with

g++ -W -Wall -O -fno-exceptions -c -o test2.o test2.ii

Removing either (or both) of -O or -fno-exceptions supresses the warnings.
Comment 23 Lars Gullik Bjønnes 2005-01-29 19:09:43 UTC
This does not seem to be fixed so reopening.
Comment 24 Andrew Pinski 2005-01-29 19:23:07 UTC
(In reply to comment #23)
> This does not seem to be fixed so reopening.
I opened another PR because it is related but not fully the same problem.  (PR 19699).
Comment 25 snyder 2005-02-08 20:18:43 UTC
(In reply to comment #24)
> (In reply to comment #23)
> > This does not seem to be fixed so reopening.
> I opened another PR because it is related but not fully the same problem.  (PR
19699).

We still (as of CVS from Feb 8) get the warning if the throw-specifier is
not empty.

This example still gives the warning with -Wall -O1:

struct E{};

inline int bar() throw(E)
{
  return 0;
}

void foo ()
{
  bar();
}
Comment 26 Ian Lance Taylor 2005-02-09 03:52:30 UTC
New patch: http://gcc.gnu.org/ml/gcc-patches/2005-02/msg00342.html
Comment 27 GCC Commits 2005-02-09 21:40:11 UTC
Subject: Bug 19583

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ian@gcc.gnu.org	2005-02-09 21:40:01

Modified files:
	gcc            : ChangeLog gimple-low.c 

Log message:
	PR middle-end/19583
	* gimple-low.c (try_catch_may_fallthru): In EH_FILTER_EXPR case,
	just check whether EH_FILTER_FAILURE falls through.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7424&r2=2.7425
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimple-low.c.diff?cvsroot=gcc&r1=2.21&r2=2.22

Comment 28 GCC Commits 2005-02-09 21:40:40 UTC
Subject: Bug 19583

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ian@gcc.gnu.org	2005-02-09 21:40:36

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/warn: Wreturn-type-3.C 

Log message:
	PR middle-end/19583
	* g++.dg/warn/Wreturn-type-3.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5008&r2=1.5009
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/Wreturn-type-3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1