This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] lower gimple: Sustain line number info for returns if possible
> I opened:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47646
Hi,
this should fix the testsuite regressions.
There are two changes caused by having line number info at some return
statements now:
1. "may be uninitialized" warnings will be issued either for the using
statement or for the var decl. Now we run into the first (preferred)
case if the return statement is the only user of the variable.
2. "'noreturn' function does return" will now be issued for the return
if possible otherwise the code still falls back to the function end
location.
I've adjusted the testcases accordingly.
Ok for mainline?
Bye,
-Andreas-
2011-02-08 Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
PR middle-end/47646
* gcc.dg/pr39666-2.c (foo2): If the location of the statement
using the variable is known the warning is emitted there.
* gcc.dg/uninit-pr19430.c (foo): Likewise.
* g++.dg/warn/Wuninitialized-5.C (foo): Likewise.
* c-c++-common/pr20000.c (g): Both warnings occur at the return
statement.
(vg): Likewise.
* gcc.dg/noreturn-1.c (foo5): Likewise.
* objc.dg/attributes/method-noreturn-1.m (method1): Likewise.
(method2): Likewise.
* gfortran.dg/pr25923.f90 (baz): The warning will now be issued for
the return statement using the uninitialized variable.
* gfortran.dg/pr39666-2.f90 (f): Likewise.
Index: gcc/testsuite/gcc.dg/pr39666-2.c
===================================================================
*** gcc/testsuite/gcc.dg/pr39666-2.c.orig
--- gcc/testsuite/gcc.dg/pr39666-2.c
***************
*** 5,11 ****
int
foo (int i)
{
! int j; /* { dg-warning "may be used uninitialized" } */
switch (i)
{
case -__INT_MAX__ - 1 ... -1:
--- 5,11 ----
int
foo (int i)
{
! int j;
switch (i)
{
case -__INT_MAX__ - 1 ... -1:
*************** foo (int i)
*** 18,22 ****
j = 4;
break;
}
! return j;
}
--- 18,22 ----
j = 4;
break;
}
! return j; /* { dg-warning "may be used uninitialized" } */
}
Index: gcc/testsuite/gcc.dg/uninit-pr19430.c
===================================================================
*** gcc/testsuite/gcc.dg/uninit-pr19430.c.orig
--- gcc/testsuite/gcc.dg/uninit-pr19430.c
*************** foo (int i)
*** 18,25 ****
int foo2( void ) {
! int rc; /* { dg-warning "'rc' is used uninitialized in this function" } */
! return rc;
*&rc = 0;
}
--- 18,25 ----
int foo2( void ) {
! int rc;
! return rc; /* { dg-warning "'rc' is used uninitialized in this function" } */
*&rc = 0;
}
Index: gcc/testsuite/c-c++-common/pr20000.c
===================================================================
*** gcc/testsuite/c-c++-common/pr20000.c.orig
--- gcc/testsuite/c-c++-common/pr20000.c
*************** void h(void) __attribute__((noreturn));
*** 10,16 ****
int g(void) {
return 1; /* { dg-warning "function declared 'noreturn' has a 'return' statement" } */
! } /* { dg-warning "'noreturn' function does return" } */
int g2(void) {
h();
--- 10,16 ----
int g(void) {
return 1; /* { dg-warning "function declared 'noreturn' has a 'return' statement" } */
! } /* { dg-warning "'noreturn' function does return" "" { target *-*-* } 12 } */
int g2(void) {
h();
*************** int vg2(void); /* { dg-bogus ".noreturn.
*** 25,31 ****
int vg(void) {
return 1; /* { dg-warning "function declared 'noreturn' has a 'return' statement" "" { target c } 27 } */
! } /* { dg-warning "'noreturn' function does return" "" { target c } 28 } */
int vg2(void) {
h();
--- 25,31 ----
int vg(void) {
return 1; /* { dg-warning "function declared 'noreturn' has a 'return' statement" "" { target c } 27 } */
! } /* { dg-warning "'noreturn' function does return" "" { target c } 27 } */
int vg2(void) {
h();
Index: gcc/testsuite/gcc.dg/noreturn-1.c
===================================================================
*** gcc/testsuite/gcc.dg/noreturn-1.c.orig
--- gcc/testsuite/gcc.dg/noreturn-1.c
*************** void
*** 35,41 ****
foo5(void)
{
return; /* { dg-warning "'noreturn' has a 'return' statement" "detect invalid return" } */
! } /* { dg-warning "function does return" "detect return from noreturn" } */
extern void foo6(void);
void
--- 35,41 ----
foo5(void)
{
return; /* { dg-warning "'noreturn' has a 'return' statement" "detect invalid return" } */
! } /* { dg-warning "function does return" "detect return from noreturn" { target c } 37 } */
extern void foo6(void);
void
Index: gcc/testsuite/g++.dg/warn/Wuninitialized-5.C
===================================================================
*** gcc/testsuite/g++.dg/warn/Wuninitialized-5.C.orig
--- gcc/testsuite/g++.dg/warn/Wuninitialized-5.C
***************
*** 5,11 ****
int
foo (int i)
{
! int j; // { dg-warning "may be used uninitialized" }
switch (i)
{
case -__INT_MAX__ - 1 ... -1:
--- 5,11 ----
int
foo (int i)
{
! int j;
switch (i)
{
case -__INT_MAX__ - 1 ... -1:
*************** foo (int i)
*** 18,22 ****
j = 4;
break;
}
! return j;
}
--- 18,22 ----
j = 4;
break;
}
! return j; // { dg-warning "may be used uninitialized" }
}
Index: gcc/testsuite/gfortran.dg/pr25923.f90
===================================================================
*** gcc/testsuite/gfortran.dg/pr25923.f90.orig
--- gcc/testsuite/gfortran.dg/pr25923.f90
*************** implicit none
*** 10,16 ****
contains
! function baz(arg) result(res) ! { dg-warning "res.yr' may be" "PR45505" { xfail ilp32 } }
type(bar), intent(in) :: arg
type(bar) :: res
logical, external:: some_func
--- 10,16 ----
contains
! function baz(arg) result(res) ! { dg-bogus "res.yr' may be" "PR45505" { xfail ilp32 } }
type(bar), intent(in) :: arg
type(bar) :: res
logical, external:: some_func
*************** contains
*** 19,25 ****
else
res = arg
end if
! end function baz ! { dg-bogus "res.yr' may be" "PR45505" { xfail ilp32 } }
end module foo
--- 19,25 ----
else
res = arg
end if
! end function baz ! { dg-warning "res.yr' may be" "PR45505" { xfail ilp32 } }
end module foo
Index: gcc/testsuite/gfortran.dg/pr39666-2.f90
===================================================================
*** gcc/testsuite/gfortran.dg/pr39666-2.f90.orig
--- gcc/testsuite/gfortran.dg/pr39666-2.f90
***************
*** 2,8 ****
! { dg-do compile }
! { dg-options "-O2 -Wuninitialized" }
! FUNCTION f(n) ! { dg-warning "may be used uninitialized" }
INTEGER, INTENT(in) :: n
REAL :: f
--- 2,8 ----
! { dg-do compile }
! { dg-options "-O2 -Wuninitialized" }
! FUNCTION f(n)
INTEGER, INTENT(in) :: n
REAL :: f
*************** FUNCTION f(n) ! { dg-warning "may be use
*** 11,14 ****
CASE (0); f = 0.0
CASE (2:); f = 1.0
END SELECT
! END FUNCTION
--- 11,14 ----
CASE (0); f = 0.0
CASE (2:); f = 1.0
END SELECT
! END FUNCTION ! { dg-warning "may be used uninitialized" }
Index: gcc/testsuite/objc.dg/attributes/method-noreturn-1.m
===================================================================
*** gcc/testsuite/objc.dg/attributes/method-noreturn-1.m.orig
--- gcc/testsuite/objc.dg/attributes/method-noreturn-1.m
***************
*** 18,28 ****
+ (id) method1
{
return self; /* { dg-warning "function declared .noreturn. has a .return. statement" } */
! } /* { dg-warning ".noreturn. function does return" } */
- (id) method2
{
return self; /* { dg-warning "function declared .noreturn. has a .return. statement" } */
! } /* { dg-warning ".noreturn. function does return" } */
+ (id) method3
{
abort ();
--- 18,28 ----
+ (id) method1
{
return self; /* { dg-warning "function declared .noreturn. has a .return. statement" } */
! } /* { dg-warning ".noreturn. function does return" "" { target *-*-* } 20 } */
- (id) method2
{
return self; /* { dg-warning "function declared .noreturn. has a .return. statement" } */
! } /* { dg-warning ".noreturn. function does return" "" { target *-*-* } 24 } */
+ (id) method3
{
abort ();