Hi everyone, I'm having some problems when loading values. Here's a
simple
example of the IR that my compiler generates to show the problem:
define i32 @main() {
entry:
%a = alloca i32 ; <i32*> [#uses=2]
store i32 1, i32* %a
%r = load i32* %a ; <i32> [#uses=1]
br label %Return
Return: ; preds = %entry
ret i32 %r
}
but instead of return 1 it returns 16777216. I have tested the program with
different values and it seems that it's a matter of internal binary
representation of integer values.
Thanks in advance.
Santos Merino del Pozo.
I show you the trace of calls to llvm that my compiler makes to generate the
code above. bloques.back().last is of type Value* and bloques.back().bl is
BasicBlock* (the current Block)
bloques.back().last =
dyn_cast<Value>(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), $1,
true)); // $1 is an int
AllocaInst *alloc =
new AllocaInst(
Type::getInt32Ty(getGlobalContext()), izq.c_str(),
bloques.back().bl);
Value *derecha = bloques.back().last;
StoreInst *s = new StoreInst(derecha, alloc, false, bloques.back().bl);
bloques.back().last = alloc;
LoadInst* v1 =
new LoadInst(bloques.back().last, "r", false,
bloques.back().bl);
bloques.back().last = v1;
BasicBlock* blockReturn =
BasicBlock::Create(getGlobalContext(), "Return",
Main);
Value* last = bloques.back().last;
BranchInst::Create(blockReturn, bloques.back().bl);
ReturnInst::Create(getGlobalContext(), last, blockReturn);
The source code corresponding to the IR representation would be:
a = 1
return a
How are you checking the return value? I put your code in santos.ll and then executed it with lli, and I get 1 as a return value. lli santos.ll ; echo $? 1 Joey On 27 May 2012 16:59, Santos Merino <santitox at hotmail.es> wrote:> I show you the trace of calls to llvm that my compiler makes to generate > the > code above. bloques.back().last is of type Value* and bloques.back().bl is > BasicBlock* (the current Block) > > bloques.back().last > > dyn_cast<Value>(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), $1, > true)); // $1 is an int > AllocaInst *alloc > new AllocaInst( > Type::getInt32Ty(getGlobalContext()), izq.c_str(), > bloques.back().bl); > Value *derecha = bloques.back().last; > StoreInst *s = new StoreInst(derecha, alloc, false, bloques.back().bl); > bloques.back().last = alloc; > LoadInst* v1 > new LoadInst(bloques.back().last, "r", false, > bloques.back().bl); > bloques.back().last = v1; > BasicBlock* blockReturn > BasicBlock::Create(getGlobalContext(), "Return", Main); > Value* last = bloques.back().last; > BranchInst::Create(blockReturn, bloques.back().bl); > ReturnInst::Create(getGlobalContext(), last, blockReturn); > > The source code corresponding to the IR representation would be: > > a = 1 > return a > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120527/26691d53/attachment.html>