]> granicus.if.org Git - clang/commitdiff
[ASan] Do not instrument other runtime functions with `__asan_handle_no_return`
authorJulian Lettner <jlettner@apple.com>
Sat, 2 Feb 2019 02:05:16 +0000 (02:05 +0000)
committerJulian Lettner <jlettner@apple.com>
Sat, 2 Feb 2019 02:05:16 +0000 (02:05 +0000)
Summary:
Currently, ASan inserts a call to `__asan_handle_no_return` before every
`noreturn` function call/invoke. This is unnecessary for calls to other
runtime funtions. This patch changes ASan to skip instrumentation for
functions calls marked with `!nosanitize` metadata.

Reviewers: TODO

Differential Revision: https://reviews.llvm.org/D57489

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352948 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
test/CodeGen/ubsan-asan-noreturn.c

index 4051cfb820c35aff2a847d847c5452d1998d75af..730dac37dd2d513754b9fd0cff19c607bdb58eac 100644 (file)
@@ -4394,8 +4394,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
 
     // Strip away the noreturn attribute to better diagnose unreachable UB.
     if (SanOpts.has(SanitizerKind::Unreachable)) {
-      // Also remove from function since CI->hasFnAttr(..) also checks attributes
-      // of the called function.
+      // Also remove from function since CallBase::hasFnAttr additionally checks
+      // attributes of the called function.
       if (auto *F = CI->getCalledFunction())
         F->removeFnAttr(llvm::Attribute::NoReturn);
       CI->removeAttribute(llvm::AttributeList::FunctionIndex,
index cd7b8425796f09c075875b53233fa0d93d6f819a..6dc0546d484e692f1ef30e03a6dbc2abcac631a1 100644 (file)
@@ -9,8 +9,7 @@ void calls_noreturn() {
   my_longjmp();
   // CHECK:      @__asan_handle_no_return{{.*}} !nosanitize
   // CHECK-NEXT: @my_longjmp(){{[^#]*}}
-  // CHECK:      @__asan_handle_no_return()
-  // CHECK-NEXT: @__ubsan_handle_builtin_unreachable{{.*}} !nosanitize
+  // CHECK:      @__ubsan_handle_builtin_unreachable{{.*}} !nosanitize
   // CHECK-NEXT: unreachable
 }