public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/37755] New: Mistaken Segmentation fault
@ 2008-10-06 21:16 charpour at gnet dot gr
2008-10-06 21:26 ` [Bug c/37755] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: charpour at gnet dot gr @ 2008-10-06 21:16 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 999 bytes --]
GCC Version: 4.2.3
Host: Ubuntu 8.04
When I compile the following code:
#include <stdio.h>
typedef struct person {
char name[40];
int age;
} Person;
static Person make_person(void);
int main(void) {
printf("%s\n", make_person().name);
return 0;
}
static Person make_person(void) {
static Person p = { "alexander", 18 };
return p;
}
I get a false warning:
warning: format %s expects type char *, but argument 2 has type char[40]
and when I execute the file I get a segmentation fault.
If I use: printf("%s\n", &make_person().name[0]);
everything works as expected and the output "alexander" is printed
--
Summary: Mistaken Segmentation fault
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: charpour at gnet dot gr
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37755
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/37755] Mistaken Segmentation fault
2008-10-06 21:16 [Bug c/37755] New: Mistaken Segmentation fault charpour at gnet dot gr
2008-10-06 21:26 ` [Bug c/37755] " pinskia at gcc dot gnu dot org
@ 2008-10-06 21:26 ` pinskia at gcc dot gnu dot org
2008-10-06 21:40 ` joseph at codesourcery dot com
2008-10-07 7:39 ` rguenth at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-10-06 21:26 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2008-10-06 21:25 -------
Confirmed.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2008-10-06 21:25:33
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37755
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/37755] Mistaken Segmentation fault
2008-10-06 21:16 [Bug c/37755] New: Mistaken Segmentation fault charpour at gnet dot gr
@ 2008-10-06 21:26 ` pinskia at gcc dot gnu dot org
2008-10-06 21:26 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-10-06 21:26 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2008-10-06 21:25 -------
I don't get a seg fault on ppc but I do on x86. It works correctly for the C++
front-end where the array decays into a pointer.
The warning is also bogus but it shows what the issue is really.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic, wrong-code
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37755
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/37755] Mistaken Segmentation fault
2008-10-06 21:16 [Bug c/37755] New: Mistaken Segmentation fault charpour at gnet dot gr
2008-10-06 21:26 ` [Bug c/37755] " pinskia at gcc dot gnu dot org
2008-10-06 21:26 ` pinskia at gcc dot gnu dot org
@ 2008-10-06 21:40 ` joseph at codesourcery dot com
2008-10-07 7:39 ` rguenth at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: joseph at codesourcery dot com @ 2008-10-06 21:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from joseph at codesourcery dot com 2008-10-06 21:39 -------
Subject: Re: New: Mistaken Segmentation fault
On Mon, 6 Oct 2008, charpour at gnet dot gr wrote:
> printf("%s\n", make_person().name);
make_person().name is a non-lvalue array, so it only decays to a pointer
for C99, not for C90. If you use -std=c99/-std=gnu99 then the program
works.
The program does not, however, have defined behavior for C99, only for
C1x. In C99 the lifetime of the array ends at the next sequence point,
before the call to printf. In C1x it instead ends at the end of the
evaluation of the containing full expression, which is the call to printf.
I do not believe any changes to GCC are needed to implement this
particular C1x requirement, since GCC discards information about variables
lifetimes smaller than a function for gimplification and tree
optimizations that may change those lifetimes, so it will in practice
treat the lifetime as being anywhere it cannot show the temporary not to
be live.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37755
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/37755] Mistaken Segmentation fault
2008-10-06 21:16 [Bug c/37755] New: Mistaken Segmentation fault charpour at gnet dot gr
` (2 preceding siblings ...)
2008-10-06 21:40 ` joseph at codesourcery dot com
@ 2008-10-07 7:39 ` rguenth at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-10-07 7:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from rguenth at gcc dot gnu dot org 2008-10-07 07:37 -------
As Joseph said. Invalid for -std=c89, worksforme for -std=c99. No changes
needed for -std=c1x.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37755
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-10-07 7:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-06 21:16 [Bug c/37755] New: Mistaken Segmentation fault charpour at gnet dot gr
2008-10-06 21:26 ` [Bug c/37755] " pinskia at gcc dot gnu dot org
2008-10-06 21:26 ` pinskia at gcc dot gnu dot org
2008-10-06 21:40 ` joseph at codesourcery dot com
2008-10-07 7:39 ` rguenth 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).