Bug 20689 - strict aliasing with temporary variable never gives warnings
Summary: strict aliasing with temporary variable never gives warnings
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3.4
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 20709 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-03-30 09:59 UTC by varun
Modified: 2005-07-27 23:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description varun 2005-03-30 09:59:09 UTC
int i;
void *p=(void *)&i;
gives strict-aliasing warning
 but
int i,*o;
o=&i;
void *p= o;
doesn't give any warning
Comment 1 Falk Hueffner 2005-03-30 10:06:33 UTC
I don't understand what you mean. Please provide a *complete* test case,
with the command line you use and the output you get, and an explanation
of why you want a warning.
Comment 2 varun 2005-03-30 12:02:24 UTC
I mean that since in case where you are doing "void *p=(void *)&i" then
according to strict-aliasing rules we get " warning: dereferencing type-punned
pointer will break strict-aliasing rules" , but same thing if done using a
temporary variable then why strict-aliasing warning doesn't appear.. According
to my understanding of strict aliasing if some unqualified version of pointer is
pointing to the address space(in out case void pointer pointing to int address
space) then it is violating  strict aliasing rule. So in second case also void
pointer is pointing to the int address space then why strict aliasing rules are
not violated. If ther is some error in my understanding of strict aliasing then
please inform .
Comment 3 Falk Hueffner 2005-03-30 12:23:21 UTC
(In reply to comment #2)
> I mean that since in case where you are doing "void *p=(void *)&i" then
> according to strict-aliasing rules we get " warning: dereferencing type-punned
> pointer will break strict-aliasing rules" 

No, you don't. Please provide a *complete* test case, with the command line
you use and the output you get.

Comment 4 Andrew Pinski 2005-03-30 15:45:52 UTC
Also this is not done because void* cannot be dereferenced.
Comment 5 varun 2005-03-31 05:05:52 UTC
please ignore previous code and consider this piece as example ... problem is
same .the exact programs are following and command line was gcc -Wall -O2
test1.c test2.c....In this why test1.c not giving warning but test2.c giving
violation of strict-aliasing warning.
//test1.c
#include <stdio.h>
#include <stdlib.h>
int main()
{ int *i;
float **q;
int **r;
i =(int *)malloc(sizeof(int));
r=&i;
q=(float **)r;
return 0;
}
//test2.c
int main(){
int *i;
float **q; 
i =(int *)malloc(sizeof(int));
q= (float **) &i;
return 0;
}
Comment 6 varun 2005-03-31 10:18:49 UTC
please ignore previous code and consider this piece as example ... problem is
same .the exact programs are following and command line was gcc -Wall -O2
test1.c test2.c....In this why test1.c not giving warning but test2.c giving
violation of strict-aliasing warning.
//test1.c
#include <stdio.h>
#include <stdlib.h>
int main()
{ int *i;
float **q;
int **r;
i =(int *)malloc(sizeof(int));
r=&i;
q=(float **)r;
return 0;
}
//test2.c
int main(){
int *i;
float **q; 
i =(int *)malloc(sizeof(int));
q= (float **) &i;
return 0;
}

Comment 7 Andrew Pinski 2005-06-30 02:20:52 UTC
Even the example you gave in comment #6 is hard to get unless you have flow analysis in the front-end 
which I really doubt is even going to be.
Comment 8 Andrew Pinski 2005-07-02 00:58:01 UTC
*** Bug 20709 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2005-07-11 17:58:06 UTC
Closing as invalid based comment #7.
Comment 10 Andrew Pinski 2005-07-27 23:39:00 UTC
*** Bug 23106 has been marked as a duplicate of this bug. ***