[llvm-commits] [llvm] r117070 - /llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp
John McCall
rjmccall at apple.com
Sat Oct 23 14:20:33 PDT 2010
On Oct 23, 2010, at 5:09 AM, Duncan Sands wrote:
> Hi John,
>
>>>> // If the third field is present, it's an integer which if equal to 1
>>>> -// indicates that the type is "constant" (meaning
>>>> -// pointsToConstantMemory should return true; see
>>>> +// indicates that the type is "constant" (meaning pointsToConstantMemory
>>>> +// should return true; see
>>>> // http://llvm.org/docs/AliasAnalysis.html#OtherItfs).
>>>
>>> is this "constant" field actually useful? How are you imagining that it will
>>> be used? Even in Ada, which has a pretty strong type system and notions of
>>> constantness, the fact that you have a view of an object via a constant type
>>> doesn't mean that the object can't be altered, it just means it can't be
>>> altered via this view. In C, this is something like saying: suppose the
>>> address of an int is held in a "const int*", then you can't alter the int via
>>> this pointer; but you can always alter it by putting the address of the int in
>>> a "int *" and using that instead. So the fact that you have a "const int*"
>>> doesn't mean you that it is valid for pointsToConstantMemory to return true.
>>
>> Both C and C++ say that modifying an object defined with a const qualifier
>> has undefined results, so while you can't use this for pointer-to-const, you
>> could use it for const variables after they've been initialized.
>
> in the case of a cont variable, is the constness part of the type?
Yes; I was talking about things like 'const A a = foo();' where we can't just constant-propagate values from 'a' (because they're not actually constants) and we can't necessarily mem2reg/SROA them (because the address might be taken) but we can say that they're unchanging for all loads (of non-'mutable' fields) after initialization. But Dan's argument — that TBAA is going to use this bit to feed an AA result saying that the pointer is globally constant — indicates that this won't work.
John.
More information about the llvm-commits
mailing list