[llvm-bugs] [Bug 26603] New: Wrong optimization with aliasing
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Feb 13 14:29:11 PST 2016
https://llvm.org/bugs/show_bug.cgi?id=26603
Bug ID: 26603
Summary: Wrong optimization with aliasing
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: cherepan at mccme.ru
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
The program:
#include <stdlib.h>
#include <stdio.h>
int main()
{
void *volatile p = malloc(10);
int *pi = p;
double *pd = p;
*pi = 1;
printf("*pi = %d\n", *pi);
int a = *pi;
*pd = 0;
*pi = a;
printf("p = %p\n", p);
printf("*pi = %d\n", *pi);
}
compiled with `clang -std=c11 -O2` prints this:
*pi = 1
p = 0x929010
*pi = 0
The last value is wrong, it should be 1.
Tested with clang 3.0, 3.5 and 3.9.0 (trunk 260831) -- all affected.
AFAICT the code above doesn't violate any aliasing rules. All reads are with
the right type. And writes to allocated objects are free to change the
effective type according to C11, 6.5p6: "If a value is stored into an object
having no declared type through an lvalue having a type that is not a character
type, then the type of the lvalue becomes the effective type of the object for
that access and for subsequent accesses that do not modify the stored value."
Similar gcc bug -- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69776 .
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160213/807d35f4/attachment.html>
More information about the llvm-bugs
mailing list