Re: ANSI alias rules checker in GCC, other optimizing compilers

Ian Lance Taylor <ian@airs.com>
17 Jan 2007 17:44:17 -0500

          From comp.compilers

Related articles
ANSI alias rules checker in GCC, other optimizing compilers andreybokhanko@gmail.com (2007-01-16)
Re: ANSI alias rules checker in GCC, other optimizing compilers ian@airs.com (Ian Lance Taylor) (2007-01-17)
Re: ANSI alias rules checker in GCC, other optimizing compilers andreybokhanko@gmail.com (Andrey Bokhanko) (2007-01-17)
Re: ANSI alias rules checker in GCC, other optimizing compilers andreybokhanko@gmail.com (Andrey Bokhanko) (2007-01-17)
Re: ANSI alias rules checker in GCC, other optimizing compilers ian@airs.com (Ian Lance Taylor) (2007-01-17)
Re: ANSI alias rules checker in GCC, other optimizing compilers silvius.rus@gmail.com (Silvius Rus) (2007-01-17)
Re: ANSI alias rules checker in GCC, other optimizing compilers ajonospam@andrew.cmu.edu (Arthur J. O'Dwyer) (2007-01-18)
Re: ANSI alias rules checker in GCC, other optimizing compilers andreybokhanko@gmail.com (2007-01-20)
| List of all articles for this month |

From: Ian Lance Taylor <ian@airs.com>
Newsgroups: comp.compilers
Date: 17 Jan 2007 17:44:17 -0500
Organization: Compilers Central
References: 07-01-047
Keywords: C, GCC, analysis, types, comment
Posted-Date: 17 Jan 2007 17:44:17 EST

"Andrey Bokhanko" <andreybokhanko@gmail.com> writes:


> If you allow me, a (possibly) stupid question: what do you mean by
> "restrict qualified pointers"? Pointers with "restrict" C keyword?


Yes.


> If yes, does "-Wstrict-aliasing=2" warns on something like this?
>
> void foo(restrict int *p1) {
> int *p2;
> p2 = p1; // p2 points to a restricted memory area, GCC warns?
> ...
> }


Well, the current warning only applies to code which casts the address
of an object. That is, when I said "(T*)&x" I really meant it. So,
no, gcc is not going to give a warning for code like your example.


> Also, can you give me examples of cases when GCC generates false
> warnings and when it doesn't catch "proper" ANSI rules violations?


gcc currently generates a false warning for:


int i;
void foo () { short *p = (short *)&i; *(int *)p = 1; }


gcc currently does not generate a warning fo:


int i;
void foo () { short *p = (short *)(void *)&i; *p = 1; }


> Is it due to internal GCC issues (like losing some type information
> in IR) or due to perplexities of ANSI rules?


It's because the current warning implementation is very simple-minded.


> And the last question: are your colleague based his implementation on
> an openly available paper, or devised everything himself?


He devised everything himself, based on the existing alias analysis
code in gcc. That is, he does not attempt to warn about any possible
aliasing violation; he only warns about those aliasing violations
which gcc is able to exploit.


Ian
[Those warnings seem appropriate. Casting int* to short* depends on
byte order, (void *) is your way to say you know, you don't
care. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.