aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2021-08-13 14:17:41 +0200
committerAlexander Potapenko <glider@google.com>2021-08-20 14:01:06 +0200
commitb0391dfc737ede147e128fe877045f61fc5e4905 (patch)
tree092fb66546f815568c2cab1fecd599ff84956470 /clang/lib/CodeGen/CodeGenFunction.cpp
parentb2aa470faeb7aaedfa63cb192a710fbe086f15c1 (diff)
downloadllvm-b0391dfc737ede147e128fe877045f61fc5e4905.zip
llvm-b0391dfc737ede147e128fe877045f61fc5e4905.tar.gz
llvm-b0391dfc737ede147e128fe877045f61fc5e4905.tar.bz2
[clang][Codegen] Introduce the disable_sanitizer_instrumentation attribute
The purpose of __attribute__((disable_sanitizer_instrumentation)) is to prevent all kinds of sanitizer instrumentation applied to a certain function, Objective-C method, or global variable. The no_sanitize(...) attribute drops instrumentation checks, but may still insert code preventing false positive reports. In some cases though (e.g. when building Linux kernel with -fsanitize=kernel-memory or -fsanitize=thread) the users may want to avoid any kind of instrumentation. Differential Revision: https://reviews.llvm.org/D108029
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index dca4204..e3a6631 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -381,6 +381,9 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
"__cyg_profile_func_exit");
}
+ if (ShouldSkipSanitizerInstrumentation())
+ CurFn->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
+
// Emit debug descriptor for function end.
if (CGDebugInfo *DI = getDebugInfo())
DI->EmitFunctionEnd(Builder, CurFn);
@@ -519,6 +522,12 @@ bool CodeGenFunction::ShouldInstrumentFunction() {
return true;
}
+bool CodeGenFunction::ShouldSkipSanitizerInstrumentation() {
+ if (!CurFuncDecl)
+ return false;
+ return CurFuncDecl->hasAttr<DisableSanitizerInstrumentationAttr>();
+}
+
/// ShouldXRayInstrument - Return true if the current function should be
/// instrumented with XRay nop sleds.
bool CodeGenFunction::ShouldXRayInstrumentFunction() const {