Fix use of deprecated IRBuilder::CreateLoad in Kaleidoscope

This commit is contained in:
David Blaikie 2021-03-11 15:42:54 -08:00
parent 0fd0fb5329
commit 48578ec2c4
1 changed files with 5 additions and 4 deletions

View File

@ -745,12 +745,12 @@ Value *NumberExprAST::codegen() {
Value *VariableExprAST::codegen() { Value *VariableExprAST::codegen() {
// Look this variable up in the function. // Look this variable up in the function.
Value *V = NamedValues[Name]; AllocaInst *A = NamedValues[Name];
if (!V) if (!A)
return LogErrorV("Unknown variable name"); return LogErrorV("Unknown variable name");
// Load the value. // Load the value.
return Builder->CreateLoad(V, Name.c_str()); return Builder->CreateLoad(A->getAllocatedType(), A, Name.c_str());
} }
Value *UnaryExprAST::codegen() { Value *UnaryExprAST::codegen() {
@ -962,7 +962,8 @@ Value *ForExprAST::codegen() {
// Reload, increment, and restore the alloca. This handles the case where // Reload, increment, and restore the alloca. This handles the case where
// the body of the loop mutates the variable. // the body of the loop mutates the variable.
Value *CurVar = Builder->CreateLoad(Alloca, VarName.c_str()); Value *CurVar =
Builder->CreateLoad(Alloca->getAllocatedType(), Alloca, VarName.c_str());
Value *NextVar = Builder->CreateFAdd(CurVar, StepVal, "nextvar"); Value *NextVar = Builder->CreateFAdd(CurVar, StepVal, "nextvar");
Builder->CreateStore(NextVar, Alloca); Builder->CreateStore(NextVar, Alloca);