Skip to content

AddressSanitizer: Add use-after-scope to pass options #130924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025

Conversation

guy-david
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 12, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Guy David (guy-david)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/130924.diff

3 Files Affected:

  • (modified) llvm/lib/Passes/PassBuilder.cpp (+2)
  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+3-1)
  • (modified) llvm/test/Other/new-pm-print-pipeline.ll (+3)
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 1f1e9561fefac..09fdd999a5d25 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -789,6 +789,8 @@ Expected<AddressSanitizerOptions> parseASanPassOptions(StringRef Params) {
 
     if (ParamName == "kernel") {
       Result.CompileKernel = true;
+    } else if (ParamName == "use-after-scope") {
+      Result.UseAfterScope = true;
     } else {
       return make_error<StringError>(
           formatv("invalid AddressSanitizer pass parameter '{0}' ", ParamName)
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index b5e9cde2ba5f6..23fd21cb28ca1 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1244,7 +1244,9 @@ void AddressSanitizerPass::printPipeline(
       OS, MapClassName2PassName);
   OS << '<';
   if (Options.CompileKernel)
-    OS << "kernel";
+    OS << "kernel;";
+  if (Options.UseAfterScope)
+    OS << "use-after-scope";
   OS << '>';
 }
 
diff --git a/llvm/test/Other/new-pm-print-pipeline.ll b/llvm/test/Other/new-pm-print-pipeline.ll
index eb3ffe3a098dd..db398d68fd426 100644
--- a/llvm/test/Other/new-pm-print-pipeline.ll
+++ b/llvm/test/Other/new-pm-print-pipeline.ll
@@ -120,3 +120,6 @@
 
 ; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='speculative-execution<only-if-divergent-target>' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-36
 ; CHECK-36: function(speculative-execution<only-if-divergent-target>)
+
+; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='module(asan<>,asan<kernel;use-after-scope>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-37
+; CHECK-37: asan<>,asan<kernel;use-after-scope>

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also update the pass to drop ClUseAfterScope?

@guy-david
Copy link
Contributor Author

guy-david commented Mar 12, 2025

Good idea, I confused it with the CodeGen option -fsanitize-address-use-after-scope.
The issue is that I don't see an easy way to explicitly disable a pass option, overriding its default value, because some tests use -asan-use-after-scope=0.
So I think it's best to leave it as it is for now.

@vitalybuka
Copy link
Collaborator

fsanitize-address-use-after-scope

-fno-sanitize-address-use-after-scope ?

@vitalybuka
Copy link
Collaborator

ClUseAfterScope

I would prefer a separate PR for that.

@guy-david guy-david merged commit 9820248 into main Mar 12, 2025
14 checks passed
@guy-david guy-david deleted the users/guy-david/asan-pipeline-use-after-scope branch March 12, 2025 15:17
guy-david added a commit to swiftlang/llvm-project that referenced this pull request Mar 16, 2025
frederik-h pushed a commit to frederik-h/llvm-project that referenced this pull request Mar 18, 2025
guy-david added a commit to swiftlang/llvm-project that referenced this pull request Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants