Bug 447253
Summary: | gcc with optimization higher than -O2 generates wrong code | ||||||
---|---|---|---|---|---|---|---|
Product: | Red Hat Enterprise Linux 5 | Reporter: | ritz <rkhadgar> | ||||
Component: | gcc | Assignee: | Jakub Jelinek <jakub> | ||||
Status: | CLOSED NOTABUG | QA Contact: | |||||
Severity: | low | Docs Contact: | |||||
Priority: | low | ||||||
Version: | 5.2 | CC: | tao | ||||
Target Milestone: | rc | ||||||
Target Release: | --- | ||||||
Hardware: | All | ||||||
OS: | Linux | ||||||
Whiteboard: | |||||||
Fixed In Version: | Doc Type: | Bug Fix | |||||
Doc Text: | Story Points: | --- | |||||
Clone Of: | Environment: | ||||||
Last Closed: | 2008-05-19 08:08:09 UTC | Type: | --- | ||||
Regression: | --- | Mount Type: | --- | ||||
Documentation: | --- | CRM: | |||||
Verified Versions: | Category: | --- | |||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
Cloudforms Team: | --- | Target Upstream Version: | |||||
Embargoed: | |||||||
Attachments: |
|
Description
ritz
2008-05-19 05:56:45 UTC
Created attachment 305902 [details]
Test case
Eh, this code is invalid even in ISO C90, so at least for 18 years. -Wstrict-aliasing=3 doesn't warn in this case because it would have too many false positives, many programs cast one type of pointer to another and dereference it that way, that in itself is not a bug. The problem is if you are accessing some object using a wrong type. Say int i; void bar (int **p) { *(int *) p |= 1; } void foo (void) { bar ((int **) (void *) &i); } is fine, i is accessed through a compatible type. The documentation for -Wstrict-aliasing clearly states that the warning catches only the most common problems and still it has many false positives too. ISO C doesn't require diagnostics in this case and in many cases aliasing violations are even theoretically impossible to detect, without whole program analysis. If you have legacy code which doesn't honor the aliasing requirements, you can always compile with -fno-strict-aliasing. That is of course a performance penalty, but you can that way postpone legacy code analysis. |