Ahmad Nouralizadeh via llvm-dev
2018-Aug-07 20:26 UTC
[llvm-dev] Error Calling eraseFromParent()
The code is really simple. But I can not the reason for the segmentation fault. I only know that the eraseFromParent() function leads to it. The whole code is: ... bool runOnFunction(Function &F) override { for (auto &I : instructions(F)) { if (auto* op = dyn_cast<BinaryOperator>(&I)) { IRBuilder<> builder(op); Value* lhs = op->getOperand(0); Value* rhs = op->getOperand(1); Value* mul = builder.CreateMul(lhs, rhs); for (auto& U : op->uses()) { User* user = U.getUser(); user->setOperand(U.getOperandNo(), mul); } I.eraseFromParent(); } } ... And I think that the code worked well with LLVM-3.6.0 that I tested one year ago. Now, I use LLVM-6.0.0. Regards. On Tue, Aug 7, 2018 at 8:11 PM, <paul.robinson at sony.com> wrote:> LLVMSymbolizer is invoked while trying to pretty-print a crash backtrace. > "error reading file" suggests that you are on Windows and it cannot find > the .pdb file with symbol information. > > If that's the case, are you doing either a Debug or RelWithDebInfo build? > If you are, I don't know what else to suggest. > > > > Note that LLVMSymbolizer is trying to make the traceback more > understandable; it has nothing to do with the cause of your problem. If > you are triggering an assertion, the assertion message should tell you > where that is. (You did run cmake with –DLLVM_ENABLE_ASSERTIONS=ON, > right?) If not, likely you are dereferencing a null pointer somewhere. > Personally I debug with 'printf' statements, but that's just me. > > --paulr > > > > *From:* llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] *On Behalf Of *Ahmad > Nouralizadeh via llvm-dev > *Sent:* Tuesday, August 07, 2018 11:03 AM > *To:* llvm-dev at lists.llvm.org > *Subject:* [llvm-dev] Error Calling eraseFromParent() > > > > Hi. > > This is part of my code: > > ... > > if (auto* op = dyn_cast<BinaryOperator>(&I)) { > > Value* lhs = op->getOperand(0); > > Value* rhs = op->getOperand(1); > > Value* mul = builder.CreateMul(lhs, rhs); > > > > for (auto& U : op->uses()) { > > User* user = U.getUser(); > > user->setOperand(U.getOperandNo(), mul); > > } > > > > I.eraseFromParent(); > > } > > ... > > This leads to the following runtime error: > > LLVMSymbolizer: error reading file: No such file or directory > > ... > > Does anybody know the solution? > > Regards. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180808/c96b2204/attachment.html>
Björn Pettersson A via llvm-dev
2018-Aug-07 21:34 UTC
[llvm-dev] Error Calling eraseFromParent()
It looks quite dangerous to erase the instruction I inside the loop when iterating over all instructions in the function. I guess it depends on how the range based iterator is implemented if that works or not. I think that you, for example, can change the range based iteration for (auto &I : instructions(F)) into something like this for (inst_iterator It = inst_begin(&F), Ie = inst_end(&F); It != Ie;) { Instruction *I = &*(It++); ... } That will make sure that you step the iterator before modifying the data structure you iterate over. Regards, Björn ________________________________________ From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Ahmad Nouralizadeh via llvm-dev <llvm-dev at lists.llvm.org> Sent: Tuesday, August 7, 2018 22:26 To: paul.robinson at sony.com Cc: llvm-dev at lists.llvm.org Subject: Re: [llvm-dev] Error Calling eraseFromParent() The code is really simple. But I can not the reason for the segmentation fault. I only know that the eraseFromParent() function leads to it. The whole code is: ... bool runOnFunction(Function &F) override { for (auto &I : instructions(F)) { if (auto* op = dyn_cast<BinaryOperator>(&I)) { IRBuilder<> builder(op); Value* lhs = op->getOperand(0); Value* rhs = op->getOperand(1); Value* mul = builder.CreateMul(lhs, rhs); for (auto& U : op->uses()) { User* user = U.getUser(); user->setOperand(U.getOperandNo(), mul); } I.eraseFromParent(); } } ... And I think that the code worked well with LLVM-3.6.0 that I tested one year ago. Now, I use LLVM-6.0.0. Regards.
Ahmad Nouralizadeh via llvm-dev
2018-Aug-07 23:54 UTC
[llvm-dev] Error Calling eraseFromParent()
Thanks Bjorn! But The problem is still there. On Wed, Aug 8, 2018 at 2:04 AM, Björn Pettersson A < bjorn.a.pettersson at ericsson.com> wrote:> It looks quite dangerous to erase the instruction I inside the loop when > iterating over all instructions in the function. > I guess it depends on how the range based iterator is implemented if that > works or not. > > I think that you, for example, can change the range based iteration > > for (auto &I : instructions(F)) > > into something like this > > for (inst_iterator It = inst_begin(&F), Ie = inst_end(&F); It != Ie;) { > Instruction *I = &*(It++); > ... > } > > That will make sure that you step the iterator before modifying the data > structure you iterate over. > > Regards, > Björn > ________________________________________ > From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Ahmad > Nouralizadeh via llvm-dev <llvm-dev at lists.llvm.org> > Sent: Tuesday, August 7, 2018 22:26 > To: paul.robinson at sony.com > Cc: llvm-dev at lists.llvm.org > Subject: Re: [llvm-dev] Error Calling eraseFromParent() > > The code is really simple. But I can not the reason for the segmentation > fault. I only know that the eraseFromParent() function leads to it. The > whole code is: > ... > bool runOnFunction(Function &F) override { > > for (auto &I : instructions(F)) { > > if (auto* op = dyn_cast<BinaryOperator>(&I)) { > IRBuilder<> builder(op); > > Value* lhs = op->getOperand(0); > Value* rhs = op->getOperand(1); > Value* mul = builder.CreateMul(lhs, rhs); > > for (auto& U : op->uses()) { > User* user = U.getUser(); > user->setOperand(U.getOperandNo(), mul); > } > > I.eraseFromParent(); > } > > } > ... > And I think that the code worked well with LLVM-3.6.0 that I tested one > year ago. Now, I use LLVM-6.0.0. > Regards. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180808/9d592482/attachment.html>