[asan] when checking the noreturn attribute on the call, also check it on the callee
authorKostya Serebryany <kcc@google.com>
Thu, 29 Nov 2012 08:57:20 +0000 (08:57 +0000)
committerKostya Serebryany <kcc@google.com>
Thu, 29 Nov 2012 08:57:20 +0000 (08:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168861 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/AddressSanitizer.cpp
test/Instrumentation/AddressSanitizer/instrument-no-return.ll

index 24dc0f267a349b92caf20c0443ebed9e850c1370..444add65c5bf8f592eb44002b576a7a0ad5ec508 100644 (file)
@@ -845,6 +845,14 @@ bool AddressSanitizer::maybeInsertAsanInitAtFunctionEntry(Function &F) {
   return false;
 }
 
+// Check both the call and the callee for doesNotReturn().
+static bool isNoReturnCall(CallInst *CI) {
+  if (CI->doesNotReturn()) return true;
+  Function *F = CI->getCalledFunction();
+  if (F && F->doesNotReturn()) return true;
+  return false;
+}
+
 bool AddressSanitizer::runOnFunction(Function &F) {
   if (BL->isIn(F)) return false;
   if (&F == AsanCtorFunction) return false;
@@ -885,7 +893,7 @@ bool AddressSanitizer::runOnFunction(Function &F) {
         if (CallInst *CI = dyn_cast<CallInst>(BI)) {
           // A call inside BB.
           TempsToInstrument.clear();
-          if (CI->doesNotReturn()) {
+          if (isNoReturnCall(CI)) {
             NoReturnCalls.push_back(CI);
           }
         }
index 80f1b1c74cd11373fbec4b9c9f19e1add34529ae..e8f62b54856e281b4621f3b483b332c416412cea 100644 (file)
@@ -7,11 +7,22 @@ target triple = "x86_64-unknown-linux-gnu"
 
 declare void @MyNoReturnFunc(i32) noreturn
 
-define i32 @_Z5ChildPv(i8* nocapture %arg) uwtable address_safety {
+define i32 @Call1(i8* nocapture %arg) uwtable address_safety {
 entry:
-  call void @MyNoReturnFunc(i32 1) noreturn
+  call void @MyNoReturnFunc(i32 1) noreturn  ; The call insn has noreturn attr.
+; CHECK:        @Call1
+; CHECK:        call void @__asan_handle_no_return
+; CHECK-NEXT:   call void @MyNoReturnFunc
+; CHECK-NEXT: unreachable
   unreachable
 }
 
+define i32 @Call2(i8* nocapture %arg) uwtable address_safety {
+entry:
+  call void @MyNoReturnFunc(i32 1)  ; No noreturn attribure on the call.
+; CHECK:        @Call2
 ; CHECK:        call void @__asan_handle_no_return
 ; CHECK-NEXT:   call void @MyNoReturnFunc
+; CHECK-NEXT: unreachable
+  unreachable
+}