[PATCH] D15798: Fix for Bug 24852 (crash with -debug -instcombine)
    Mehdi AMINI via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Thu Jan  7 09:02:19 PST 2016
    
    
  
joker.eph added inline comments.
================
Comment at: unittests/IR/AsmWriterTest.cpp:49
@@ +48,3 @@
+  BI->insertAfter(Alloca1); // reparent so that it will be cleaned up
+}
+
----------------
joker.eph wrote:
> It seems a bit overkill to me to have to create a function and multiple basic blocks, I'd expect this to be close to minimal:
> 
> ```
> // PR24852: Ensure that an instruction can be printed even when it
> // has no parent.
> LLVMContext Ctx;
> auto Ty = Type::getInt32Ty(Ctx)
> auto Undef = UndefValue::get(Ty);
> std::unique_ptr<BinaryOperator> Add(BinaryOperator::CreateAdd(Undef, Undef));
> Add.setDebugLoc(DebugLoc());
> std::string S;
> raw_string_ostream OS(S);
> Add->print(OS)
> ASSERT_EQ(OS.str(), "<insert correct string here>");
> }
> ```
> 
> 
It's possible that the empty DebugLoc won't be enough and a metadata is needed I don't know.
Your original example can be fine, but add an `ASSERT_EQ` on the expected outputs.
http://reviews.llvm.org/D15798
    
    
More information about the llvm-commits
mailing list