[llvm-commits] [llvm-gcc-4.2] r97989 - /llvm-gcc-4.2/trunk/gcc/llvm-types.cpp

Duncan Sands baldrick at free.fr
Tue Mar 9 11:40:17 PST 2010

Hi Dale,

>>>     // If this function returns via a shadow argument, the dest loc is passed
>>> -  // in as a pointer.  Mark that pointer as struct-ret and noalias.
>>> +  // in as a pointer.  Mark that pointer as struct-ret.
>>> +  //
>>> +  // It's tempting to want NoAlias here too, however even though llvm-gcc
>>> +  // itself currently always passes a dedicated alloca as the actual argument,
>>> +  // this isn't mandated by the ABI. There are other compilers which don't
>>> +  // always pass a dedicated alloca. Using NoAlias here would make code which
>>> +  // isn't interoperable with that of other compilers.
>>>     if (ABIConverter.isShadowReturn())
>>>       Attrs.push_back(AttributeWithIndex::get(ArgTys.size(),
>>> -                                    Attribute::StructRet | Attribute::NoAlias));
>>> +                                    Attribute::StructRet));
>> what does the ABI say exactly?  Is it really valid to pass something which may
>> get "accidentally" altered when the callee (for example) writes to a global or
>> to some other argument?
> The ABI does NOT say that the shadow return value must be a  dedicated stack-allocated object, and therefore it doesn't have to be if we see the same result under the as-if rule.  I also have seen other compilers do this (not just clang).  I believe it's safe in some circumstances, but you have to be careful.

if the callee can't tell that it's not being passed a dedicated stack-object,
then noalias should be fine.



More information about the llvm-commits mailing list