public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14156] New: no warning for address of parameter
@ 2004-02-16  9:56 d dot binderman at virgin dot net
  2004-02-16 12:17 ` [Bug c++/14156] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: d dot binderman at virgin dot net @ 2004-02-16  9:56 UTC (permalink / raw)
  To: gcc-bugs

// Given the following C++ source code

int * f( int a)
{
	return &a;
}

int * g()
{
	int b = 0;

	return &b;
}

/*
then

[dcb@localhost src]$ ~/gnu/gcc333pre2/results/bin/g++ -c -g -O2 -Wall -ansi
-pedantic addrLocal.cc
addrLocal.cc: In function `int* g()':
addrLocal.cc:9: warning: address of local variable `b' returned
[dcb@localhost src]$

Note only one warning message.  
G++ 333 pre release version 2 doesn't find the problem in function f.  
G++ 332 also doesn't find the problem.

Here is Intel C++ doing what I want.

[dcb@localhost src]$ icc -c addrLocal.cc
addrLocal.cc(6): warning #1251: returning pointer to local variable
        return &a;
               ^

addrLocal.cc(13): warning #1251: returning pointer to local variable
        return &b;
               ^

This bug report boiled down from real code in Fedora Core 1.

*/

-- 
           Summary: no warning for address of parameter
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: d dot binderman at virgin dot net
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: linux / x86


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


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

* [Bug c++/14156] no warning for address of parameter
  2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
@ 2004-02-16 12:17 ` pinskia at gcc dot gnu dot org
  2004-02-16 12:36 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-02-16 12:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-02-16 12:17 -------
Confirmed, this is an easy fix.
Checking also for PARM_DECL is what is needed:
Index: c-typeck.c
===============================================================
====
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.277
diff -u -p -r1.277 c-typeck.c
--- c-typeck.c  12 Feb 2004 19:14:05 -0000      1.277
+++ c-typeck.c  16 Feb 2004 12:14:54 -0000
@@ -6207,7 +6207,8 @@ c_expand_return (tree retval)
              while (TREE_CODE_CLASS (TREE_CODE (inner)) == 'r')
                inner = TREE_OPERAND (inner, 0);
 
-             if (TREE_CODE (inner) == VAR_DECL
+             if ((TREE_CODE (inner) == VAR_DECL
+                  || TREE_CODE (inner) == PARM_DECL)
                  && ! DECL_EXTERNAL (inner)
                  && ! TREE_STATIC (inner)
                  && DECL_CONTEXT (inner) == current_function_decl)
Index: typeck.c
===============================================================
====
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.528
diff -u -p -r1.528 typeck.c
--- typeck.c    14 Feb 2004 00:49:12 -0000      1.528
+++ typeck.c    16 Feb 2004 12:16:14 -0000
@@ -5884,7 +5884,8 @@ maybe_warn_about_returning_address_of_lo
        }
     }
 
-  if (TREE_CODE (whats_returned) == VAR_DECL
+  if ((TREE_CODE (whats_returned) == VAR_DECL
+       || TREE_CODE (whats_returned) == PARM_DECL)
       && DECL_NAME (whats_returned)
       && DECL_FUNCTION_SCOPE_P (whats_returned)
       && !(TREE_STATIC (whats_returned)

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pinskia at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2004-02-16 12:17:11
               date|                            |
   Target Milestone|---                         |3.5.0


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


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

* [Bug c++/14156] no warning for address of parameter
  2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
  2004-02-16 12:17 ` [Bug c++/14156] " pinskia at gcc dot gnu dot org
@ 2004-02-16 12:36 ` pinskia at gcc dot gnu dot org
  2004-02-16 13:18 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-02-16 12:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-02-16 12:36 -------
Patch here: http://gcc.gnu.org/ml/gcc-patches/2004-02/msg01407.html.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


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


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

* [Bug c++/14156] no warning for address of parameter
  2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
  2004-02-16 12:17 ` [Bug c++/14156] " pinskia at gcc dot gnu dot org
  2004-02-16 12:36 ` pinskia at gcc dot gnu dot org
@ 2004-02-16 13:18 ` pinskia at gcc dot gnu dot org
  2004-02-23 15:22 ` cvs-commit at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-02-16 13:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-02-16 13:18 -------
New patch which also fixes it for returning fields parts of structs:
http://gcc.gnu.org/ml/gcc-patches/2004-02/msg01412.html

This will now warn:
struct ll
{
  int i;
};
int *h(struct ll c)
{
  return &c.i;/* { dg-warning "address" "" } */
}

-- 


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


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

* [Bug c++/14156] no warning for address of parameter
  2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
                   ` (2 preceding siblings ...)
  2004-02-16 13:18 ` pinskia at gcc dot gnu dot org
@ 2004-02-23 15:22 ` cvs-commit at gcc dot gnu dot org
  2004-02-23 15:27 ` cvs-commit at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-02-23 15:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-02-23 15:22 -------
Subject: Bug 14156

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pinskia@gcc.gnu.org	2004-02-23 15:22:12

Modified files:
	gcc            : ChangeLog c-typeck.c 
	gcc/cp         : ChangeLog typeck.c 

Log message:
	PR c/14156
	* c-typeck.c (c_expand_return): Change check for VAR_DECL
	to use DECL_P instead.
	
	PR c++/14156
	* typeck.c (maybe_warn_about_returning_address_of_location):
	Change check for VAR_DECL to use DECL_P instead.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.2892&r2=2.2893
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.278&r2=1.279
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3967&r2=1.3968
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.528&r2=1.529



-- 


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


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

* [Bug c++/14156] no warning for address of parameter
  2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
                   ` (3 preceding siblings ...)
  2004-02-23 15:22 ` cvs-commit at gcc dot gnu dot org
@ 2004-02-23 15:27 ` cvs-commit at gcc dot gnu dot org
  2004-02-23 15:29 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-02-23 15:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-02-23 15:27 -------
Subject: Bug 14156

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pinskia@gcc.gnu.org	2004-02-23 15:27:49

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: 20040223-1.c 

Log message:
	2004-02-23  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR c/14156
	* gcc.dg/20040223-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3533&r2=1.3534
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20040223-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


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


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

* [Bug c++/14156] no warning for address of parameter
  2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
                   ` (4 preceding siblings ...)
  2004-02-23 15:27 ` cvs-commit at gcc dot gnu dot org
@ 2004-02-23 15:29 ` pinskia at gcc dot gnu dot org
  2004-02-23 21:00 ` d dot binderman at virgin dot net
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-02-23 15:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-02-23 15:29 -------
Fixed for 3.5.0 (will have to revisit when I change the front-ends for the tree-ssa though but I already 
have a patch for it).

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug c++/14156] no warning for address of parameter
  2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
                   ` (5 preceding siblings ...)
  2004-02-23 15:29 ` pinskia at gcc dot gnu dot org
@ 2004-02-23 21:00 ` d dot binderman at virgin dot net
  2004-02-23 21:36 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: d dot binderman at virgin dot net @ 2004-02-23 21:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From d dot binderman at virgin dot net  2004-02-23 21:00 -------

>Fixed for 3.5.0

The value of your patch, especially to the Redhat Fedora team,
would be considerably increased if it could be available in a sooner
version than 3.5, which is probably a couple years away.

Patch possible for 3.3.4 ?
 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


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


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

* [Bug c++/14156] no warning for address of parameter
  2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
                   ` (6 preceding siblings ...)
  2004-02-23 21:00 ` d dot binderman at virgin dot net
@ 2004-02-23 21:36 ` pinskia at gcc dot gnu dot org
  2004-02-23 22:41 ` bangerth at dealii dot org
  2004-03-11  5:45 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-02-23 21:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-02-23 21:36 -------
I am not going to deal with this junk, this never worked so I am closing this as fixed for 3.5.0 and if you 
want it in for 3.3.4 or 3.4.0, please ask for yourself.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug c++/14156] no warning for address of parameter
  2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
                   ` (7 preceding siblings ...)
  2004-02-23 21:36 ` pinskia at gcc dot gnu dot org
@ 2004-02-23 22:41 ` bangerth at dealii dot org
  2004-03-11  5:45 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2004-02-23 22:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-02-23 22:41 -------
3.3.4 will almost certainly not get this patch, since it is not 
a regression. 
 
Regarding 3.4: this is the RM's call. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mmitchel at gcc dot gnu dot
                   |                            |org


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


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

* [Bug c++/14156] no warning for address of parameter
  2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
                   ` (8 preceding siblings ...)
  2004-02-23 22:41 ` bangerth at dealii dot org
@ 2004-03-11  5:45 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-11  5:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-11 05:45 -------
*** Bug 14519 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jhaltom at feedbackplusinc
                   |                            |dot com


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


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

end of thread, other threads:[~2004-03-11  5:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-16  9:56 [Bug c++/14156] New: no warning for address of parameter d dot binderman at virgin dot net
2004-02-16 12:17 ` [Bug c++/14156] " pinskia at gcc dot gnu dot org
2004-02-16 12:36 ` pinskia at gcc dot gnu dot org
2004-02-16 13:18 ` pinskia at gcc dot gnu dot org
2004-02-23 15:22 ` cvs-commit at gcc dot gnu dot org
2004-02-23 15:27 ` cvs-commit at gcc dot gnu dot org
2004-02-23 15:29 ` pinskia at gcc dot gnu dot org
2004-02-23 21:00 ` d dot binderman at virgin dot net
2004-02-23 21:36 ` pinskia at gcc dot gnu dot org
2004-02-23 22:41 ` bangerth at dealii dot org
2004-03-11  5:45 ` pinskia at gcc dot gnu dot 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).