Skip to content

[NFC] Fix use-after-free: track TargetLibraryAnalysis in BasicAAResult invalidation - #183852

Merged
dpaoliello merged 1 commit into
llvm:mainfrom
dpaoliello:fixav
Feb 27, 2026
Merged

dpaoliello merged 1 commit into
llvm:mainfrom
dpaoliello:fixav

Conversation

@dpaoliello

@dpaoliello dpaoliello commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

BasicAAResult holds a reference to TargetLibraryInfo but its invalidate() function did not check TargetLibraryAnalysis. When the pass manager destroyed and re-created TLI (e.g. during CGSCC invalidation or FAM.clear()), BasicAAResult survived with a dangling TLI reference.

This was exposed by #157495 which added aliasErrno(), the first code path that dereferences TLI from BasicAAResult during the CGSCC pipeline, causing a AV when compiling Rust's core library on Arm64 Windows.

This change adds TargetLibraryAnalysis to the invalidation check so BasicAAResult is properly invalidated when its TLI reference becomes stale.

… invalidation

BasicAAResult holds a reference to TargetLibraryInfo but its invalidate()
method did not check TargetLibraryAnalysis. When the pass manager destroyed
and re-created TLI (e.g. during CGSCC invalidation or FAM.clear()),
BasicAAResult survived with a dangling TLI reference because it only tracked
AssumptionAnalysis and DominatorTreeAnalysis as dependencies.

This was exposed by commit f9f62ef which added aliasErrno(), the first
code path that dereferences TLI from BasicAAResult during the CGSCC pipeline,
causing a STATUS_ACCESS_VIOLATION crash when compiling rust core on
aarch64-pc-windows-msvc.

Add TargetLibraryAnalysis to the invalidation check so BasicAAResult is
properly invalidated when its TLI reference becomes stale.
@dpaoliello
dpaoliello requested a review from nikic as a code owner February 27, 2026 22:19
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Feb 27, 2026
@llvmbot

llvmbot commented Feb 27, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-llvm-analysis

Author: Daniel Paoliello (dpaoliello)

Changes

BasicAAResult holds a reference to TargetLibraryInfo but its invalidate() function did not check TargetLibraryAnalysis. When the pass manager destroyed and re-created TLI (e.g. during CGSCC invalidation or FAM.clear()), BasicAAResult survived with a dangling TLI reference.

This was exposed by !157495 which added aliasErrno(), the first code path that dereferences TLI from BasicAAResult during the CGSCC pipeline, causing a AV when compiling Rust's core library on Arm64 Windows.

This change adds TargetLibraryAnalysis to the invalidation check so BasicAAResult is properly invalidated when its TLI reference becomes stale.


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

1 Files Affected:

  • (modified) llvm/lib/Analysis/BasicAliasAnalysis.cpp (+2-1)
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 1d5f9ac465808..64e035436a414 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -86,7 +86,8 @@ bool BasicAAResult::invalidate(Function &Fn, const PreservedAnalyses &PA,
   // may be created without handles to some analyses and in that case don't
   // depend on them.
   if (Inv.invalidate<AssumptionAnalysis>(Fn, PA) ||
-      (DT_ && Inv.invalidate<DominatorTreeAnalysis>(Fn, PA)))
+      (DT_ && Inv.invalidate<DominatorTreeAnalysis>(Fn, PA)) ||
+      Inv.invalidate<TargetLibraryAnalysis>(Fn, PA))
     return true;
 
   // Otherwise this analysis result remains valid.

@dpaoliello
dpaoliello merged commit 7886257 into llvm:main Feb 27, 2026
12 checks passed
@dpaoliello
dpaoliello deleted the fixav branch February 27, 2026 23:19
@dpaoliello dpaoliello added this to the LLVM 22.x Release milestone Feb 27, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in LLVM Release Status Feb 27, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in LLVM Release Status Feb 27, 2026
@dpaoliello

Copy link
Copy Markdown
Contributor Author

/cherry-pick 7886257

@llvmbot

llvmbot commented Feb 27, 2026

Copy link
Copy Markdown
Member

/pull-request #183865

sahas3 pushed a commit to sahas3/llvm-project that referenced this pull request Mar 4, 2026
…t invalidation (llvm#183852)

`BasicAAResult` holds a reference to `TargetLibraryInfo` but its
`invalidate()` function did not check `TargetLibraryAnalysis`. When the
pass manager destroyed and re-created `TLI` (e.g. during `CGSCC`
invalidation or `FAM.clear()`), `BasicAAResult` survived with a dangling
`TLI` reference.

This was exposed by llvm#157495 which added `aliasErrno()`, the first code
path that dereferences `TLI` from `BasicAAResult` during the `CGSCC`
pipeline, causing a AV when compiling Rust's core library on Arm64
Windows.

This change adds `TargetLibraryAnalysis` to the invalidation check so
`BasicAAResult` is properly invalidated when its `TLI` reference becomes
stale.
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
…t invalidation (llvm#183852)

`BasicAAResult` holds a reference to `TargetLibraryInfo` but its
`invalidate()` function did not check `TargetLibraryAnalysis`. When the
pass manager destroyed and re-created `TLI` (e.g. during `CGSCC`
invalidation or `FAM.clear()`), `BasicAAResult` survived with a dangling
`TLI` reference.

This was exposed by llvm#157495 which added `aliasErrno()`, the first code
path that dereferences `TLI` from `BasicAAResult` during the `CGSCC`
pipeline, causing a AV when compiling Rust's core library on Arm64
Windows.

This change adds `TargetLibraryAnalysis` to the invalidation check so
`BasicAAResult` is properly invalidated when its `TLI` reference becomes
stale.
dyung pushed a commit that referenced this pull request Mar 5, 2026
…t invalidation (#183852)

`BasicAAResult` holds a reference to `TargetLibraryInfo` but its
`invalidate()` function did not check `TargetLibraryAnalysis`. When the
pass manager destroyed and re-created `TLI` (e.g. during `CGSCC`
invalidation or `FAM.clear()`), `BasicAAResult` survived with a dangling
`TLI` reference.

This was exposed by #157495 which added `aliasErrno()`, the first code
path that dereferences `TLI` from `BasicAAResult` during the `CGSCC`
pipeline, causing a AV when compiling Rust's core library on Arm64
Windows.

This change adds `TargetLibraryAnalysis` to the invalidation check so
`BasicAAResult` is properly invalidated when its `TLI` reference becomes
stale.

(cherry picked from commit 7886257)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

Development

Successfully merging this pull request may close these issues.

3 participants