<html><head></head><body><div dir="auto">Hi Russell. <br></div>
<div dir="auto">Disclaimer: I haven't created IR from scratch nor have I used IRBuilder or Verifier before. <br><br></div>
<div dir="auto">There is a second parameter in verifyFunction which is the output stream it should write error messages to in case errors occur. <br><br></div>
<div dir="auto">Just from looking at the output I see that f is not mangled, maybe that could be a problem?<br></div>
<div dir="auto">Try Mangler::getNameWithPrefix(...) from "llvm/IR/Manger.h"<br><br></div>
<div dir="auto">Regards,<br></div>
<div dir="auto">Viktor</div>
<div class="gmail_quote" >On May 13, 2019, at 00:55, Russell Wallace via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div dir="ltr"><div dir="ltr"><div dir="ltr">I am programmatically building some functions in intermediate representation, and trying to verify them, but the verifier always reports that there is a problem, and I can't see why. Minimal test case:<div><br></div><div><div>#ifdef _MSC_VER</div><div>#pragma warning(disable : 4141)</div><div>#pragma warning(disable : 4530)</div><div>#pragma warning(disable : 4624)</div><div>#endif</div><div><br></div><div>#include <llvm/IR/IRBuilder.h></div><div>#include <llvm/IR/Verifier.h></div><div>using namespace llvm;</div><div><br></div><div>int main(int argc, char **argv) {</div><div> LLVMContext context;</div><div> IRBuilder<> builder(context);</div><div> Module module("", context);</div><div><br></div><div> // Function</div><div> auto rty = Type::getInt32Ty(context);</div><div> SmallVector<Type *, 1> pty;</div><div> auto ty = FunctionType::get(rty, pty, false);</div><div> auto f = Function::Create(ty, GlobalValue::CommonLinkage, "f", module);</div><div><br></div><div> // Entry block</div><div> auto entry = BasicBlock::Create(context, "entry", f);</div><div> builder.SetInsertPoint(entry);</div><div><br></div><div> // return 0</div><div> auto val = ConstantInt::getSigned(rty, 0);</div><div> builder.CreateRet(val);</div><div><br></div><div> // Check</div><div> f->dump();</div><div> outs() << verifyFunction(*f) << '\n';</div><div> return 0;</div><div>}</div></div><div><br></div><div>Output:</div><div><div><br></div><div>define common i32 @f() {</div><div>entry:</div><div> ret i32 0</div><div>}</div><div><br></div></div><div>1</div><div><br></div><div>So the verifier says there is a problem, but I don't see anywhere the problem could be. What am I missing?</div></div></div></div>
<pre class="blue"><hr><br>LLVM Developers mailing list<br>llvm-dev@lists.llvm.org<br><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></pre></blockquote></div></body></html>