[llvm] [ASan] AddressSanitizerPass constructor should honor the AsanCtorKind argument (PR #72330)

Usama Hameed via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 12:24:49 PST 2023


https://github.com/usama54321 updated https://github.com/llvm/llvm-project/pull/72330

>From b4b0010f4e3614124a997bc7f2123c3c620e3160 Mon Sep 17 00:00:00 2001
From: usama <u_hameed at apple.com>
Date: Wed, 15 Nov 2023 12:23:46 -0800
Subject: [PATCH] [ASan] AddressSanitizerPass constructor should honor the
 AsanCtorKind argument.

Currently, the ConstructorKind member variable in AddressSanitizerPass
gets overriden by the ClConstructorKind whether the option is passed
from the command line or not.  This override should only happen if the
ClConstructorKind argument is passed from the command line.  Otherwise,
the constructor should honor the argument passed to it. This patch makes
this fix.

rdar://118423755
---
 llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 5c2763850ac6540..ea5fcf26e3de1e6 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -803,7 +803,9 @@ class ModuleAddressSanitizer {
         // do globals-gc.
         UseCtorComdat(UseGlobalsGC && ClWithComdat && !this->CompileKernel),
         DestructorKind(DestructorKind),
-        ConstructorKind(ConstructorKind) {
+        ConstructorKind(ClConstructorKind.getNumOccurrences() > 0
+                            ? ClConstructorKind
+                            : ConstructorKind) {
     C = &(M.getContext());
     int LongSize = M.getDataLayout().getPointerSizeInBits();
     IntptrTy = Type::getIntNTy(*C, LongSize);
@@ -1149,7 +1151,7 @@ AddressSanitizerPass::AddressSanitizerPass(
     AsanCtorKind ConstructorKind)
     : Options(Options), UseGlobalGC(UseGlobalGC),
       UseOdrIndicator(UseOdrIndicator), DestructorKind(DestructorKind),
-      ConstructorKind(ClConstructorKind) {}
+      ConstructorKind(ConstructorKind) {}
 
 PreservedAnalyses AddressSanitizerPass::run(Module &M,
                                             ModuleAnalysisManager &MAM) {



More information about the llvm-commits mailing list