Skip to content

Chapter03 code doesn't build #15

@sudarshanchoubey

Description

@sudarshanchoubey

/home/source/Learn-LLVM-12/Chapter03/calc/src/CodeGen.cpp: In member function ‘virtual void {anonymous}::ToIRVisitor::visit(WithDecl&)’:
/home/source/Learn-LLVM-12/Chapter03/calc/src/CodeGen.cpp:101:11: error: cannot convert ‘llvm::GlobalVariable*’ to ‘llvm::Type*’
101 | Str, {Int32Zero, Int32Zero}, "ptr");
| ^~~
| |
| llvm::GlobalVariable*
In file included from /home/source/Learn-LLVM-12/Chapter03/calc/src/CodeGen.cpp:3:
/usr/local/include/llvm/IR/IRBuilder.h:1775:34: note: initializing argument 1 of ‘llvm::Value* llvm::IRBuilderBase::CreateInBoundsGEP(llvm::Type*, llvm::Value*, llvm::ArrayRefllvm::Value*, const llvm::Twine&)’
1775 | Value *CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
| ~~~~~~^~
make[2]: *** [src/CMakeFiles/calc.dir/build.make:90: src/CMakeFiles/calc.dir/CodeGen.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:179: src/CMakeFiles/calc.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Changing the same lines to
Value *Ptr = Builder.CreateInBoundsGEP((llvm::Type *)Str, Int32Zero, Int32Zero, "ptr");
leads to a successful build.
Could you provide a better solution, the casting I have added may not be the best way to write this code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions