r305110 - [ODRHash] Add support for TemplateArgument types.

Richard Trieu via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 8 12:14:42 PST 2017


Vassil,

It depends on which parts of the AST you want to be stable.  The ODRHashing
is stable across TU's, but it may depend on information that you don't want
to be part of the hash.  For instance, if you have "using F = float;" in
you code, then the hash of TemplateArgument for "float" and for "F" would
be different.  If the template specializations you are dealing with are
canonicalized, then the TemplateArgument hashes should be the same.
Otherwise, ODRHash would need to be changed to suit your requirements.

On Fri, Dec 8, 2017 at 8:16 AM, Vassil Vassilev <v.g.vassilev at gmail.com>
wrote:

> Hi Richard,
>
>   Is there a way to get an ODRHashing which is stable across translation
> units? I'd like to use the TemplateArgument ODRHash to lookup template
> specializations and deserialize them only if they are required.
>
> Many thanks!
> Vassil
>
> On 6/9/17 11:00 PM, Richard Trieu via cfe-commits wrote:
>
>> Author: rtrieu
>> Date: Fri Jun  9 16:00:10 2017
>> New Revision: 305110
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=305110&view=rev
>> Log:
>> [ODRHash] Add support for TemplateArgument types.
>>
>> Recommit r304592 that was reverted in r304618.  r305104 should have fixed
>> the
>> issue.
>>
>> Modified:
>>      cfe/trunk/lib/AST/ODRHash.cpp
>>      cfe/trunk/test/Modules/odr_hash.cpp
>>
>> Modified: cfe/trunk/lib/AST/ODRHash.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHas
>> h.cpp?rev=305110&r1=305109&r2=305110&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/lib/AST/ODRHash.cpp (original)
>> +++ cfe/trunk/lib/AST/ODRHash.cpp Fri Jun  9 16:00:10 2017
>> @@ -140,7 +140,25 @@ void ODRHash::AddTemplateName(TemplateNa
>>     }
>>   }
>>   -void ODRHash::AddTemplateArgument(TemplateArgument TA) {}
>> +void ODRHash::AddTemplateArgument(TemplateArgument TA) {
>> +  auto Kind = TA.getKind();
>> +  ID.AddInteger(Kind);
>> +
>> +  switch (Kind) {
>> +  case TemplateArgument::Null:
>> +  case TemplateArgument::Declaration:
>> +  case TemplateArgument::NullPtr:
>> +  case TemplateArgument::Integral:
>> +  case TemplateArgument::Template:
>> +  case TemplateArgument::TemplateExpansion:
>> +  case TemplateArgument::Expression:
>> +  case TemplateArgument::Pack:
>> +    break;
>> +  case TemplateArgument::Type:
>> +    AddQualType(TA.getAsType());
>> +    break;
>> +  }
>> +}
>>   void ODRHash::AddTemplateParameterList(const TemplateParameterList
>> *TPL) {}
>>     void ODRHash::clear() {
>>
>> Modified: cfe/trunk/test/Modules/odr_hash.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/
>> odr_hash.cpp?rev=305110&r1=305109&r2=305110&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/test/Modules/odr_hash.cpp (original)
>> +++ cfe/trunk/test/Modules/odr_hash.cpp Fri Jun  9 16:00:10 2017
>> @@ -900,6 +900,24 @@ S2 s2;
>>   #endif
>>   }
>>   +namespace TemplateArgument {
>> +#if defined(FIRST)
>> +template<typename> struct U1 {};
>> +struct S1 {
>> +  U1<int> u;
>> +};
>> +#elif defined(SECOND)
>> +template<typename> struct U1 {};
>> +struct S1 {
>> +  U1<double> u;
>> +};
>> +#else
>> +S1 s1;
>> +// expected-error at first.h:* {{'TemplateArgument::S1::u' from module
>> 'FirstModule' is not present in definition of 'TemplateArgument::S1' in
>> module 'SecondModule'}}
>> +// expected-note at second.h:* {{declaration of 'u' does not match}}
>> +#endif
>> +}
>> +
>>   // Interesting cases that should not cause errors.  struct S should not
>> error
>>   // while struct T should error at the access specifier mismatch at the
>> end.
>>   namespace AllDecls {
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171208/e8ad47ce/attachment.html>


More information about the cfe-commits mailing list