https://llvm.org/bugs/show_bug.cgi?id=26118
Bug ID: 26118 Summary: TBAA failed to alias union in a very obvious code Product: clang Version: unspecified Hardware: PC OS: Windows NT Status: NEW Severity: normal Priority: P Component: -New Bugs Assignee: unassignedclangb...@nondot.org Reporter: yi...@codeaurora.org CC: llvm-bugs@lists.llvm.org Classification: Unclassified ###---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. -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs