[llvm-dev] Proper method to initialize all LLVM Internal Data Structures?

Zhang via llvm-dev llvm-dev at lists.llvm.org
Mon Jun 11 21:59:23 PDT 2018


Hi:
I'm building a small tool on top of LLVM Core Library.


```
LLVMContext context;
SMDiagnostic diag;
Module *M = parseIRFile(InputIR, diag, context).get();
  if (M == nullptr) {
    diag.print("LLVM", errs());
    exit(-1);
  }
  assert(M->isMaterialized() && "Module not materialized!");
  PointerType *ArrayPtrTy =
      M->getTypeByName("struct._Array")->getPointerTo();
```


However this piece of code crashes at Module::getTypeByName because getContext().pImpl is NULL pointer. Other similar issues include Module::getTypeByName results in a NULL pointer dereference because TheTable in StringMap is not allocated/initialized.


It would be great if someone could show me what's the correct way to initialize all this kind of internal data structures so I could focus on my tool's logic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180612/8afd272d/attachment.html>


More information about the llvm-dev mailing list