[PATCH] D52814: [PassManager/Sanitizer] Enable usage of ported AddressSanitizer passes with -fsanitize=address
Leonard Chan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 2 16:54:27 PDT 2018
leonardchan created this revision.
leonardchan added reviewers: mcgrathr, phosek, fedor.sergeev, philip.pfaffe, vitalybuka.
leonardchan added projects: clang, Sanitizers.
leonardchan added a dependency: D52739: [PassManager/Sanitizer] Port of AddresSanitizer pass from legacy to new PassManager.
Enable usage of `AddressSanitizer` and `AddressModuleSanitizer` ported from the legacy to the new PassManager.
This patch depends on https://reviews.llvm.org/D52739.
Repository:
rC Clang
https://reviews.llvm.org/D52814
Files:
lib/CodeGen/BackendUtil.cpp
test/CodeGen/asan-new-pm.ll
Index: test/CodeGen/asan-new-pm.ll
===================================================================
--- /dev/null
+++ test/CodeGen/asan-new-pm.ll
@@ -0,0 +1,31 @@
+; RUN: %clang_cc1 -S -emit-llvm -o - -fexperimental-new-pass-manager -fsanitize=address %s | FileCheck %s
+
+; CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor
+
+define i32 @test_load(i32* %a) sanitize_address {
+entry:
+; CHECK: %0 = ptrtoint i32* %a to i64
+; CHECK: %1 = lshr i64 %0, 3
+; CHECK: %2 = add i64 %1, 2147450880
+; CHECK: %3 = inttoptr i64 %2 to i8*
+; CHECK: %4 = load i8, i8* %3
+; CHECK: %5 = icmp ne i8 %4, 0
+; CHECK: br i1 %5, label %6, label %12, !prof !0
+
+; CHECK:; <label>:6: ; preds = %entry
+; CHECK: %7 = and i64 %0, 7
+; CHECK: %8 = add i64 %7, 3
+; CHECK: %9 = trunc i64 %8 to i8
+; CHECK: %10 = icmp sge i8 %9, %4
+; CHECK: br i1 %10, label %11, label %12
+
+; CHECK:; <label>:11: ; preds = %6
+; CHECK: call void @__asan_report_load4(i64 %0)
+; CHECK: call void asm sideeffect "", ""()
+; CHECK: unreachable
+
+; CHECK:; <label>:12: ; preds = %6, %entry
+
+ %tmp1 = load i32, i32* %a, align 4
+ ret i32 %tmp1
+}
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -27,6 +27,7 @@
#include "llvm/CodeGen/RegAllocRegistry.h"
#include "llvm/CodeGen/SchedulerRegistry.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/IR/AddressSanitizerPass.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LegacyPassManager.h"
@@ -902,6 +903,12 @@
}
}
+static FunctionPassManager buildAddressSanitizerPipeline(bool DebugLogging) {
+ FunctionPassManager FPM(DebugLogging);
+ FPM.addPass(AddressSanitizerPass());
+ return FPM;
+}
+
/// A clean version of `EmitAssembly` that uses the new pass manager.
///
/// Not all features are currently supported in this system, but where
@@ -1019,6 +1026,17 @@
CodeGenOpts.DebugPassManager);
}
}
+
+ if (LangOpts.Sanitize.has(SanitizerKind::Address)) {
+ MPM.addPass(AddressSanitizerModulePass());
+
+ // Add Function Pass
+ CGSCCPassManager MainCGPipeline(CodeGenOpts.DebugPassManager);
+ MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
+ buildAddressSanitizerPipeline(CodeGenOpts.DebugPassManager)));
+ MPM.addPass(
+ createModuleToPostOrderCGSCCPassAdaptor(std::move(MainCGPipeline)));
+ }
}
// FIXME: We still use the legacy pass manager to do code generation. We
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52814.168054.patch
Type: text/x-patch
Size: 2734 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181002/f1b8bcc0/attachment.bin>
More information about the cfe-commits
mailing list