TBAA: fix PR17620.

We can have a struct type with a single field and the field does not start
with 0. In that case, we should correctly update the offset.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193137 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Manman Ren 2013-10-22 01:40:25 +00:00
parent 8348b7d400
commit 11d78777d5
2 changed files with 56 additions and 1 deletions

View File

@ -231,8 +231,12 @@ namespace {
if (Node->getNumOperands() < 2)
return TBAAStructTypeNode();
// Special handling for a scalar type node.
// Fast path for a scalar type node and a struct type node with a single
// field.
if (Node->getNumOperands() <= 3) {
uint64_t Cur = Node->getNumOperands() == 2 ? 0 :
cast<ConstantInt>(Node->getOperand(2))->getZExtValue();
Offset -= Cur;
MDNode *P = dyn_cast_or_null<MDNode>(Node->getOperand(1));
if (!P)
return TBAAStructTypeNode();

View File

@ -0,0 +1,51 @@
; RUN: opt < %s -O2 -S | FileCheck %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
%"structA" = type { %"structB" }
%"structB" = type { i32*, %classT }
%classT = type { %classO, %classJ*, i8 }
%classO = type { i32 }
%classJ = type { i8 }
%"classA" = type { %"classB" }
%"classB" = type { i8 }
%"classC" = type { %"classD", %"structA" }
%"classD" = type { %"structA"* }
; Function Attrs: ssp uwtable
define %"structA"** @test(%"classA"* %this, i32** %p1) #0 align 2 {
entry:
; CHECK-LABEL: @test
; CHECK: load i32** %p1, align 8, !tbaa
; CHECK: load i32** inttoptr (i64 8 to i32**), align 8, !tbaa
; CHECK: call void @callee
%p1.addr = alloca i32**, align 8
store i32** %p1, i32*** %p1.addr, align 8, !tbaa !1
%0 = load i32*** %p1.addr, align 8
%1 = load i32** %0, align 8, !tbaa !4
%__value_ = getelementptr inbounds %"classC"* null, i32 0, i32 1
%__cc = getelementptr inbounds %"structA"* %__value_, i32 0, i32 0
%first = getelementptr inbounds %"structB"* %__cc, i32 0, i32 0
%2 = load i32** %first, align 8, !tbaa !6
call void @callee(i32* %1, i32* %2)
unreachable
}
declare void @callee(i32*, i32*) #1
attributes #0 = { ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.ident = !{!0}
!0 = metadata !{metadata !"clang version 3.4"}
!1 = metadata !{metadata !2, metadata !2, i64 0}
!2 = metadata !{metadata !"omnipotent char", metadata !3, i64 0}
!3 = metadata !{metadata !"Simple C/C++ TBAA"}
!4 = metadata !{metadata !5, metadata !5, i64 0}
!5 = metadata !{metadata !"any pointer", metadata !2, i64 0}
!6 = metadata !{metadata !7, metadata !5, i64 8}
!7 = metadata !{metadata !"_ZTSN12_GLOBAL__N_11RINS_1FIPi8TreeIterN1I1S1LENS_1KINS_1DIKS2_S3_EEEEE1GEPSD_EE", metadata !8, i64 8}
!8 = metadata !{metadata !"_ZTSN12_GLOBAL__N_11FIPi8TreeIterN1I1S1LENS_1KINS_1DIKS1_S2_EEEEE1GE", metadata !9, i64 0}
!9 = metadata !{metadata !"_ZTSN12_GLOBAL__N_11DIKPi8TreeIterEE", metadata !5, i64 0, metadata !10, i64 8}
!10 = metadata !{metadata !"_ZTS8TreeIter", metadata !5, i64 8, metadata !11, i64 16}
!11 = metadata !{metadata !"bool", metadata !2, i64 0}