[llvm] 7547508 - Revert "[StackSafety] Skip ambiguous lifetime analysis"

Alexander Kornienko via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 7 18:34:40 PDT 2020


In case you need an isolated test case for a regression test, I happen to
have one:

template <class> struct a;
template <class u> struct a<u &> { typedef u e; };
template <class u> typename a<u>::e &&f(u &&g) {
  return static_cast<typename a<u>::e>(g);
}
typedef char h;
template <typename i> class j {
  i k;

public:
  bool l();
  void operator=(i g) {
    if (l())
      k = f(g);
  }
};
template <typename i> class m {
  j<i> n;

public:
  void operator=(i g) { n = g; }
};
class o {
  char *p;
  int x;
};
class F {
  o p;
  h q;

public:
  void r();
};
struct s {
  void t(F);
  struct H {
    h b, c, d;
  };
  m<H> z;
};
void s::t(F g) {
  g.r();
  z = H();
}


$ clang -cc1 -triple x86_64-grtev4-linux-gnu -emit-obj  -O3
-fsanitize=safe-stack -o qqq.o -x c++ qqq.cc
...
PLEASE submit a bug report to http://go/clang-crash-bug and include the
crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: clang -cc1 -triple x86_64-grtev4-linux-gnu
-emit-obj -O3 -fsanitize=safe-stack -o qqq.o -x c++ qqq.cc
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'qqq.cc'.
4.      Running pass 'Safe Stack instrumentation pass' on function
'@_ZN1s1tE1F'
 #0 0x000055ae224be7e2 SignalHandler(int)
 #1 0x00007f0d4a6ea9a0 __restore_rt
 #2 0x000055ae22390d64 llvm::StackLifetime::collectMarkers()
 #3 0x000055ae21fdc4ff (anonymous namespace)::SafeStack::run()
 #4 0x000055ae208396fe (anonymous
namespace)::SafeStackLegacyPass::runOnFunction(llvm::Function&)
(.llvm.1747005879505724891)
 #5 0x000055ae202a17c0 llvm::FPPassManager::runOnFunction(llvm::Function&)
 #6 0x000055ae202a1154 llvm::FPPassManager::runOnModule(llvm::Module&)
 #7 0x000055ae1f37fb05 llvm::legacy::PassManagerImpl::run(llvm::Module&)
...

On Fri, Aug 7, 2020 at 11:03 PM Vitaly Buka via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

>
> Author: Vitaly Buka
> Date: 2020-08-07T14:02:50-07:00
> New Revision: 7547508b7ae0985bde2b2cbba953f87e5c30e242
>
> URL:
> https://github.com/llvm/llvm-project/commit/7547508b7ae0985bde2b2cbba953f87e5c30e242
> DIFF:
> https://github.com/llvm/llvm-project/commit/7547508b7ae0985bde2b2cbba953f87e5c30e242.diff
>
> LOG: Revert "[StackSafety] Skip ambiguous lifetime analysis"
>
> This reverts commit 0b2616a8045cb776ea1514c3401d0a8577de1060.
>
> Crashes with safe-stack.
>
> Added:
>
>
> Modified:
>     llvm/include/llvm/Analysis/StackLifetime.h
>     llvm/lib/Analysis/StackLifetime.cpp
>     llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
>     llvm/test/CodeGen/AArch64/stack-tagging.ll
>
> Removed:
>
>
>
>
> ################################################################################
> diff  --git a/llvm/include/llvm/Analysis/StackLifetime.h
> b/llvm/include/llvm/Analysis/StackLifetime.h
> index 1c0e10368daf..8abc6cc1ce00 100644
> --- a/llvm/include/llvm/Analysis/StackLifetime.h
> +++ b/llvm/include/llvm/Analysis/StackLifetime.h
> @@ -121,8 +121,6 @@ class StackLifetime {
>    DenseMap<const BasicBlock *, SmallVector<std::pair<unsigned, Marker>,
> 4>>
>        BBMarkers;
>
> -  bool HasUnknownLifetimeStartOrEnd = false;
> -
>    void dumpAllocas() const;
>    void dumpBlockLiveness() const;
>    void dumpLiveRanges() const;
>
> diff  --git a/llvm/lib/Analysis/StackLifetime.cpp
> b/llvm/lib/Analysis/StackLifetime.cpp
> index d953a8762608..9727b7a33d1f 100644
> --- a/llvm/lib/Analysis/StackLifetime.cpp
> +++ b/llvm/lib/Analysis/StackLifetime.cpp
> @@ -11,7 +11,6 @@
>  #include "llvm/ADT/STLExtras.h"
>  #include "llvm/ADT/SmallVector.h"
>  #include "llvm/ADT/StringExtras.h"
> -#include "llvm/Analysis/ValueTracking.h"
>  #include "llvm/Config/llvm-config.h"
>  #include "llvm/IR/AssemblyAnnotationWriter.h"
>  #include "llvm/IR/BasicBlock.h"
> @@ -64,27 +63,42 @@ bool StackLifetime::isAliveAfter(const AllocaInst *AI,
>    return getLiveRange(AI).test(InstNum);
>  }
>
> +static bool readMarker(const Instruction *I, bool *IsStart) {
> +  if (!I->isLifetimeStartOrEnd())
> +    return false;
> +
> +  auto *II = cast<IntrinsicInst>(I);
> +  *IsStart = II->getIntrinsicID() == Intrinsic::lifetime_start;
> +  return true;
> +}
> +
>  void StackLifetime::collectMarkers() {
>    InterestingAllocas.resize(NumAllocas);
>    DenseMap<const BasicBlock *, SmallDenseMap<const IntrinsicInst *,
> Marker>>
>        BBMarkerSet;
>
>    // Compute the set of start/end markers per basic block.
> -  for (const BasicBlock *BB : depth_first(&F)) {
> -    for (const Instruction &I : *BB) {
> -      const IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I);
> -      if (!II || !II->isLifetimeStartOrEnd())
> -        continue;
> -      const AllocaInst *AI =
> llvm::findAllocaForValue(II->getArgOperand(1));
> -      if (!AI) {
> -        HasUnknownLifetimeStartOrEnd = true;
> -        continue;
> +  for (unsigned AllocaNo = 0; AllocaNo < NumAllocas; ++AllocaNo) {
> +    const AllocaInst *AI = Allocas[AllocaNo];
> +    SmallVector<const Instruction *, 8> WorkList;
> +    WorkList.push_back(AI);
> +    while (!WorkList.empty()) {
> +      const Instruction *I = WorkList.pop_back_val();
> +      for (const User *U : I->users()) {
> +        if (auto *BI = dyn_cast<BitCastInst>(U)) {
> +          WorkList.push_back(BI);
> +          continue;
> +        }
> +        auto *UI = dyn_cast<IntrinsicInst>(U);
> +        if (!UI)
> +          continue;
> +        bool IsStart;
> +        if (!readMarker(UI, &IsStart))
> +          continue;
> +        if (IsStart)
> +          InterestingAllocas.set(AllocaNo);
> +        BBMarkerSet[UI->getParent()][UI] = {AllocaNo, IsStart};
>        }
> -      bool IsStart = II->getIntrinsicID() == Intrinsic::lifetime_start;
> -      unsigned AllocaNo = AllocaNumbering[AI];
> -      if (IsStart)
> -        InterestingAllocas.set(AllocaNo);
> -      BBMarkerSet[BB][II] = {AllocaNo, IsStart};
>      }
>    }
>
> @@ -290,20 +304,6 @@ StackLifetime::StackLifetime(const Function &F,
>  }
>
>  void StackLifetime::run() {
> -  if (HasUnknownLifetimeStartOrEnd) {
> -    // There is marker which we can't assign to a specific alloca, so we
> -    // fallback to the most conservative results for the type.
> -    switch (Type) {
> -    case LivenessType::May:
> -      LiveRanges.resize(NumAllocas, getFullLiveRange());
> -      break;
> -    case LivenessType::Must:
> -      LiveRanges.resize(NumAllocas, LiveRange(Instructions.size()));
> -      break;
> -    }
> -    return;
> -  }
> -
>    LiveRanges.resize(NumAllocas, LiveRange(Instructions.size()));
>    for (unsigned I = 0; I < NumAllocas; ++I)
>      if (!InterestingAllocas.test(I))
>
> diff  --git a/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
> b/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
> index 470450a3a977..1c7eeb5ac69c 100644
> --- a/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
> +++ b/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
> @@ -742,7 +742,7 @@ if.end:
>  ; MAY-NEXT: Alive: <x y>
>  ; MUST-NEXT: Alive: <y>
>
> -  ret void
> +ret void
>  }
>
>  define void @unreachable() {
> @@ -778,62 +778,7 @@ end:
>  ; CHECK: end:
>  ; CHECK-NEXT: Alive: <x y>
>
> -  ret void
> -}
> -
> -define void @non_alloca(i8* %p) {
> -; CHECK-LABEL: define void @non_alloca
> -entry:
> -; CHECK: entry:
> -; MAY-NEXT: Alive: <x y>
> -; MUST-NEXT: Alive: <>
> -  %x = alloca i8, align 4
> -  %y = alloca i8, align 4
> -
> -  call void @llvm.lifetime.start.p0i8(i64 4, i8* %p)
> -; CHECK: call void @llvm.lifetime.start.p0i8(i64 4, i8* %p)
> -; MAY-NEXT: Alive: <x y>
> -; MUST-NEXT: Alive: <>
> -
> -  call void @llvm.lifetime.start.p0i8(i64 4, i8* %x)
> -; CHECK: call void @llvm.lifetime.start.p0i8(i64 4, i8* %x)
> -; MAY-NEXT: Alive: <x y>
> -; MUST-NEXT: Alive: <>
> -
> -  call void @llvm.lifetime.end.p0i8(i64 4, i8* %p)
> -; CHECK: call void @llvm.lifetime.end.p0i8(i64 4, i8* %p)
> -; MAY-NEXT: Alive: <x y>
> -; MUST-NEXT: Alive: <>
> -
> -  ret void
> -}
> -
> -define void @select_alloca(i1 %v) {
> -; CHECK-LABEL: define void @select_alloca
> -entry:
> -; CHECK: entry:
> -; MAY-NEXT: Alive: <x y>
> -; MUST-NEXT: Alive: <>
> -  %x = alloca i8, align 4
> -  %y = alloca i8, align 4
> -  %cxcy = select i1 %v, i8* %x, i8* %y
> -
> -  call void @llvm.lifetime.start.p0i8(i64 1, i8* %cxcy)
> -; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %cxcy)
> -; MAY-NEXT: Alive: <x y>
> -; MUST-NEXT: Alive: <>
> -
> -  call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
> -; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
> -; MAY-NEXT: Alive: <x y>
> -; MUST-NEXT: Alive: <>
> -
> -  call void @llvm.lifetime.end.p0i8(i64 1, i8* %x)
> -; CHECK: call void @llvm.lifetime.end.p0i8(i64 1, i8* %x)
> -; MAY-NEXT: Alive: <x y>
> -; MUST-NEXT: Alive: <>
> -
> -  ret void
> +ret void
>  }
>
>  declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
>
> diff  --git a/llvm/test/CodeGen/AArch64/stack-tagging.ll
> b/llvm/test/CodeGen/AArch64/stack-tagging.ll
> index 83fe4025ea0c..275b8a7dbad7 100644
> --- a/llvm/test/CodeGen/AArch64/stack-tagging.ll
> +++ b/llvm/test/CodeGen/AArch64/stack-tagging.ll
> @@ -192,9 +192,10 @@ another_bb:
>  ; CHECK: alloca { i32, [12 x i8] }, align 16
>  ; CHECK: call { i32, [12 x i8] }* @llvm.aarch64.tagp
>  ; CHECK: call void @llvm.aarch64.settag(
> -; CHECK: alloca { i32, [12 x i8] }, align 16
> -; CHECK: call { i32, [12 x i8] }* @llvm.aarch64.tagp
> -; CHECK: call void @llvm.aarch64.settag(
> +; SSI: alloca i32, align 4
> +; NOSSI: alloca { i32, [12 x i8] }, align 16
> +; NOSSI: call { i32, [12 x i8] }* @llvm.aarch64.tagp
> +; NOSSI: call void @llvm.aarch64.settag(
>  ; CHECK: store i32
>  ; CHECK: call void @noUse32(i32*
>  ; CHECK: store i32
> @@ -202,7 +203,7 @@ another_bb:
>  ; CHECK: call void @noUse32(i32*
>  ; CHECK: call void @llvm.aarch64.settag(
>  ; CHECK: call void @llvm.aarch64.settag(
> -; CHECK: call void @llvm.aarch64.settag(
> +; NOSSI: call void @llvm.aarch64.settag(
>  ; CHECK: ret void
>
> -!0 = !{}
> +!0 = !{}
> \ No newline at end of file
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200808/d0cf2b39/attachment.html>


More information about the llvm-commits mailing list