[llvm-bugs] [Bug 34673] New: function creation crash in getContext()

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 19 12:47:16 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34673

            Bug ID: 34673
           Summary: function creation crash in getContext()
           Product: libraries
           Version: 5.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Core LLVM classes
          Assignee: unassignedbugs at nondot.org
          Reporter: guillaume at morinfr.org
                CC: llvm-bugs at lists.llvm.org

Created attachment 19174
  --> https://bugs.llvm.org/attachment.cgi?id=19174&action=edit
testcase

This simple code worked just fine with llvm 4.0.  It crashes with llvm 5.0.  I
am really sorry if this is an issue with the code but can't see anything wrong:

$ cat llvm5_bug.cpp 
#include <llvm/IR/Module.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Type.h>

#include <memory>
#include <string>

int main(void)
{
    llvm::LLVMContext globalCtx;
    std::unique_ptr<llvm::Module> module(new llvm::Module("m", globalCtx));

    llvm::Type* argType = llvm::IntegerType::get(globalCtx, 8 * sizeof(short));
    llvm::Type* retType = llvm::IntegerType::get(globalCtx, 8 * sizeof(long));

    std::string name("funcName");
    llvm::Constant* c = module->getOrInsertFunction(name, retType, argType,
                                                    nullptr);
    llvm::Function* func = llvm::cast<llvm::Function>(c);
    func->arg_begin(); // crashes in here with llvm 5.0

    return 0;
}

$ g++-7 -Wall $(llvm-config-5.0 --libs --cflags) -o c llvm5_bug.cpp
$ ./c
Segmentation fault (core dumped)

Backtrace:
0x00007ffff51408b3 in llvm::Value::getContext() const () at
/build/llvm-toolchain-5.0-5.0/lib/IR/Value.cpp:697
697     /build/llvm-toolchain-5.0-5.0/lib/IR/Value.cpp: No such file or
directory.
(gdb) bt
#0  0x00007ffff51408b3 in llvm::Value::getContext() const () at
/build/llvm-toolchain-5.0-5.0/lib/IR/Value.cpp:697
#1  0x00007ffff514112c in llvm::Value::setNameImpl(llvm::Twine const&) () at
/build/llvm-toolchain-5.0-5.0/lib/IR/Value.cpp:229
#2  0x00007ffff51413a9 in llvm::Value::setName(llvm::Twine const&) () at
/build/llvm-toolchain-5.0-5.0/lib/IR/Value.cpp:285
#3  0x00007ffff50c91ea in llvm::Function::BuildLazyArguments() const () at
/build/llvm-toolchain-5.0-5.0/lib/IR/Function.cpp:257
#4  0x0000000000400d55 in llvm::Function::CheckLazyArguments (this=<optimized
out>) at /usr/lib/llvm-5.0/include/llvm/IR/Function.h:109
#5  llvm::Function::arg_begin (this=<optimized out>) at
/usr/lib/llvm-5.0/include/llvm/IR/Function.h:596
#6  main () at llvm5_bug.cpp:20

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170919/ce5d1c8f/attachment.html>


More information about the llvm-bugs mailing list