This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/71924] New: missing -Wreturn-local-addr returning alloca result
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 19 Jul 2016 00:37:19 +0000
- Subject: [Bug c/71924] New: missing -Wreturn-local-addr returning alloca result
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71924
Bug ID: 71924
Summary: missing -Wreturn-local-addr returning alloca result
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
All three functions defined in the following example return an address of a
stack object, but GCC only issues a -Wreturn-local-addr warning for two of them
and not for the one where alloca was used to allocated the stack object. The
warning should be issued for all three functions.
Note that the warning comes and goes with the value of the size argument, and
is not issued when the argument is not constant (the warning is, however,
issued for VLAs).
Also, the note printed following the second warning is wrong (the object isn't
declared) and points to the wrong location (to be useful, it should point to
the line containing either the declaration of the local object or the
invocation of the alloca function).
$ cat walloca.c && /build/gcc-walloca/gcc/xgcc -B /build/gcc-walloca/gcc -S
-Wall -Wextra -Wpedantic walloca.c
void* foo (void)
{
char a [4];
return a;
}
void* bar (void)
{
void *a = __builtin_alloca (4);
return a;
}
void* baz (void)
{
void *a = __builtin_alloca_with_align (4, 8);
return a;
}
walloca.c: In function ‘foo’:
walloca.c:4:10: warning: function returns address of local variable
[-Wreturn-local-addr]
return a;
^
walloca.c: In function ‘baz’:
walloca.c:16:10: warning: function returns address of local variable
[-Wreturn-local-addr]
return a;
^
walloca.c:17:1: note: declared here
}
^