public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/30368] New: wrong result
@ 2007-01-04 14:21 lidaobing at gmail dot com
2007-01-04 14:26 ` [Bug c/30368] " lidaobing at gmail dot com
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: lidaobing at gmail dot com @ 2007-01-04 14:21 UTC (permalink / raw)
To: gcc-bugs
for the following example[1], it should exit with 0, but under gcc-4.0 gcc-4.1
gcc-4.2 and all optimize level(-O0, -O1, -O2, -O3), it exit with 1;
check gcc versions in [2]
[1]
/* begin */
struct A { int b; };
int main(int argc, char **argv)
{
struct A* a = 0;
if (&a->b) return 1;
return 0;
}
/* end */
[2]
gcc version 4.0.4 20060904 (prerelease) (Debian 4.0.3-7)
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
gcc version 4.2.0 20061003 (experimental) (Debian 4.2-20061003-1)
--
Summary: wrong result
Product: gcc
Version: 4.0.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: lidaobing at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30368
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/30368] wrong result
2007-01-04 14:21 [Bug c/30368] New: wrong result lidaobing at gmail dot com
@ 2007-01-04 14:26 ` lidaobing at gmail dot com
2007-01-05 5:23 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: lidaobing at gmail dot com @ 2007-01-04 14:26 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from lidaobing at gmail dot com 2007-01-04 14:25 -------
orignal reported by RoachCock in newsmth.net BBS
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30368
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/30368] wrong result
2007-01-04 14:21 [Bug c/30368] New: wrong result lidaobing at gmail dot com
2007-01-04 14:26 ` [Bug c/30368] " lidaobing at gmail dot com
@ 2007-01-05 5:23 ` pinskia at gcc dot gnu dot org
2007-01-05 20:13 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-05 5:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2007-01-05 05:23 -------
Actually this is undefined by the C standard as you are deferencing a null
pointer, yes &a->b is implemented as a pointer arthematic but it is still a
deferencing according to the C standard.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30368
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/30368] wrong result
2007-01-04 14:21 [Bug c/30368] New: wrong result lidaobing at gmail dot com
2007-01-04 14:26 ` [Bug c/30368] " lidaobing at gmail dot com
2007-01-05 5:23 ` pinskia at gcc dot gnu dot org
@ 2007-01-05 20:13 ` pinskia at gcc dot gnu dot org
2007-01-05 21:12 ` gdr at integrable-solutions dot net
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-05 20:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2007-01-05 20:13 -------
> anther, consider an example definite[2] of 'offsetof', if you think
> that is undefined, it's almost impossible to give a definite of
> offsetof.
> #define offsetof(TYPE,MEMBER) ((size_t)&((TYPE*)0)->MEMBER)
The C standard still says that is undefined. See 6.5.3.2/4.
Also GCC has a builtin for offsetof to get around the undefinedness of the
above.
You can also define offsetof like:
#define offsetof(TYPE,MEMBER) (((size_t)&((TYPE*)128)->MEMBER) - 128)
Which gets around the undefined issue.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30368
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/30368] wrong result
2007-01-04 14:21 [Bug c/30368] New: wrong result lidaobing at gmail dot com
` (2 preceding siblings ...)
2007-01-05 20:13 ` pinskia at gcc dot gnu dot org
@ 2007-01-05 21:12 ` gdr at integrable-solutions dot net
2007-01-26 23:14 ` manu at gcc dot gnu dot org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: gdr at integrable-solutions dot net @ 2007-01-05 21:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from gdr at integrable-solutions dot net 2007-01-05 21:11 -------
Subject: Re: wrong result
"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:
| > anther, consider an example definite[2] of 'offsetof', if you think
| > that is undefined, it's almost impossible to give a definite of
| > offsetof.
|
| > #define offsetof(TYPE,MEMBER) ((size_t)&((TYPE*)0)->MEMBER)
|
| The C standard still says that is undefined. See 6.5.3.2/4.
| Also GCC has a builtin for offsetof to get around the undefinedness of the
| above.
The C front-end should probably warn -- the C++ front-end does.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30368
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/30368] wrong result
2007-01-04 14:21 [Bug c/30368] New: wrong result lidaobing at gmail dot com
` (3 preceding siblings ...)
2007-01-05 21:12 ` gdr at integrable-solutions dot net
@ 2007-01-26 23:14 ` manu at gcc dot gnu dot org
2007-03-13 16:13 ` [Bug c/30368] missing warning for dereferencing null pointer manu at gcc dot gnu dot org
2007-03-13 16:22 ` manu at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-01-26 23:14 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from manu at gcc dot gnu dot org 2007-01-26 23:14 -------
(In reply to comment #4)
> Subject: Re: wrong result
>
> "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:
>
> | > anther, consider an example definite[2] of 'offsetof', if you think
> | > that is undefined, it's almost impossible to give a definite of
> | > offsetof.
> |
> | > #define offsetof(TYPE,MEMBER) ((size_t)&((TYPE*)0)->MEMBER)
> |
> | The C standard still says that is undefined. See 6.5.3.2/4.
> | Also GCC has a builtin for offsetof to get around the undefinedness of the
> | above.
>
> The C front-end should probably warn -- the C++ front-end does.
Does it? With which options? I wasn't able to get a warning or error.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30368
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/30368] missing warning for dereferencing null pointer
2007-01-04 14:21 [Bug c/30368] New: wrong result lidaobing at gmail dot com
` (4 preceding siblings ...)
2007-01-26 23:14 ` manu at gcc dot gnu dot org
@ 2007-03-13 16:13 ` manu at gcc dot gnu dot org
2007-03-13 16:22 ` manu at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-03-13 16:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from manu at gcc dot gnu dot org 2007-03-13 16:12 -------
So the conclusion is that we should emit a warning for the undefinedness.
--
manu 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 |2007-03-13 16:12:46
date| |
Summary|wrong result |missing warning for
| |dereferencing null pointer
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30368
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/30368] missing warning for dereferencing null pointer
2007-01-04 14:21 [Bug c/30368] New: wrong result lidaobing at gmail dot com
` (5 preceding siblings ...)
2007-03-13 16:13 ` [Bug c/30368] missing warning for dereferencing null pointer manu at gcc dot gnu dot org
@ 2007-03-13 16:22 ` manu at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-03-13 16:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from manu at gcc dot gnu dot org 2007-03-13 16:22 -------
and as such, this is a duplicate of bug 16351.
*** This bug has been marked as a duplicate of 16351 ***
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30368
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-03-13 16:22 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-04 14:21 [Bug c/30368] New: wrong result lidaobing at gmail dot com
2007-01-04 14:26 ` [Bug c/30368] " lidaobing at gmail dot com
2007-01-05 5:23 ` pinskia at gcc dot gnu dot org
2007-01-05 20:13 ` pinskia at gcc dot gnu dot org
2007-01-05 21:12 ` gdr at integrable-solutions dot net
2007-01-26 23:14 ` manu at gcc dot gnu dot org
2007-03-13 16:13 ` [Bug c/30368] missing warning for dereferencing null pointer manu at gcc dot gnu dot org
2007-03-13 16:22 ` manu 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).