<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - TBAA failed to alias union in a very obvious code"
href="https://llvm.org/bugs/show_bug.cgi?id=26118">26118</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>TBAA failed to alias union in a very obvious code
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>yinma@codeaurora.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>###---t.c----###
typedef union
{
unsigned int b32[2];
long long int b64;
} Vector;
int bar();
unsigned int h264p_get_bits(Vector *c)
{
unsigned int v = c->b64;
c->b32[0]= bar();
return v;
}
clang t.c -S -O1 -mllvm -print-after-all
*** IR Dump After Module Verifier ***
; Function Attrs: nounwind
define i32 @h264p_get_bits(%union.Vector* %c) #0 {
entry:
%c.addr = alloca %union.Vector*, align 4
%v = alloca i32, align 4
store %union.Vector* %c, %union.Vector** %c.addr, align 4, !tbaa !3
%0 = bitcast i32* %v to i8*
call void @llvm.lifetime.start(i64 4, i8* %0) #3
%1 = load %union.Vector*, %union.Vector** %c.addr, align 4, !tbaa !3
%b64 = bitcast %union.Vector* %1 to i64*
%2 = load i64, i64* %b64, align 8, !tbaa !7 <<<----- !7
%conv = trunc i64 %2 to i32
store i32 %conv, i32* %v, align 4, !tbaa !9
%call = call i32 bitcast (i32 (...)* @bar to i32 ()*)()
%3 = load %union.Vector*, %union.Vector** %c.addr, align 4, !tbaa !3
%b32 = bitcast %union.Vector* %3 to [2 x i32]*
%arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %b32, i32 0, i32 0
store i32 %call, i32* %arrayidx, align 8, !tbaa !9 <<<----- !9, not !7
%4 = load i32, i32* %v, align 4, !tbaa !9
%5 = bitcast i32* %v to i8*
call void @llvm.lifetime.end(i64 4, i8* %5) #3
ret i32 %4
}
Although I understand
Strictly speaking, reading a member of a union different from the one written
to is undefined in ANSI/ISO C99 except in the special case of type-punning to a
char*, similar to the example below: Casting to char*. However, it is an
extremely common idiom and is well-supported by all major compilers. As a
practical matter, reading and writing to any member of a union, in any order,
is acceptable practice.
And for type based AA, it should not strict aligned. However, for union, this
is very general usage, tbaa should output they are aliased, right.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>