Skip to content

Commit a22c72c

Browse files
author
Eric Liu
committed
Revert "[Sanitizers] UBSan unreachable incompatible with ASan in the presence of noreturn calls"
This reverts commit r352690. This causes clang to crash. Sent reproducer to the author in the orginal commit. llvm-svn: 352755
1 parent 0ca744c commit a22c72c

File tree

4 files changed

+21
-57
lines changed

4 files changed

+21
-57
lines changed

clang/lib/CodeGen/CGCall.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -4398,23 +4398,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
43984398

43994399
// Strip away the noreturn attribute to better diagnose unreachable UB.
44004400
if (SanOpts.has(SanitizerKind::Unreachable)) {
4401-
// Also remove from function since CI->hasFnAttr(..) also checks attributes
4402-
// of the called function.
44034401
if (auto *F = CI->getCalledFunction())
44044402
F->removeFnAttr(llvm::Attribute::NoReturn);
44054403
CI->removeAttribute(llvm::AttributeList::FunctionIndex,
44064404
llvm::Attribute::NoReturn);
4407-
4408-
// Avoid incompatibility with ASan which relies on the `noreturn`
4409-
// attribute to insert handler calls.
4410-
if (SanOpts.has(SanitizerKind::Address)) {
4411-
SanitizerScope SanScope(this);
4412-
Builder.SetInsertPoint(CI);
4413-
auto *FnType = llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
4414-
auto *Fn = CGM.CreateRuntimeFunction(FnType, "__asan_handle_no_return");
4415-
EmitNounwindRuntimeCall(Fn);
4416-
Builder.SetInsertPoint(CI->getParent());
4417-
}
44184405
}
44194406

44204407
EmitUnreachable(Loc);

clang/lib/CodeGen/CodeGenFunction.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4084,8 +4084,8 @@ class CodeGenFunction : public CodeGenTypeCache {
40844084
/// passing to a runtime sanitizer handler.
40854085
llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc);
40864086

4087-
/// Create a basic block that will either trap or call a handler function in
4088-
/// the UBSan runtime with the provided arguments, and create a conditional
4087+
/// Create a basic block that will call a handler function in a
4088+
/// sanitizer runtime with the provided arguments, and create a conditional
40894089
/// branch to it.
40904090
void EmitCheck(ArrayRef<std::pair<llvm::Value *, SanitizerMask>> Checked,
40914091
SanitizerHandler Check, ArrayRef<llvm::Constant *> StaticArgs,

clang/test/CodeGen/ubsan-asan-noreturn.c

-21
This file was deleted.
+19-21
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,63 @@
11
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=unreachable | FileCheck %s
22

3-
void abort() __attribute__((noreturn));
3+
extern void __attribute__((noreturn)) abort();
44

5-
// CHECK-LABEL: define void @_Z14calls_noreturnv()
5+
// CHECK-LABEL: define void @_Z14calls_noreturnv
66
void calls_noreturn() {
7-
// Check absence ([^#]*) of call site attributes (including noreturn)
8-
// CHECK: call void @_Z5abortv(){{[^#]*}}
97
abort();
108

9+
// Check that there are no attributes on the call site.
10+
// CHECK-NOT: call void @_Z5abortv{{.*}}#
11+
1112
// CHECK: __ubsan_handle_builtin_unreachable
1213
// CHECK: unreachable
1314
}
1415

1516
struct A {
16-
// CHECK: declare void @_Z5abortv() [[EXTERN_FN_ATTR:#[0-9]+]]
17+
// CHECK: declare void @_Z5abortv{{.*}} [[ABORT_ATTR:#[0-9]+]]
1718

1819
// CHECK-LABEL: define linkonce_odr void @_ZN1A5call1Ev
1920
void call1() {
20-
// CHECK: call void @_ZN1A16does_not_return2Ev({{.*}}){{[^#]*}}
21+
// CHECK-NOT: call void @_ZN1A16does_not_return2Ev{{.*}}#
2122
does_not_return2();
2223

2324
// CHECK: __ubsan_handle_builtin_unreachable
2425
// CHECK: unreachable
2526
}
2627

27-
// Test static members. Checks are below after `struct A` scope ends.
28-
static void does_not_return1() __attribute__((noreturn)) {
28+
// Test static members.
29+
static void __attribute__((noreturn)) does_not_return1() {
30+
// CHECK-NOT: call void @_Z5abortv{{.*}}#
2931
abort();
3032
}
3133

3234
// CHECK-LABEL: define linkonce_odr void @_ZN1A5call2Ev
3335
void call2() {
34-
// CHECK: call void @_ZN1A16does_not_return1Ev(){{[^#]*}}
36+
// CHECK-NOT: call void @_ZN1A16does_not_return1Ev{{.*}}#
3537
does_not_return1();
3638

3739
// CHECK: __ubsan_handle_builtin_unreachable
3840
// CHECK: unreachable
3941
}
4042

4143
// Test calls through pointers to non-static member functions.
42-
typedef void (A::*MemFn)() __attribute__((noreturn));
44+
typedef void __attribute__((noreturn)) (A::*MemFn)();
4345

4446
// CHECK-LABEL: define linkonce_odr void @_ZN1A5call3Ev
4547
void call3() {
4648
MemFn MF = &A::does_not_return2;
47-
// CHECK: call void %{{[0-9]+\(.*}}){{[^#]*}}
4849
(this->*MF)();
4950

51+
// CHECK-NOT: call void %{{.*}}#
5052
// CHECK: __ubsan_handle_builtin_unreachable
5153
// CHECK: unreachable
5254
}
5355

5456
// Test regular members.
5557
// CHECK-LABEL: define linkonce_odr void @_ZN1A16does_not_return2Ev({{.*}})
56-
// CHECK-SAME: [[USER_FN_ATTR:#[0-9]+]]
57-
void does_not_return2() __attribute__((noreturn)) {
58-
// CHECK: call void @_Z5abortv(){{[^#]*}}
58+
// CHECK-SAME: [[DOES_NOT_RETURN_ATTR:#[0-9]+]]
59+
void __attribute__((noreturn)) does_not_return2() {
60+
// CHECK-NOT: call void @_Z5abortv(){{.*}}#
5961
abort();
6062

6163
// CHECK: call void @__ubsan_handle_builtin_unreachable
@@ -66,9 +68,7 @@ struct A {
6668
}
6769
};
6870

69-
// CHECK-LABEL: define linkonce_odr void @_ZN1A16does_not_return1Ev()
70-
// CHECK-SAME: [[USER_FN_ATTR]]
71-
// CHECK: call void @_Z5abortv(){{[^#]*}}
71+
// CHECK: define linkonce_odr void @_ZN1A16does_not_return1Ev() [[DOES_NOT_RETURN_ATTR]]
7272

7373
void force_irgen() {
7474
A a;
@@ -77,7 +77,5 @@ void force_irgen() {
7777
a.call3();
7878
}
7979

80-
// `noreturn` should be removed from functions and call sites
81-
// CHECK-LABEL: attributes
82-
// CHECK-NOT: [[USER_FN_ATTR]] = { {{.*noreturn.*}} }
83-
// CHECK-NOT: [[EXTERN_FN_ATTR]] = { {{.*noreturn.*}} }
80+
// CHECK-NOT: [[ABORT_ATTR]] = {{[^}]+}}noreturn
81+
// CHECK-NOT: [[DOES_NOT_RETURN_ATTR]] = {{[^}]+}}noreturn

0 commit comments

Comments
 (0)