From d6f7346a4b4bdbdfef9ba7a5b8619e42091e2440 Mon Sep 17 00:00:00 2001 From: Piotr Padlewski Date: Wed, 23 May 2018 09:16:44 +0000 Subject: Fix aliasing of launder.invariant.group Summary: Patch for capture tracking broke bootstrap of clang with -fstict-vtable-pointers which resulted in debbugging nightmare. It was fixed https://reviews.llvm.org/D46900 but as it turned out, there were other parts like inliner (computing of noalias metadata) that I found after bootstraping with enabled assertions. Reviewers: hfinkel, rsmith, chandlerc, amharc, kuhar Subscribers: JDevlieghere, eraman, llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D47088 llvm-svn: 333070 --- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp') diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index 55a53f2122a..c1582b6e298 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -132,16 +132,8 @@ static bool isNonEscapingLocalObject(const Value *V) { /// Returns true if the pointer is one which would have been considered an /// escape by isNonEscapingLocalObject. static bool isEscapeSource(const Value *V) { - if (auto CS = ImmutableCallSite(V)) { - // launder_invariant_group captures its argument only by returning it, - // so it might not be considered an escape by isNonEscapingLocalObject. - // Note that adding similar special cases for intrinsics in CaptureTracking - // requires handling them here too. - if (CS.getIntrinsicID() == Intrinsic::launder_invariant_group) - return false; - + if (ImmutableCallSite(V)) return true; - } if (isa(V)) return true; @@ -438,11 +430,19 @@ bool BasicAAResult::DecomposeGEPExpression(const Value *V, const GEPOperator *GEPOp = dyn_cast(Op); if (!GEPOp) { - if (auto CS = ImmutableCallSite(V)) - if (const Value *RV = CS.getReturnedArgOperand()) { - V = RV; + if (auto CS = ImmutableCallSite(V)) { + // Note: getArgumentAliasingToReturnedPointer keeps it in sync with + // CaptureTracking, which is needed for correctness. This is because + // some intrinsics like launder.invariant.group returns pointers that + // are aliasing it's argument, which is known to CaptureTracking. + // If AliasAnalysis does not use the same information, it could assume + // that pointer returned from launder does not alias it's argument + // because launder could not return it if the pointer was not captured. + if (auto *RP = getArgumentAliasingToReturnedPointer(CS)) { + V = RP; continue; } + } // If it's not a GEP, hand it off to SimplifyInstruction to see if it // can come up with something. This matches what GetUnderlyingObject does. -- cgit v1.2.3