0

I was trying to run the simplify CFG Pass in LLVM , and delete an unreachable basic block after running one of my own IR transforms , but I keep getting the error -

While deleting: i8* %g

Use still stuck around after Def is destroyed: store i8 0, i8* %g

I am well aware of what that means, but isn't the whole purpose of the "simplifyCFGPass" to delete the unreachable basic blocks for us ? Why must it then throw this error ? I would assume it should simply be able to manage all the use-def dependencies and delete the instructions in the unreachable "continuation" basic block below.

Following is the relevant IR -

entry:
  %a3 = alloca i32
  store i32 %a, i32* %a3
  %a4 = load i32, i32* %a3 
  %ifcond = icmp ne i32 %a4, 0
  br i1 %ifcond, label %then, label %else



then:                                             ; preds = %entry
  %gclone1 = alloca i32
  store i32 0, i32* %gclone1
  ret i5 0

else:                                             ; preds = %entry
  %gclone4 = alloca i64
  store i64 0, i64* %gclone4
  ret i5 0

continuation:                                     ; No predecessors!
  %iftmp = phi i32 [ 32, %then ], [ 64, %else ], !range !0
  %datasize = alloca i32
  store i32 %iftmp, i32* %datasize

  %g = alloca i8 ---------------------> Issue
  store i8 0, i8* %g ---------------------> Issue
  ret i5 0
}

Can someone please explain why this error crops up? Isn't the API supposed to handle this?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
mal
  • 143
  • 2
  • 12
  • Does this error occur when you run your transformation or when you run simplifyCFGPass? – deLta Jun 16 '17 at 19:11
  • I run the CFG Pass ( using FPM->run(*F) ) ... my pass is simply some C++ code that changes the IR, I am not using it in the opt tool or anything like that ... – mal Jun 16 '17 at 22:33

1 Answers1

0

Your IR is clearly broken. You're having:

%iftmp = phi i32 [ 32, %then ], [ 64, %else ], !range !0

However, per LLVM IR specification (http://llvm.org/docs/LangRef.html#phi-instruction):

The type of the incoming values is specified with the first type field. After this, the ‘phi‘ instruction takes a list of pairs as arguments, with one pair for each predecessor basic block of the current block. Only values of first class type may be used as the value arguments to the PHI node. Only labels may be used as the label arguments.

This is clearly violated in your case and therefore the subsequent IR transformation passes might easily fail. I'd suggest you to run IR verification pass (e.g. via opt -verify) after your transformation pass.

Anton Korobeynikov
  • 9,074
  • 25
  • 28
  • Nope. I think I have clearly mentioned in the question "delete an unreachable basic block after running one of my own IR transforms". The phi node is not broken ( and the verifier pass does not detect an issue ) – mal Jun 19 '17 at 13:20
  • The phi node is certainly broken. Neither %else nor %then are predecessors of %continuation – Anton Korobeynikov Jun 20 '17 at 06:56