Index: compiler-rt/test/ubsan/TestCases/Misc/unreachable_asan-compatibility.c =================================================================== --- compiler-rt/test/ubsan/TestCases/Misc/unreachable_asan-compatibility.c +++ compiler-rt/test/ubsan/TestCases/Misc/unreachable_asan-compatibility.c @@ -11,6 +11,5 @@ // CHECK-LABEL: define void @foo() // CHECK: call void @__asan_handle_no_return // CHECK-NEXT: call void @bar -// CHECK-NEXT: call void @__asan_handle_no_return // CHECK-NEXT: call void @__ubsan_handle_builtin_unreachable // CHECK-NEXT: unreachable Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -2568,7 +2568,10 @@ if (CS) { // A call inside BB. TempsToInstrument.clear(); - if (CS.doesNotReturn() || CS.hasFnAttr(Attribute::ExpectNoReturn)) + bool NoReturn = + CS.doesNotReturn() || CS.hasFnAttr(Attribute::ExpectNoReturn); + bool Instrument = !CS->getMetadata("nosanitize"); + if (NoReturn && Instrument) NoReturnCalls.push_back(CS.getInstruction()); } if (CallInst *CI = dyn_cast(&Inst)) @@ -2606,7 +2609,7 @@ FunctionStackPoisoner FSP(F, *this); bool ChangedStack = FSP.runOnFunction(); - // We must unpoison the stack before every NoReturn call (throw, _exit, etc). + // We must unpoison the stack before most NoReturn call (throw, _exit, etc). // See e.g. https://github.com/google/sanitizers/issues/37 for (auto CI : NoReturnCalls) { IRBuilder<> IRB(CI); Index: llvm/test/Instrumentation/AddressSanitizer/instrument-no-return.ll =================================================================== --- llvm/test/Instrumentation/AddressSanitizer/instrument-no-return.ll +++ llvm/test/Instrumentation/AddressSanitizer/instrument-no-return.ll @@ -8,7 +8,7 @@ declare void @NormalFunc() declare void @NoReturnFunc() noreturn -; Instrument calls to noreturn functions (regardless of callsite) +; Instrument calls to noreturn functions (regardless of call site) define i32 @Call1() sanitize_address { call void @NoReturnFunc() unreachable @@ -35,6 +35,15 @@ ; CHECK: call void @__asan_handle_no_return ; CHECK-NEXT: call void @NormalFunc +; Never instrument !nosanitize call sites +define i32 @Call4() sanitize_address { + call void @NoReturnFunc() noreturn, !nosanitize !{} + ret i32 0 +} +; CHECK-LABEL: @Call4 +; CHECK-NOT: call void @__asan_handle_no_return +; CHECK: call void @NoReturnFunc + declare i32 @__gxx_personality_v0(...) define i64 @Invoke1(i8** %esc) sanitize_address personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {