[llvm-dev] Why does verifyFunction dislike this?

Viktor Was BSc via llvm-dev llvm-dev at lists.llvm.org
Sun May 12 16:26:43 PDT 2019


Hi Russell. 
Disclaimer: I haven't created IR from scratch nor have I used IRBuilder or Verifier before. 

There is a second parameter in verifyFunction which is the output stream it should write error messages to in case errors occur. 

Just from looking at the output I see that f is not mangled, maybe that could be a problem?
Try Mangler::getNameWithPrefix(...) from "llvm/IR/Manger.h"

Regards,
Viktor

On May 13, 2019, 00:55, at 00:55, Russell Wallace via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>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:
>
>#ifdef _MSC_VER
>#pragma warning(disable : 4141)
>#pragma warning(disable : 4530)
>#pragma warning(disable : 4624)
>#endif
>
>#include <llvm/IR/IRBuilder.h>
>#include <llvm/IR/Verifier.h>
>using namespace llvm;
>
>int main(int argc, char **argv) {
>  LLVMContext context;
>  IRBuilder<> builder(context);
>  Module module("", context);
>
>  // Function
>  auto rty = Type::getInt32Ty(context);
>  SmallVector<Type *, 1> pty;
>  auto ty = FunctionType::get(rty, pty, false);
>auto f = Function::Create(ty, GlobalValue::CommonLinkage, "f", module);
>
>  // Entry block
>  auto entry = BasicBlock::Create(context, "entry", f);
>  builder.SetInsertPoint(entry);
>
>  // return 0
>  auto val = ConstantInt::getSigned(rty, 0);
>  builder.CreateRet(val);
>
>  // Check
>  f->dump();
>  outs() << verifyFunction(*f) << '\n';
>  return 0;
>}
>
>Output:
>
>define common i32 @f() {
>entry:
>  ret i32 0
>}
>
>1
>
>So the verifier says there is a problem, but I don't see anywhere the
>problem could be. What am I missing?
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>LLVM Developers mailing list
>llvm-dev at lists.llvm.org
>https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190513/ae4accfe/attachment.html>


More information about the llvm-dev mailing list