[llvm] r224372 - [sanitizer] prevent function call merging for sanitizer-coverage callbacks
Kostya Serebryany
kcc at google.com
Tue Dec 16 13:24:15 PST 2014
Author: kcc
Date: Tue Dec 16 15:24:15 2014
New Revision: 224372
URL: http://llvm.org/viewvc/llvm-project?rev=224372&view=rev
Log:
[sanitizer] prevent function call merging for sanitizer-coverage callbacks
Modified:
llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
llvm/trunk/test/Instrumentation/SanitizerCoverage/coverage.ll
Modified: llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp?rev=224372&r1=224371&r2=224372&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp Tue Dec 16 15:24:15 2014
@@ -37,6 +37,7 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
@@ -107,6 +108,7 @@ class SanitizerCoverageModule : public M
Function *SanCovIndirCallFunction;
Function *SanCovModuleInit;
Function *SanCovTraceEnter, *SanCovTraceBB;
+ InlineAsm *EmptyAsm;
Type *IntptrTy;
LLVMContext *C;
@@ -146,6 +148,10 @@ bool SanitizerCoverageModule::runOnModul
SanCovModuleInit = checkInterfaceFunction(M.getOrInsertFunction(
kSanCovModuleInitName, Type::getVoidTy(*C), IntptrTy, nullptr));
SanCovModuleInit->setLinkage(Function::ExternalLinkage);
+ // We insert an empty inline asm after cov callbacks to avoid callback merge.
+ EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
+ StringRef(""), StringRef(""),
+ /*hasSideEffects=*/true);
if (ClExperimentalTracing) {
SanCovTraceEnter = checkInterfaceFunction(
@@ -283,6 +289,7 @@ void SanitizerCoverageModule::InjectCove
IRB.SetCurrentDebugLocation(EntryLoc);
// __sanitizer_cov gets the PC of the instruction using GET_CALLER_PC.
IRB.CreateCall(SanCovFunction, Guard);
+ IRB.CreateCall(EmptyAsm); // Avoids callback merge.
}
char SanitizerCoverageModule::ID = 0;
Modified: llvm/trunk/test/Instrumentation/SanitizerCoverage/coverage.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/SanitizerCoverage/coverage.ll?rev=224372&r1=224371&r2=224372&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/SanitizerCoverage/coverage.ll (original)
+++ llvm/trunk/test/Instrumentation/SanitizerCoverage/coverage.ll Tue Dec 16 15:24:15 2014
@@ -37,6 +37,7 @@ entry:
; CHECK1: %1 = icmp eq i8 0, %0
; CHECK1: br i1 %1, label %2, label %3
; CHECK1: call void @__sanitizer_cov(i8*{{.*}})
+; CHECK1: call void asm sideeffect "", ""()
; CHECK1-NOT: call void @__sanitizer_cov
; CHECK1: ret void
@@ -48,8 +49,11 @@ entry:
; CHECK2-LABEL: define void @foo
; CHECK2: call void @__sanitizer_cov
+; CHECK2: call void asm sideeffect "", ""()
; CHECK2: call void @__sanitizer_cov
+; CHECK2: call void asm sideeffect "", ""()
; CHECK2: call void @__sanitizer_cov
+; CHECK2: call void asm sideeffect "", ""()
; CHECK2-NOT: call void @__sanitizer_cov
; CHECK2: ret void
More information about the llvm-commits
mailing list