llvm.org GIT mirror llvm / a1e328d
Revert "[Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls" This reverts commit cea84ab93aeb079a358ab1c8aeba6d9140ef8b47. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352069 91177308-0d34-0410-b5e6-96231b3b80d8 Julian Lettner 1 year, 9 months ago
15 changed file(s) with 25 addition(s) and 65 deletion(s). Raw diff Collapse all Expand all
14571457 This function attribute indicates that the function never returns
14581458 normally. This produces undefined behavior at runtime if the
14591459 function ever does dynamically return.
1460 ``expect_noreturn``
1461 This function attribute indicates that the function is unlikely to return
1462 normally, but that it still allowed to do so. This is useful in cases where
1463 ``noreturn`` is too strong a guarantee.
14641460 ``norecurse``
14651461 This function attribute indicates that the function does not call itself
14661462 either directly or indirectly down any possible call path. This produces
602602 ATTR_KIND_OPT_FOR_FUZZING = 57,
603603 ATTR_KIND_SHADOWCALLSTACK = 58,
604604 ATTR_KIND_SPECULATIVE_LOAD_HARDENING = 59,
605 ATTR_KIND_EXPECT_NO_RETURN = 60,
606605 };
607606
608607 enum ComdatSelectionKindCodes {
104104
105105 /// Mark the function as not returning.
106106 def NoReturn : EnumAttr<"noreturn">;
107
108 /// Mark the function as unlikely to return. This is useful in cases where
109 /// `noreturn` is too strong a guarantee.
110 def ExpectNoReturn : EnumAttr<"expect_noreturn">;
111107
112108 /// Disable Indirect Branch Tracking.
113109 def NoCfCheck : EnumAttr<"nocf_check">;
655655 KEYWORD(nonnull);
656656 KEYWORD(noredzone);
657657 KEYWORD(noreturn);
658 KEYWORD(expect_noreturn);
659658 KEYWORD(nocf_check);
660659 KEYWORD(nounwind);
661660 KEYWORD(optforfuzzing);
12471247 case lltok::kw_nonlazybind: B.addAttribute(Attribute::NonLazyBind); break;
12481248 case lltok::kw_noredzone: B.addAttribute(Attribute::NoRedZone); break;
12491249 case lltok::kw_noreturn: B.addAttribute(Attribute::NoReturn); break;
1250 case lltok::kw_expect_noreturn:
1251 B.addAttribute(Attribute::ExpectNoReturn); break;
12521250 case lltok::kw_nocf_check: B.addAttribute(Attribute::NoCfCheck); break;
12531251 case lltok::kw_norecurse: B.addAttribute(Attribute::NoRecurse); break;
12541252 case lltok::kw_nounwind: B.addAttribute(Attribute::NoUnwind); break;
16121610 case lltok::kw_nonlazybind:
16131611 case lltok::kw_noredzone:
16141612 case lltok::kw_noreturn:
1615 case lltok::kw_expect_noreturn:
16161613 case lltok::kw_nocf_check:
16171614 case lltok::kw_nounwind:
16181615 case lltok::kw_optforfuzzing:
17101707 case lltok::kw_nonlazybind:
17111708 case lltok::kw_noredzone:
17121709 case lltok::kw_noreturn:
1713 case lltok::kw_expect_noreturn:
17141710 case lltok::kw_nocf_check:
17151711 case lltok::kw_nounwind:
17161712 case lltok::kw_optforfuzzing:
199199 kw_nonnull,
200200 kw_noredzone,
201201 kw_noreturn,
202 kw_expect_noreturn,
203202 kw_nocf_check,
204203 kw_nounwind,
205204 kw_optforfuzzing,
11851185 case Attribute::NoCfCheck: return 1ULL << 57;
11861186 case Attribute::OptForFuzzing: return 1ULL << 58;
11871187 case Attribute::ShadowCallStack: return 1ULL << 59;
1188 case Attribute::SpeculativeLoadHardening: return 1ULL << 60;
1189 case Attribute::ExpectNoReturn: return 1ULL << 61;
1188 case Attribute::SpeculativeLoadHardening:
1189 return 1ULL << 60;
11901190 case Attribute::Dereferenceable:
11911191 llvm_unreachable("dereferenceable attribute not supported in raw format");
11921192 break;
13651365 return Attribute::NoRedZone;
13661366 case bitc::ATTR_KIND_NO_RETURN:
13671367 return Attribute::NoReturn;
1368 case bitc::ATTR_KIND_EXPECT_NO_RETURN:
1369 return Attribute::ExpectNoReturn;
13701368 case bitc::ATTR_KIND_NOCF_CHECK:
13711369 return Attribute::NoCfCheck;
13721370 case bitc::ATTR_KIND_NO_UNWIND:
653653 return bitc::ATTR_KIND_NO_RED_ZONE;
654654 case Attribute::NoReturn:
655655 return bitc::ATTR_KIND_NO_RETURN;
656 case Attribute::ExpectNoReturn:
657 return bitc::ATTR_KIND_EXPECT_NO_RETURN;
658656 case Attribute::NoCfCheck:
659657 return bitc::ATTR_KIND_NOCF_CHECK;
660658 case Attribute::NoUnwind:
297297 return "noredzone";
298298 if (hasAttribute(Attribute::NoReturn))
299299 return "noreturn";
300 if (hasAttribute(Attribute::ExpectNoReturn))
301 return "expect_noreturn";
302300 if (hasAttribute(Attribute::NoCfCheck))
303301 return "nocf_check";
304302 if (hasAttribute(Attribute::NoRecurse))
14761476 static bool isFuncOnlyAttr(Attribute::AttrKind Kind) {
14771477 switch (Kind) {
14781478 case Attribute::NoReturn:
1479 case Attribute::ExpectNoReturn:
14801479 case Attribute::NoCfCheck:
14811480 case Attribute::NoUnwind:
14821481 case Attribute::NoInline:
4040 .Case("nonlazybind", Attribute::NonLazyBind)
4141 .Case("noredzone", Attribute::NoRedZone)
4242 .Case("noreturn", Attribute::NoReturn)
43 .Case("expect_noreturn", Attribute::ExpectNoReturn)
4443 .Case("nocf_check", Attribute::NoCfCheck)
4544 .Case("norecurse", Attribute::NoRecurse)
4645 .Case("nounwind", Attribute::NoUnwind)
25672567 if (CS) {
25682568 // A call inside BB.
25692569 TempsToInstrument.clear();
2570 if (CS.doesNotReturn() || CS.hasFnAttr(Attribute::ExpectNoReturn))
2571 NoReturnCalls.push_back(CS.getInstruction());
2570 if (CS.doesNotReturn()) NoReturnCalls.push_back(CS.getInstruction());
25722571 }
25732572 if (CallInst *CI = dyn_cast(&Inst))
25742573 maybeMarkSanitizerLibraryCallNoBuiltin(CI, TLI);
778778 case Attribute::NoBuiltin:
779779 case Attribute::NoCapture:
780780 case Attribute::NoReturn:
781 case Attribute::ExpectNoReturn:
782781 case Attribute::None:
783782 case Attribute::NonNull:
784783 case Attribute::ReadNone:
203203 ; CHECK: define void @f34()
204204 {
205205 call void @nobuiltin() nobuiltin
206 ; CHECK: call void @nobuiltin() #37
206 ; CHECK: call void @nobuiltin() #36
207207 ret void;
208208 }
209209
346346
347347 ; CHECK: define void @f59() #35
348348 define void @f59() shadowcallstack
349 {
350 ret void
351 }
352
353 ; CHECK: define void @f60() #36
354 define void @f60() expect_noreturn
355349 {
356350 ret void
357351 }
392386 ; CHECK: attributes #33 = { speculatable }
393387 ; CHECK: attributes #34 = { sanitize_hwaddress }
394388 ; CHECK: attributes #35 = { shadowcallstack }
395 ; CHECK: attributes #36 = { expect_noreturn }
396 ; CHECK: attributes #37 = { nobuiltin }
389 ; CHECK: attributes #36 = { nobuiltin }
None ; RUN: opt < %s -asan -S | FileCheck %s
0 ; RUN: opt < %s -asan -asan-module -S | FileCheck %s
11 ; AddressSanitizer must insert __asan_handle_no_return
22 ; before every noreturn call or invoke.
33
44 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
55 target triple = "x86_64-unknown-linux-gnu"
66
7 declare void @NormalFunc()
8 declare void @NoReturnFunc() noreturn
7 declare void @MyNoReturnFunc(i32) noreturn
98
10 ; Instrument calls to noreturn functions (regardless of callsite)
11 define i32 @Call1() sanitize_address {
12 call void @NoReturnFunc()
9 define i32 @Call1(i8* nocapture %arg) uwtable sanitize_address {
10 entry:
11 call void @MyNoReturnFunc(i32 1) noreturn ; The call insn has noreturn attr.
12 ; CHECK: @Call1
13 ; CHECK: call void @__asan_handle_no_return
14 ; CHECK-NEXT: call void @MyNoReturnFunc
15 ; CHECK-NEXT: unreachable
1316 unreachable
1417 }
15 ; CHECK-LABEL: @Call1
18
19 define i32 @Call2(i8* nocapture %arg) uwtable sanitize_address {
20 entry:
21 call void @MyNoReturnFunc(i32 1) ; No noreturn attribure on the call.
22 ; CHECK: @Call2
1623 ; CHECK: call void @__asan_handle_no_return
17 ; CHECK-NEXT: call void @NoReturnFunc
18
19 ; Instrument noreturn call sites (regardless of function)
20 define i32 @Call2() sanitize_address {
21 call void @NormalFunc() noreturn
24 ; CHECK-NEXT: call void @MyNoReturnFunc
25 ; CHECK-NEXT: unreachable
2226 unreachable
2327 }
24 ; CHECK-LABEL: @Call2
25 ; CHECK: call void @__asan_handle_no_return
26 ; CHECK-NEXT: call void @NormalFunc
27
28 ; Also instrument expect_noreturn call sites
29 define i32 @Call3() sanitize_address {
30 call void @NormalFunc() expect_noreturn
31 ret i32 0
32 }
33 ; CHECK-LABEL: @Call3
34 ; CHECK: call void @__asan_handle_no_return
35 ; CHECK-NEXT: call void @NormalFunc
3628
3729 declare i32 @__gxx_personality_v0(...)
3830
39 define i64 @Invoke1(i8** %esc) sanitize_address personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
31 define i64 @Invoke1(i8** %esc) nounwind uwtable ssp sanitize_address personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
4032 entry:
41 invoke void @NoReturnFunc()
33 invoke void @MyNoReturnFunc(i32 1)
4234 to label %invoke.cont unwind label %lpad
4335
4436 invoke.cont:
4941 filter [0 x i8*] zeroinitializer
5042 ret i64 1
5143 }
52 ; CHECK-LABEL: @Invoke1
44 ; CHECK: @Invoke1
5345 ; CHECK: call void @__asan_handle_no_return
54 ; CHECK-NEXT: invoke void @NoReturnFunc
46 ; CHECK-NEXT: invoke void @MyNoReturnFunc
5547 ; CHECK: ret i64 0
5648 ; CHECK: ret i64 1