r352069 - Revert "[Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls"

Julian Lettner via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 24 10:04:21 PST 2019


Author: yln
Date: Thu Jan 24 10:04:21 2019
New Revision: 352069

URL: http://llvm.org/viewvc/llvm-project?rev=352069&view=rev
Log:
Revert "[Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls"

This reverts commit cea84ab93aeb079a358ab1c8aeba6d9140ef8b47.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=352069&r1=352068&r2=352069&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Jan 24 10:04:21 2019
@@ -4401,16 +4401,12 @@ RValue CodeGenFunction::EmitCall(const C
     if (UnusedReturnSizePtr)
       PopCleanupBlock();
 
-    // Replace the noreturn attribute to better diagnose unreachable UB.
+    // Strip away the noreturn attribute to better diagnose unreachable UB.
     if (SanOpts.has(SanitizerKind::Unreachable)) {
-      // Also remove from function since CS.hasFnAttr(..) also checks attributes
-      // of the called function.
       if (auto *F = CS.getCalledFunction())
         F->removeFnAttr(llvm::Attribute::NoReturn);
       CS.removeAttribute(llvm::AttributeList::FunctionIndex,
                          llvm::Attribute::NoReturn);
-      CS.addAttribute(llvm::AttributeList::FunctionIndex,
-                      llvm::Attribute::ExpectNoReturn);
     }
 
     EmitUnreachable(Loc);

Modified: cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp?rev=352069&r1=352068&r2=352069&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp Thu Jan 24 10:04:21 2019
@@ -2,35 +2,38 @@
 
 extern void __attribute__((noreturn)) abort();
 
-// CHECK-LABEL: define void @_Z14calls_noreturnv()
+// CHECK-LABEL: define void @_Z14calls_noreturnv
 void calls_noreturn() {
-  // CHECK: call void @_Z5abortv() [[CALL_SITE_ATTR:#[0-9]+]]
   abort();
 
+  // Check that there are no attributes on the call site.
+  // CHECK-NOT: call void @_Z5abortv{{.*}}#
+
   // CHECK: __ubsan_handle_builtin_unreachable
   // CHECK: unreachable
 }
 
 struct A {
-  // CHECK: declare void @_Z5abortv() [[EXTERN_FN_ATTR:#[0-9]+]]
+  // CHECK: declare void @_Z5abortv{{.*}} [[ABORT_ATTR:#[0-9]+]]
 
   // CHECK-LABEL: define linkonce_odr void @_ZN1A5call1Ev
   void call1() {
-    // CHECK: call void @_ZN1A16does_not_return2Ev({{.*}}) [[CALL_SITE_ATTR]]
+    // CHECK-NOT: call void @_ZN1A16does_not_return2Ev{{.*}}#
     does_not_return2();
 
     // CHECK: __ubsan_handle_builtin_unreachable
     // CHECK: unreachable
   }
 
-  // Test static members. Checks are below after `struct A` scope ends.
+  // Test static members.
   static void __attribute__((noreturn)) does_not_return1() {
+    // CHECK-NOT: call void @_Z5abortv{{.*}}#
     abort();
   }
 
   // CHECK-LABEL: define linkonce_odr void @_ZN1A5call2Ev
   void call2() {
-    // CHECK: call void @_ZN1A16does_not_return1Ev() [[CALL_SITE_ATTR]]
+    // CHECK-NOT: call void @_ZN1A16does_not_return1Ev{{.*}}#
     does_not_return1();
 
     // CHECK: __ubsan_handle_builtin_unreachable
@@ -43,18 +46,18 @@ struct A {
   // CHECK-LABEL: define linkonce_odr void @_ZN1A5call3Ev
   void call3() {
     MemFn MF = &A::does_not_return2;
-    // CHECK: call void %{{[0-9]+\(.*}}) [[CALL_SITE_ATTR]]
     (this->*MF)();
 
+    // CHECK-NOT: call void %{{.*}}#
     // CHECK: __ubsan_handle_builtin_unreachable
     // CHECK: unreachable
   }
 
   // Test regular members.
   // CHECK-LABEL: define linkonce_odr void @_ZN1A16does_not_return2Ev({{.*}})
-  // CHECK-SAME: [[USER_FN_ATTR:#[0-9]+]]
+  // CHECK-SAME: [[DOES_NOT_RETURN_ATTR:#[0-9]+]]
   void __attribute__((noreturn)) does_not_return2() {
-    // CHECK: call void @_Z5abortv() [[CALL_SITE_ATTR]]
+    // CHECK-NOT: call void @_Z5abortv(){{.*}}#
     abort();
 
     // CHECK: call void @__ubsan_handle_builtin_unreachable
@@ -65,9 +68,7 @@ struct A {
   }
 };
 
-// CHECK-LABEL: define linkonce_odr void @_ZN1A16does_not_return1Ev()
-// CHECK-SAME: [[USER_FN_ATTR]]
-// CHECK: call void @_Z5abortv() [[CALL_SITE_ATTR]]
+// CHECK: define linkonce_odr void @_ZN1A16does_not_return1Ev() [[DOES_NOT_RETURN_ATTR]]
 
 void force_irgen() {
   A a;
@@ -76,9 +77,5 @@ void force_irgen() {
   a.call3();
 }
 
-// 1) 'noreturn' should be removed from functions and call sites
-// 2) 'expect_noreturn' added to call sites
-// CHECK-LABEL: attributes
-// CHECK: [[USER_FN_ATTR]] = { {{.*[^noreturn].*}} }
-// CHECK: [[EXTERN_FN_ATTR]] = { {{.*[^noreturn].*}} }
-// CHECK: [[CALL_SITE_ATTR]] = { expect_noreturn }
+// CHECK-NOT: [[ABORT_ATTR]] = {{[^}]+}}noreturn
+// CHECK-NOT: [[DOES_NOT_RETURN_ATTR]] = {{[^}]+}}noreturn




More information about the cfe-commits mailing list