Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -676,6 +676,9 @@ /// \brief Collect all Ret instructions. void visitReturnInst(ReturnInst &RI) { RetVec.push_back(&RI); } + /// \brief Collect all Resume instructions. + void visitResumeInst(ResumeInst &RI) { RetVec.push_back(&RI); } + void unpoisonDynamicAllocasBeforeInst(Instruction *InstBefore, Value *SavedStack) { IRBuilder<> IRB(InstBefore); Index: test/Instrumentation/AddressSanitizer/lifetime-throw.ll =================================================================== --- /dev/null +++ test/Instrumentation/AddressSanitizer/lifetime-throw.ll @@ -0,0 +1,61 @@ +; Test hanlding of llvm.lifetime intrinsics. +; RUN: opt < %s -asan -asan-module -asan-use-after-scope -asan-use-after-return=0 -S | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%struct.ABC = type { i32 } + +$_ZN3ABCD2Ev = comdat any + +$_ZTS3ABC = comdat any + +$_ZTI3ABC = comdat any + +@_ZTVN10__cxxabiv117__class_type_infoE = external global i8* +@_ZTS3ABC = linkonce_odr constant [5 x i8] c"3ABC\00", comdat +@_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 + +define void @Throw() sanitize_address #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: + %x = alloca %struct.ABC, align 4 + %0 = bitcast %struct.ABC* %x to i8* + call void @llvm.lifetime.start(i64 4, i8* %0) #3 + ; CHECK: call void @__asan_unpoison_stack_memory + + %exception = call i8* @__cxa_allocate_exception(i64 4) #3 + %1 = getelementptr inbounds %struct.ABC, %struct.ABC* %x, i64 0, i32 0 + %2 = bitcast i8* %exception to i32* + %3 = load i32, i32* %1, align 4 + store i32 %3, i32* %2, align 4 + invoke void @__cxa_throw(i8* %exception, i8* bitcast ({ i8*, i8* }* @_ZTI3ABC to i8*), i8* bitcast (void (%struct.ABC*)* @_ZN3ABCD2Ev to i8*)) #4 + to label %unreachable unwind label %lpad + ; CHECK: call void @__asan_handle_no_return + +lpad: + %4 = landingpad { i8*, i32 } + cleanup + call void @_ZN3ABCD2Ev(%struct.ABC* nonnull %x) + call void @llvm.lifetime.end(i64 4, i8* %0) #3 + ; CHECK: call void @__asan_poison_stack_memory + + resume { i8*, i32 } %4 + ; CHECK: call void @__asan_unpoison_stack_memory + +unreachable: + unreachable +} + +declare i32 @__gxx_personality_v0(...) +declare void @llvm.lifetime.start(i64, i8* nocapture) #1 +declare void @llvm.lifetime.end(i64, i8* nocapture) #1 + +declare void @__cxa_throw(i8*, i8*, i8*) local_unnamed_addr +declare i8* @__cxa_allocate_exception(i64) local_unnamed_addr + +define linkonce_odr void @_ZN3ABCD2Ev(%struct.ABC* %this) unnamed_addr #2 comdat align 2{ +entry: + ret void +} + +attributes #4 = { noreturn }