Skip to content

Conversation

@usx95
Copy link
Contributor

@usx95 usx95 commented Sep 19, 2025

Disable canonicalization in immutable collections for lifetime analysis.

Modified the LifetimeFactory struct in LifetimeSafety.cpp to explicitly initialize the immutable collection factories with canonicalize=false. This prevents the factories from canonicalizing their data structures, which can improve performance by avoiding unnecessary comparisons and digest computations.

@github-actions
Copy link

github-actions bot commented Sep 19, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@usx95 usx95 force-pushed the users/usx95/09-19-no-canonicalize branch from 05da67b to 9916bec Compare September 19, 2025 21:44
@usx95 usx95 changed the title no-canonicalize [LifetimeSafety] Disable canonicalization in immutable collections Sep 19, 2025
@usx95 usx95 marked this pull request as ready for review September 19, 2025 21:46
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:analysis clang:temporal-safety Issue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr) labels Sep 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2025

@llvm/pr-subscribers-clang-temporal-safety

@llvm/pr-subscribers-clang-analysis

Author: Utkarsh Saxena (usx95)

Changes

Disable canonicalization in immutable collections for lifetime analysis.

Modified the LifetimeFactory struct in LifetimeSafety.cpp to explicitly initialize the immutable collection factories with canonicalize=false. This prevents the factories from canonicalizing their data structures, which can improve performance by avoiding unnecessary comparisons and digest computations.


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

1 Files Affected:

  • (modified) clang/lib/Analysis/LifetimeSafety.cpp (+6-3)
diff --git a/clang/lib/Analysis/LifetimeSafety.cpp b/clang/lib/Analysis/LifetimeSafety.cpp
index 0dd5716d93fb6..43cab406a9dc3 100644
--- a/clang/lib/Analysis/LifetimeSafety.cpp
+++ b/clang/lib/Analysis/LifetimeSafety.cpp
@@ -966,9 +966,12 @@ using ExpiredLoanMap = llvm::ImmutableMap<LoanID, const ExpireFact *>;
 /// An object to hold the factories for immutable collections, ensuring
 /// that all created states share the same underlying memory management.
 struct LifetimeFactory {
-  OriginLoanMap::Factory OriginMapFactory;
-  LoanSet::Factory LoanSetFactory;
-  ExpiredLoanMap::Factory ExpiredLoanMapFactory;
+  // Avoid canonicalising
+  OriginLoanMap::Factory OriginMapFactory =
+      OriginLoanMap::Factory(/*canonicalize=*/false);
+  LoanSet::Factory LoanSetFactory = LoanSet::Factory(/*canonicalize=*/false);
+  ExpiredLoanMap::Factory ExpiredLoanMapFactory =
+      ExpiredLoanMap::Factory(/*canonicalize=*/false);
 };
 
 /// Represents the dataflow lattice for loan propagation.

@usx95 usx95 force-pushed the users/usx95/09-19-no-canonicalize branch from 0775d9e to 53adfd8 Compare September 22, 2025 15:33
Base automatically changed from users/usx95/09-19-fix-add-immutable-set to main September 25, 2025 15:50
@usx95 usx95 enabled auto-merge (squash) September 25, 2025 15:51
@usx95 usx95 merged commit fc9369a into main Sep 25, 2025
9 checks passed
@usx95 usx95 deleted the users/usx95/09-19-no-canonicalize branch September 25, 2025 16:11
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
…lvm#159850)

Disable canonicalization in immutable collections for lifetime analysis.

Modified the `LifetimeFactory` struct in `LifetimeSafety.cpp` to
explicitly initialize the immutable collection factories with
`canonicalize=false`. This prevents the factories from canonicalizing
their data structures, which can improve performance by avoiding
unnecessary comparisons and digest computations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:analysis clang:temporal-safety Issue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr) clang Clang issues not falling into any other category

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants