[LLVMdev] BasicAliasAnalysis: Null pointers do not alias with anything

Nick Lewycky nicholas at mxc.ca
Thu Nov 5 00:34:59 PST 2009


Dan Gohman wrote:
> Hello,
> 
> On Nov 4, 2009, at 1:51 AM, Hans Wennborg wrote:
>>
>> / Hans
>> Index: lib/Analysis/BasicAliasAnalysis.cpp
>> ===================================================================
>> --- lib/Analysis/BasicAliasAnalysis.cpp	(revision 86023)
>> +++ lib/Analysis/BasicAliasAnalysis.cpp	(working copy)
>> @@ -633,6 +633,15 @@
>> AliasAnalysis::AliasResult
>> BasicAliasAnalysis::aliasCheck(const Value *V1, unsigned V1Size,
>>                                const Value *V2, unsigned V2Size) {
>> +  // Null pointers do not alias with anything
>> +  if (const Constant *C = dyn_cast<Constant>(V1))
>> +    if (C->isNullValue())
>> +      return NoAlias;
>> +
>> +  if (const Constant *C = dyn_cast<Constant>(V2))
>> +    if (C->isNullValue())
>> +      return NoAlias;
>> +
> 
> As Chris mentioned, for consistency with what the rest of LLVM is doing,
> this should check whether the pointers are in the default address space
> (0).
> 
> Also, this could be generalized by checking the results from 
> getUnderlyingObject, since it's not valid to do arithmetic from null to
> reach an LLVM identified object either.

Also, you can just test for "isa<ConstantPointerNull>(V1)" directly 
instead of casting to Constant then asking isNullValue (assuming the 
types of V1 and V2 are going to be PointerTy which I believe they always 
will be, without looking at the code).

Nick



More information about the llvm-dev mailing list