Home | History | Annotate | Download | only in AddressSanitizer
      1 ; Test handling of llvm.lifetime intrinsics with C++ exceptions.
      2 ; RUN: opt < %s -asan -asan-module -asan-use-after-scope -asan-use-after-return=0 -S | FileCheck %s
      3 
      4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
      5 target triple = "x86_64-unknown-linux-gnu"
      6 
      7 %struct.ABC = type { i32 }
      8 
      9 $_ZN3ABCD2Ev = comdat any
     10 $_ZTS3ABC = comdat any
     11 $_ZTI3ABC = comdat any
     12 
     13 @_ZTVN10__cxxabiv117__class_type_infoE = external global i8*
     14 @_ZTS3ABC = linkonce_odr constant [5 x i8] c"3ABC\00", comdat
     15 @_ZTI3ABC = linkonce_odr constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @_ZTS3ABC, i32 0, i32 0) }, comdat
     16 
     17 define void @Throw() sanitize_address personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
     18 ; CHECK-LABEL: define void @Throw()
     19 entry:
     20   %x = alloca %struct.ABC, align 4
     21   %0 = bitcast %struct.ABC* %x to i8*
     22 
     23   ; Poison memory in prologue: F1F1F1F1F8F3F3F3
     24   ; CHECK: store i64 -868082052615769615, i64* %{{[0-9]+}}
     25 
     26   call void @llvm.lifetime.start.p0i8(i64 4, i8* %0)
     27   ; CHECK: store i8 4, i8* %{{[0-9]+}}
     28   ; CHECK-NEXT: @llvm.lifetime.start
     29 
     30   %exception = call i8* @__cxa_allocate_exception(i64 4)
     31   invoke void @__cxa_throw(i8* %exception, i8* bitcast ({ i8*, i8* }* @_ZTI3ABC to i8*), i8* bitcast (void (%struct.ABC*)* @_ZN3ABCD2Ev to i8*)) noreturn
     32           to label %unreachable unwind label %lpad
     33   ; CHECK: call void @__asan_handle_no_return
     34   ; CHECK-NEXT: @__cxa_throw
     35 
     36 lpad:
     37   %1 = landingpad { i8*, i32 }
     38           cleanup
     39   call void @_ZN3ABCD2Ev(%struct.ABC* nonnull %x)
     40   call void @llvm.lifetime.end.p0i8(i64 4, i8* %0)
     41   ; CHECK: store i8 -8, i8* %{{[0-9]+}}
     42   ; CHECK-NEXT: @llvm.lifetime.end
     43 
     44   resume { i8*, i32 } %1
     45   ; CHECK: store i64 0, i64* %{{[0-9]+}}
     46   ; CHECK-NEXT: resume
     47 
     48 unreachable:
     49   unreachable
     50 }
     51 
     52 %rtti.TypeDescriptor9 = type { i8**, i8*, [10 x i8] }
     53 %eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 }
     54 %eh.CatchableTypeArray.1 = type { i32, [1 x i32] }
     55 %eh.ThrowInfo = type { i32, i32, i32, i32 }
     56 
     57 $"\01??1ABC@@QEAA@XZ" = comdat any
     58 $"\01??_R0?AUABC@@@8" = comdat any
     59 $"_CT??_R0?AUABC@@@84" = comdat any
     60 $"_CTA1?AUABC@@" = comdat any
     61 $"_TI1?AUABC@@" = comdat any
     62 
     63 @"\01??_7type_info@@6B@" = external constant i8*
     64 @"\01??_R0?AUABC@@@8" = linkonce_odr global %rtti.TypeDescriptor9 { i8** @"\01??_7type_info@@6B@", i8* null, [10 x i8] c".?AUABC@@\00" }, comdat
     65 @__ImageBase = external constant i8
     66 @"_CT??_R0?AUABC@@@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor9* @"\01??_R0?AUABC@@@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 4, i32 0 }, section ".xdata", comdat
     67 @"_CTA1?AUABC@@" = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableType* @"_CT??_R0?AUABC@@@84" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32)] }, section ".xdata", comdat
     68 @"_TI1?AUABC@@" = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (void (%struct.ABC*)* @"\01??1ABC@@QEAA@XZ" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableTypeArray.1* @"_CTA1?AUABC@@" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section ".xdata", comdat
     69 
     70 define void @ThrowWin() sanitize_address personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
     71 ; CHECK-LABEL: define void @ThrowWin()
     72 entry:
     73   %x = alloca %struct.ABC, align 4
     74   %tmp = alloca %struct.ABC, align 4
     75   %0 = bitcast %struct.ABC* %x to i8*
     76 
     77   ; Poison memory in prologue: F1F1F1F1F8F304F2
     78   ; CHECK: store i64 -935355671561244175, i64* %{{[0-9]+}}
     79 
     80   call void @llvm.lifetime.start.p0i8(i64 4, i8* %0)
     81   ; CHECK: store i8 4, i8* %{{[0-9]+}}
     82   ; CHECK-NEXT: @llvm.lifetime.start
     83 
     84   %1 = bitcast %struct.ABC* %tmp to i8*
     85   invoke void @_CxxThrowException(i8* %1, %eh.ThrowInfo* nonnull @"_TI1?AUABC@@") noreturn
     86           to label %unreachable unwind label %ehcleanup
     87   ; CHECK: call void @__asan_handle_no_return
     88   ; CHECK-NEXT: @_CxxThrowException
     89 
     90 ehcleanup:
     91   %2 = cleanuppad within none []
     92   call void @"\01??1ABC@@QEAA@XZ"(%struct.ABC* nonnull %x) [ "funclet"(token %2) ]
     93   call void @llvm.lifetime.end.p0i8(i64 4, i8* %0)
     94   ; CHECK: store i8 -8, i8* %{{[0-9]+}}
     95   ; CHECK-NEXT: @llvm.lifetime.end
     96 
     97   cleanupret from %2 unwind to caller
     98   ; CHECK: store i64 0, i64* %{{[0-9]+}}
     99   ; CHECK-NEXT: cleanupret
    100 
    101 unreachable:
    102   unreachable
    103 }
    104 
    105 
    106 declare i32 @__gxx_personality_v0(...)
    107 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
    108 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
    109 declare void @__cxa_throw(i8*, i8*, i8*) local_unnamed_addr
    110 declare i8* @__cxa_allocate_exception(i64) local_unnamed_addr
    111 declare void @_ZN3ABCD2Ev(%struct.ABC* %this) unnamed_addr
    112 declare void @"\01??1ABC@@QEAA@XZ"(%struct.ABC* %this)
    113 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
    114 declare i32 @__CxxFrameHandler3(...)
    115