[llvm-branch-commits] [llvm] 5b622d3 - tsan: don't instrument __attribute__((naked)) functions
Anton Bikineev via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Apr 9 04:35:11 PDT 2020
Author: Anton Bikineev
Date: 2020-04-09T13:32:58+02:00
New Revision: 5b622d37c194eb8e0046b465ff78f4daa92139cc
URL: https://github.com/llvm/llvm-project/commit/5b622d37c194eb8e0046b465ff78f4daa92139cc
DIFF: https://github.com/llvm/llvm-project/commit/5b622d37c194eb8e0046b465ff78f4daa92139cc.diff
LOG: tsan: don't instrument __attribute__((naked)) functions
Naked functions are required to not have compiler generated
prologues/epilogues, hence no instrumentation is needed for them.
Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=45400
Differential Revision: https://reviews.llvm.org/D77477
Added:
Modified:
llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
index 9b7edad3444b..e8882e4217aa 100644
--- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -441,6 +441,11 @@ bool ThreadSanitizer::sanitizeFunction(Function &F,
// the module constructor.
if (F.getName() == kTsanModuleCtorName)
return false;
+ // Naked functions can not have prologue/epilogue
+ // (__tsan_func_entry/__tsan_func_exit) generated, so don't instrument them at
+ // all.
+ if (F.hasFnAttribute(Attribute::Naked))
+ return false;
initialize(*F.getParent());
SmallVector<Instruction*, 8> AllLoadsAndStores;
SmallVector<Instruction*, 8> LocalLoadsAndStores;
diff --git a/llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll b/llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
index 953ab8ed8dc5..100717af13bf 100644
--- a/llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
+++ b/llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
@@ -78,5 +78,18 @@ define void @SwiftErrorCall(i8** swifterror) sanitize_thread {
call void @SwiftError(i8** %0)
ret void
}
+
+; CHECK-LABEL: @NakedTest(i32* %a)
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: %tmp1 = load i32, i32* %a, align 4
+; CHECK-NEXT: ret i32 %tmp1
+define i32 @NakedTest(i32* %a) naked sanitize_thread {
+ call void @foo()
+ %tmp1 = load i32, i32* %a, align 4
+ ret i32 %tmp1
+}
+
+declare void @foo() nounwind
+
; CHECK: define internal void @tsan.module_ctor()
; CHECK: call void @__tsan_init()
More information about the llvm-branch-commits
mailing list