[llvm] 1d9f490 - [BasicAA] Add simple depth limit to avoid stack overflow (PR49151)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 19 02:53:34 PST 2021


Author: Nikita Popov
Date: 2021-02-19T11:05:42+01:00
New Revision: 1d9f4903c6151f1b3f90a743eac339dde8ef5d29

URL: https://github.com/llvm/llvm-project/commit/1d9f4903c6151f1b3f90a743eac339dde8ef5d29
DIFF: https://github.com/llvm/llvm-project/commit/1d9f4903c6151f1b3f90a743eac339dde8ef5d29.diff

LOG: [BasicAA] Add simple depth limit to avoid stack overflow (PR49151)

This is a simpler variant of D96647. It just adds a straightforward
depth limit with a high cutoff, without introducing complex logic
for BatchAA consistency. It accepts that we may cache a sub-optimal
result if the depth limit is hit.

Eventually this should be more fully addressed by D96647 or similar,
but in the meantime this avoids stack overflows in a cheap way.

Differential Revision: https://reviews.llvm.org/D96996

Added: 
    

Modified: 
    llvm/lib/Analysis/BasicAliasAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 81996f3f8e37..828d9130c78d 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1559,6 +1559,13 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
     V2Size = LocationSize::afterPointer();
   }
 
+  // FIXME: If this depth limit is hit, then we may cache sub-optimal results
+  // for recursive queries. For this reason, this limit is chosen to be large
+  // enough to be very rarely hit, while still being small enough to avoid
+  // stack overflows.
+  if (AAQI.Depth >= 512)
+    return MayAlias;
+
   // Check the cache before climbing up use-def chains. This also terminates
   // otherwise infinitely recursive queries.
   AAQueryInfo::LocPair Locs(MemoryLocation(V1, V1Size, V1AAInfo),


        


More information about the llvm-commits mailing list