<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - function creation crash in getContext()"
   href="https://bugs.llvm.org/show_bug.cgi?id=34673">34673</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>function creation crash in getContext()
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>5.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Core LLVM classes
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>guillaume@morinfr.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=19174" name="attach_19174" title="testcase">attachment 19174</a> <a href="attachment.cgi?id=19174&action=edit" title="testcase">[details]</a></span>
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</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>