Russell Wallace via llvm-dev
2019-May-12 22:54 UTC
[llvm-dev] Why does verifyFunction dislike this?
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>
Viktor Was BSc via llvm-dev
2019-May-12 23:26 UTC
[llvm-dev] Why does verifyFunction dislike this?
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>
Russell Wallace via llvm-dev
2019-May-12 23:42 UTC
[llvm-dev] Why does verifyFunction dislike this?
On Mon, May 13, 2019 at 12:26 AM Viktor Was BSc <gs15m015 at technikum-wien.at> wrote:> 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. > >Ah, that led to a solution, thanks! Now the verifier reports the specific problem: functions may not have common linkage. When I change it to external linkage, the verifier is happy. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190513/e96d18ba/attachment.html>