From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13129 invoked by alias); 10 Apr 2012 07:40:58 -0000 Received: (qmail 12972 invoked by uid 22791); 10 Apr 2012 07:40:56 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Apr 2012 07:40:38 +0000 From: "fredrik.hederstierna@securitas-direct.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/52923] New: Warn if making external references to local stack memory Date: Tue, 10 Apr 2012 07:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: fredrik.hederstierna@securitas-direct.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-04/txt/msg00587.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52923 Bug #: 52923 Summary: Warn if making external references to local stack memory Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: fredrik.hederstierna@securitas-direct.com Created attachment 27123 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27123 Example code with functions returning with stack memory refs bugs. GCC does warn if returning a pointer to a local variable (stack memory). But there are alot of more cases where GCC could possibly warn, eg. when references are made to local variables or stack memory. See this attached example code. GCC warns for first case, but not the others. I think all cases can be considered program bugs, and could trigger a compiler warning I think. I've found out that the present warning is done in "c-typeck.c", is this the right place to but additional warnings of this kind too? Thanks & Best Regards Fredrik Hederstierna The example code file was compiled with "-O2 -W -Wall -Wextra" for enabling as many warnings as possible.