Summary: | Bogus location given for warning, no warning at real location: dereferencing pointer ‘<anonymous>’ does break strict-aliasing rules | ||
---|---|---|---|
Product: | gcc | Reporter: | Török Edwin <edwin+bugs> |
Component: | middle-end | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | NEW --- | ||
Severity: | normal | CC: | gcc-bugs, manu, musiphil, rguenth |
Priority: | P3 | Keywords: | diagnostic |
Version: | 4.4.0 | ||
Target Milestone: | --- | ||
Host: | x86_64-linux-gnu | Target: | x86_64-linux-gnu |
Build: | x86_64-linux-gnu | Known to work: | |
Known to fail: | Last reconfirmed: | 2009-04-25 10:41:02 | |
Attachments: | testcase |
Description
Török Edwin
2009-04-25 09:37:22 UTC
Created attachment 17690 [details]
testcase
Thanks for the short testcase. I'll try to improve the location information. The compiler at the point of the warning sees D.1756_5 = (struct APSInt &) &Val.Data; AdditionalOffset.D.1723 = D.1756_5->D.1723; and complains about dereferencing D.1756_5 which is of type APSInt * but the object that is accessed is of type void *. So yes, this is an alias violation. What you probably want to do is sth like class APValue { private: char Data[sizeof(APSInt)]; public: APSInt &getInt() { return *(new (Data) APSInt); } }; to be conforming. The location is also "correct" in the sense that we try to warn with the location of the _dereference_. And that is indeed in APSInt& APSInt::operator=(const APSInt&): (void) (((struct APSInt *) this)->D.1723 = *(const struct APInt &) &((const struct APSInt *) RHS)->D.1723) the pointer initialization point is that of the call - we dereference a type-pun of the this pointer in Val.getInt(). I have some improvements though - trying to get rid of '<anonymous>' most of the time. The improved version would look like t.ii: In function 'bool foo()': t.ii:8: warning: dereferencing type-punned pointer '& Val.APValue::Data' does break strict-aliasing rules t.ii:26: note: initialized from here I don't know if that is more useful though - the &Val.APValue::Data expression does not appear literally in the program either. Note that getInt is completely inlined and there is no location involving that function available anymore :/ The difficulties of C++ and late diagnostics ... (In reply to comment #3) > > Note that getInt is completely inlined and there is no location involving > that function available anymore :/ The difficulties of C++ and late > diagnostics ... > I wonder what Clang+LLVM does here. Their diagnostics are (in general) far superior and we are the ones that should start following their lead. (In reply to comment #3) > > Note that getInt is completely inlined and there is no location involving > that function available anymore :/ The difficulties of C++ and late > diagnostics ... Don't we keep abstract_origin somewhere? I have seen in the middle-end that sometimes we test whether something is an inline variable or not. |