1 ; RUN: opt < %s -tbaa -basicaa -aa-eval -evaluate-aa-metadata -print-no-aliases -print-may-aliases -disable-output 2>&1 | FileCheck %s 2 ; RUN: opt < %s -aa-pipeline=type-based-aa,basic-aa -passes=aa-eval -evaluate-aa-metadata -print-no-aliases -print-may-aliases -disable-output 2>&1 | FileCheck %s 3 4 ; Generated with "clang -cc1 -disable-llvm-optzns -O1 -emit-llvm" 5 ; #include <new> 6 ; struct Foo { long i; }; 7 ; struct Bar { void *p; }; 8 ; long foo(int n) { 9 ; Foo *f = new Foo; 10 ; f->i = 1; 11 ; for (int i=0; i<n; ++i) { 12 ; Bar *b = new (f) Bar; 13 ; b->p = 0; 14 ; f = new (f) Foo; 15 ; f->i = i; 16 ; } 17 ; return f->i; 18 ; } 19 20 ; Basic AA says MayAlias, TBAA says NoAlias 21 ; CHECK: MayAlias: i64* %i5, i8** %p 22 ; CHECK: NoAlias: store i64 %conv, i64* %i5, align 8, !tbaa !6 <-> store i8* null, i8** %p, align 8, !tbaa !9 23 24 %struct.Foo = type { i64 } 25 %struct.Bar = type { i8* } 26 27 define i64 @_Z3fooi(i32 %n) #0 { 28 entry: 29 %n.addr = alloca i32, align 4 30 %f = alloca %struct.Foo*, align 8 31 %i1 = alloca i32, align 4 32 %b = alloca %struct.Bar*, align 8 33 store i32 %n, i32* %n.addr, align 4, !tbaa !0 34 %call = call noalias i8* @_Znwm(i64 8) 35 %0 = bitcast i8* %call to %struct.Foo* 36 store %struct.Foo* %0, %struct.Foo** %f, align 8, !tbaa !4 37 %1 = load %struct.Foo*, %struct.Foo** %f, align 8, !tbaa !4 38 %i = getelementptr inbounds %struct.Foo, %struct.Foo* %1, i32 0, i32 0 39 store i64 1, i64* %i, align 8, !tbaa !6 40 store i32 0, i32* %i1, align 4, !tbaa !0 41 br label %for.cond 42 43 for.cond: 44 %2 = load i32, i32* %i1, align 4, !tbaa !0 45 %3 = load i32, i32* %n.addr, align 4, !tbaa !0 46 %cmp = icmp slt i32 %2, %3 47 br i1 %cmp, label %for.body, label %for.end 48 49 for.body: 50 %4 = load %struct.Foo*, %struct.Foo** %f, align 8, !tbaa !4 51 %5 = bitcast %struct.Foo* %4 to i8* 52 %new.isnull = icmp eq i8* %5, null 53 br i1 %new.isnull, label %new.cont, label %new.notnull 54 55 new.notnull: 56 %6 = bitcast i8* %5 to %struct.Bar* 57 br label %new.cont 58 59 new.cont: 60 %7 = phi %struct.Bar* [ %6, %new.notnull ], [ null, %for.body ] 61 store %struct.Bar* %7, %struct.Bar** %b, align 8, !tbaa !4 62 %8 = load %struct.Bar*, %struct.Bar** %b, align 8, !tbaa !4 63 %p = getelementptr inbounds %struct.Bar, %struct.Bar* %8, i32 0, i32 0 64 store i8* null, i8** %p, align 8, !tbaa !9 65 %9 = load %struct.Foo*, %struct.Foo** %f, align 8, !tbaa !4 66 %10 = bitcast %struct.Foo* %9 to i8* 67 %new.isnull2 = icmp eq i8* %10, null 68 br i1 %new.isnull2, label %new.cont4, label %new.notnull3 69 70 new.notnull3: 71 %11 = bitcast i8* %10 to %struct.Foo* 72 br label %new.cont4 73 74 new.cont4: 75 %12 = phi %struct.Foo* [ %11, %new.notnull3 ], [ null, %new.cont ] 76 store %struct.Foo* %12, %struct.Foo** %f, align 8, !tbaa !4 77 %13 = load i32, i32* %i1, align 4, !tbaa !0 78 %conv = sext i32 %13 to i64 79 %14 = load %struct.Foo*, %struct.Foo** %f, align 8, !tbaa !4 80 %i5 = getelementptr inbounds %struct.Foo, %struct.Foo* %14, i32 0, i32 0 81 store i64 %conv, i64* %i5, align 8, !tbaa !6 82 br label %for.inc 83 84 for.inc: 85 %15 = load i32, i32* %i1, align 4, !tbaa !0 86 %inc = add nsw i32 %15, 1 87 store i32 %inc, i32* %i1, align 4, !tbaa !0 88 br label %for.cond 89 90 for.end: 91 %16 = load %struct.Foo*, %struct.Foo** %f, align 8, !tbaa !4 92 %i6 = getelementptr inbounds %struct.Foo, %struct.Foo* %16, i32 0, i32 0 93 %17 = load i64, i64* %i6, align 8, !tbaa !6 94 ret i64 %17 95 } 96 97 declare noalias i8* @_Znwm(i64) 98 99 attributes #0 = { nounwind } 100 101 !0 = !{!1, !1, i64 0} 102 !1 = !{!"int", !2, i64 0} 103 !2 = !{!"omnipotent char", !3, i64 0} 104 !3 = !{!"Simple C/C++ TBAA"} 105 !4 = !{!5, !5, i64 0} 106 !5 = !{!"any pointer", !2, i64 0} 107 !6 = !{!7, !8, i64 0} 108 !7 = !{!"_ZTS3Foo", !8, i64 0} 109 !8 = !{!"long", !2, i64 0} 110 !9 = !{!10, !5, i64 0} 111 !10 = !{!"_ZTS3Bar", !5, i64 0} 112