Displaying 3 results from an estimated 3 matches for "constantfoldcastinstruct".
2015 Jun 09
2
[LLVMdev] Constant folding inttoptr i32 0 to null pointer?
Hello,
It seems that ConstantFoldCastInstruction in ConstantFold.cpp folds inttoptr instruction with 0 as operand to a null pointer. It makes sense, when talking about a C-style frontend, as the C99 spec (6.3.2.3) states:
"An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer...
2015 Jun 09
2
[LLVMdev] Constant folding inttoptr i32 0 to null pointer?
...>>
>> ret i32 %std_ld.i
>>
>> }
>>
>>
>>
>> The contant folder doesn’t seem to check for address space, it simply
>> checks if the integer in question is zero, and folds the inttoptr to null:
>>
>>
>>
>> Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
>>
>> Type *DestTy) {
>>
>>
>>
>> ...
>>
>>
>>
>> if (V->isNullValue() && !DestTy->isX86_MMXTy())
>>
>> return Constant::getNullValue...
2015 Jun 09
4
[LLVMdev] Constant folding inttoptr i32 0 to null pointer?
...on (early CSE):
define i32 @foo() #0 {
entry:
%std_ld.i = load volatile i32 addrspace(1)* null, align 536870912
ret i32 %std_ld.i
}
The contant folder doesn’t seem to check for address space, it simply checks if the integer in question is zero, and folds the inttoptr to null:
Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
Type *DestTy) {
...
if (V->isNullValue() && !DestTy->isX86_MMXTy())
return Constant::getNullValue(DestTy);
...
Is this a bug?
Thanks
Guy
From: David Majnemer [mailto:david.majnemer at gmail.co...