[llvm-dev] Why does verifyFunction dislike this?

Russell Wallace via llvm-dev llvm-dev at lists.llvm.org
Sun May 12 15:54:38 PDT 2019


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190512/5689127d/attachment.html>


More information about the llvm-dev mailing list