Skip to content

Commit 3a4185c

Browse files
committed
Disable ASan in coroutine functions; it interferes with splitting.
I filed rdar://43673059 to track re-enabling it.
1 parent 872463d commit 3a4185c

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,8 +1243,12 @@ IRGenSILFunction::IRGenSILFunction(IRGenModule &IGM,
12431243
// Apply sanitizer attributes to the function.
12441244
// TODO: Check if the function is supposed to be excluded from ASan either by
12451245
// being in the external file or via annotations.
1246-
if (IGM.IRGen.Opts.Sanitizers & SanitizerKind::Address)
1247-
CurFn->addFnAttr(llvm::Attribute::SanitizeAddress);
1246+
if (IGM.IRGen.Opts.Sanitizers & SanitizerKind::Address) {
1247+
// Disable ASan in coroutines; stack poisoning is not going to do
1248+
// reasonable things to the structural invariants.
1249+
if (!f->getLoweredFunctionType()->isCoroutine())
1250+
CurFn->addFnAttr(llvm::Attribute::SanitizeAddress);
1251+
}
12481252
if (IGM.IRGen.Opts.Sanitizers & SanitizerKind::Thread) {
12491253
auto declContext = f->getDeclContext();
12501254
if (declContext && isa<DestructorDecl>(declContext))

test/IRGen/asan-attributes.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
// This test verifies that we add the function attributes used by ASan.
22

3-
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-ir -sanitize=address %s | %FileCheck %s -check-prefix=ASAN
3+
// RUN: %target-swift-frontend -emit-ir -disable-llvm-optzns -sanitize=address %s | %FileCheck %s -check-prefix=ASAN
44

5-
func test() {
5+
// ASAN: define {{.*}} @"$S4main4testyyF"() [[DEFAULT_ATTRS:#[0-9]+]]
6+
public func test() {
67
}
78

8-
// ASAN: Function Attrs: sanitize_address
9+
// ASAN: define {{.*}} @"$S4main1xSivr"({{.*}}) [[COROUTINE_ATTRS:#[0-9]+]]
10+
public var x: Int {
11+
_read {
12+
yield 0
13+
}
14+
}
15+
16+
// ASAN: attributes [[DEFAULT_ATTRS]] =
17+
// ASAN-SAME: sanitize_address
18+
// ASAN-SAME: }
19+
20+
// ASAN: attributes [[COROUTINE_ATTRS]] =
21+
// ASAN-NOT: sanitize_address
22+
// ASAN-SAME: }

0 commit comments

Comments
 (0)