public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26492]  New: -Wstrict-aliasing=2 warns about explicitly allowed cast to pointer to union.
@ 2006-02-28  1:09 bartoldeman at users dot sourceforge dot net
  2006-02-28  1:10 ` [Bug c/26492] " pinskia at gcc dot gnu dot org
  2006-02-28  1:29 ` bartoldeman at users dot sourceforge dot net
  0 siblings, 2 replies; 3+ messages in thread
From: bartoldeman at users dot sourceforge dot net @ 2006-02-28  1:09 UTC (permalink / raw)
  To: gcc-bugs

In a discussion about aliasing, some aliasing was explicitly allowed: see
http://gcc.gnu.org/ml/gcc/1999-06n/msg00294.html
from Mark Mitchell.

quote: "

  extern void printf(const char*, ...);

  #define noalias(type, ptr) \
    (((union { type __x__; __typeof__(*(ptr)) __y__;} *)(ptr))->__x__)

  typedef unsigned short usa[2];

  int
  main ()
  {
      int a = 0x12345678;
      printf ("%x\n", a);
      noalias(usa, &a)[1] = 0;
      printf ("%x\n", a);

      return 0;
  }

Here's what I get:

  linux1.codesourcery.com% ./a.out
  12345678
  5678

which is I think what you expected.  
"
This still works, but with gcc 4.0.3 and -Wstrict-aliasing=2 I see:
(using #include <stdio.h> instead of extern void printf...)

$ gcc -O2 -Wstrict-aliasing=2 alias.c
alias.c: In function 'main':
alias.c:13: warning: dereferencing type-punned pointer might break
strict-aliasing rules
$ ./a.out
12345678
5678

It would be nice if the warning would not trigger in this case. Although the
documentation does not say it must trigger, this is claimed to be a documented
extension and should work warning-free IMHO.


-- 
           Summary: -Wstrict-aliasing=2 warns about explicitly allowed cast
                    to pointer to union.
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bartoldeman at users dot sourceforge dot net
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/26492] -Wstrict-aliasing=2 warns about explicitly allowed cast to pointer to union.
  2006-02-28  1:09 [Bug c/26492] New: -Wstrict-aliasing=2 warns about explicitly allowed cast to pointer to union bartoldeman at users dot sourceforge dot net
@ 2006-02-28  1:10 ` pinskia at gcc dot gnu dot org
  2006-02-28  1:29 ` bartoldeman at users dot sourceforge dot net
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-28  1:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-28 01:09 -------
Can you first read the documention of -Wstrict-aliasing=2?
-Wstrict-aliasing=2
This option is only active when -fstrict-aliasing is active. It warns about
code which might break the strict aliasing rules that the compiler is using for
optimization. This warning catches more cases than -Wstrict-aliasing, but it
will also give a warning for some ambiguous cases that are safe. 

It says this is one of the known limitations, I am not saying this cannot be
detected but since you did not mention this fact I thought you did not read the
documention like most people.


-- 


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/26492] -Wstrict-aliasing=2 warns about explicitly allowed cast to pointer to union.
  2006-02-28  1:09 [Bug c/26492] New: -Wstrict-aliasing=2 warns about explicitly allowed cast to pointer to union bartoldeman at users dot sourceforge dot net
  2006-02-28  1:10 ` [Bug c/26492] " pinskia at gcc dot gnu dot org
@ 2006-02-28  1:29 ` bartoldeman at users dot sourceforge dot net
  1 sibling, 0 replies; 3+ messages in thread
From: bartoldeman at users dot sourceforge dot net @ 2006-02-28  1:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bartoldeman at users dot sourceforge dot net  2006-02-28 01:27 -------
I am sorry about not being clear: I did read the documentation.

With
"Although the documentation does not say it must trigger, ..."

I meant:
"Although the documentation does not say that if the warning is given then
strict aliasing is actually done, ...".
which is why I filed this as an "enhancement" bug. 
I hope this case is not ambiguous, as the documentation may claim it to be.


-- 


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-02-28  1:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-28  1:09 [Bug c/26492] New: -Wstrict-aliasing=2 warns about explicitly allowed cast to pointer to union bartoldeman at users dot sourceforge dot net
2006-02-28  1:10 ` [Bug c/26492] " pinskia at gcc dot gnu dot org
2006-02-28  1:29 ` bartoldeman at users dot sourceforge dot net

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).