public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "acahalan at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/28778] [4.0/4.1/4.2 Regression] alias bug with cast and call clobbered
Date: Tue, 26 Sep 2006 15:33:00 -0000	[thread overview]
Message-ID: <20060926153329.14801.qmail@sourceware.org> (raw)
In-Reply-To: <bug-28778-1447@http.gcc.gnu.org/bugzilla/>



------- Comment #37 from acahalan at gmail dot com  2006-09-26 15:33 -------
(In reply to comment #36)

> > Evidence: this bug has existed for ages, meanwhile aliasing violations keep
> > getting reported as compiler bugs.
> This bug (PR28778) has only existed for the last two major releases which is
> not ages.

IMHO that qualifies as "ages". If the bug has survived that long, it
can't be all that major. People have learned that -fno-strict-aliasing
is the cure-all for mystery bugs.

> > Since gcc introduced strict aliasing, I've worked at three places doing
> > software development. All were embedded/OS related, so I would say the people
> > are/were hard-core programmers with a clue. Everybody is shocked when I explain
> > strict-aliasing, and all but one have been horrified.
> 
> And Aliasing rules in C have existed now for at least 17 years.

Your point?

Fact: strict aliasing horrifies most software developers.

The wording in a seriously expensive ISO document doesn't
change the simple fact that people don't write code that way.
Books intended to teach the language don't mention this
"feature" of the language. I don't just mean "Learn C in
5 days", but college textbooks as well.

> > So, to get back to this bug specifically: treating a (void*) arg the same as a
> > (char*) arg will cover up the problem for nearly everyone. Sadly it won't fix
> > the example given, which is legit to a language lawyer and a nonsense piece of
> > shit to any normal programmer. Oh well. By treating (void*) the same as
> > (char*), you can demote the bug severity greatly and move on.
> 
> Again, aliasing in C has to do with accesses and nothing to the type of
> pointers.

I know. I'm perfectly clear on that. You don't need to remind me.

If the example code had used (char*), the bug would not have shown
itself. Great. Most real-world code would use (void*) for this.
That breaks. If (void*) is treated the same as (char*) though, the
bug goes away. That is, an access to "void" (which is pretty much
impossible except for computed goto) should be considered to be
something which could happen and which could alias with anything.
Probably this fixes 99% of the real-world occurances of this bug.

Given such a change, the remaining bug is an insignificant
violation of the C standard. For the next release it can be
either ignored or addressed by having both -std=c99 and -std=c89
disable strict aliasing.

> > BTW, in the testcase, the following line should generate a warning:
> > 
> > glChoosePixelFormat((GLint*)blist);
> 
> Why there is nothing questionable about it until glChoosePixelFormat deferences
> the agrument in the wrong type.

It's not illegal, and thus not an error, but it damn well is questionable.
Normal people cast to/from (void*), because this comes free in C or because it
seems clean to use (void*) as the generic pointer type. People trying to avoid
aliasing problems cast to/form (char*), and use (char*) as the generic pointer
type. Other casts between pointers to types not allowed to alias are highly
suspect.


-- 


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


  parent reply	other threads:[~2006-09-26 15:33 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-18 21:07 [Bug tree-optimization/28778] New: strict-aliasing bug mrs at apple dot com
2006-08-18 21:11 ` [Bug tree-optimization/28778] " pinskia at gcc dot gnu dot org
2006-08-18 21:12 ` mrs at apple dot com
2006-08-18 21:15 ` pinskia at gcc dot gnu dot org
2006-08-18 21:18 ` [Bug tree-optimization/28778] [4.0/4.1/4.2 Regression] alias bug with cast and call clobbered pinskia at gcc dot gnu dot org
2006-08-19 10:15 ` rguenth at gcc dot gnu dot org
2006-08-19 10:44 ` rguenth at gcc dot gnu dot org
2006-08-19 14:10 ` dberlin at gcc dot gnu dot org
2006-08-19 14:27 ` rguenth at gcc dot gnu dot org
2006-08-20 22:53 ` mmitchel at gcc dot gnu dot org
2006-08-21  1:34 ` dberlin at dberlin dot org
2006-08-21 16:34 ` janis at gcc dot gnu dot org
2006-08-25 19:57 ` drow at gcc dot gnu dot org
2006-08-25 20:51 ` drow at gcc dot gnu dot org
2006-08-25 20:57 ` drow at gcc dot gnu dot org
2006-08-25 22:12 ` drow at gcc dot gnu dot org
2006-08-26 15:15 ` drow at gcc dot gnu dot org
2006-08-26 20:30 ` rguenth at gcc dot gnu dot org
2006-08-26 20:42 ` rguenth at gcc dot gnu dot org
2006-08-26 23:25 ` drow at gcc dot gnu dot org
2006-08-27  4:12 ` dberlin at dberlin dot org
2006-08-27 14:20 ` rguenth at gcc dot gnu dot org
2006-08-27 15:41 ` dberlin at dberlin dot org
2006-08-27 15:50 ` rguenth at gcc dot gnu dot org
2006-08-27 16:00 ` dberlin at dberlin dot org
2006-08-27 17:56 ` drow at gcc dot gnu dot org
2006-08-27 20:25 ` mmitchel at gcc dot gnu dot org
2006-08-27 20:28 ` mmitchel at gcc dot gnu dot org
2006-08-27 20:51 ` dberlin at dberlin dot org
2006-08-27 21:09 ` dberlin at dberlin dot org
2006-08-28  8:43 ` rguenth at gcc dot gnu dot org
2006-09-09 17:55 ` dberlin at dberlin dot org
2006-09-16 18:09 ` steven at gcc dot gnu dot org
2006-09-16 20:03 ` dberlin at dberlin dot org
2006-09-26  4:44 ` acahalan at gmail dot com
2006-09-26  4:56   ` Andrew Pinski
2006-09-26  4:56 ` pinskia at physics dot uc dot edu
2006-09-26 14:17 ` acahalan at gmail dot com
2006-09-26 14:32 ` pinskia at gcc dot gnu dot org
2006-09-26 15:33 ` acahalan at gmail dot com [this message]
2006-09-26 15:47 ` dberlin at dberlin dot org
2006-09-26 15:49 ` pinskia at gcc dot gnu dot org
2006-09-26 15:57 ` pcarlini at suse dot de
2006-09-27  2:12 ` dberlin at dberlin dot org
2006-10-13 17:50 ` dberlin at gcc dot gnu dot org
2006-10-19 23:06 ` dberlin at gcc dot gnu dot org
2006-10-19 23:07 ` dberlin at gcc dot gnu dot org
2006-10-20  8:25 ` [Bug tree-optimization/28778] [4.0/4.1 " rguenth at gcc dot gnu dot org
2006-11-05 22:17 ` chuck at vertica dot com
2006-11-05 22:26 ` drow at gcc dot gnu dot org
2006-11-05 22:26 ` pinskia at gcc dot gnu dot org
2006-11-05 23:39 ` chuck at vertica dot com
2007-01-25 15:51 ` gdr at gcc dot gnu dot org
2007-02-07 22:52 ` pinskia at gcc dot gnu dot org
2007-02-14  9:09 ` mmitchel at gcc dot gnu dot org
2008-07-04 15:51 ` [Bug tree-optimization/28778] [4.1 " jsm28 at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060926153329.14801.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).