r220060 - Rename TemplateArgument::getTypeForDecl to getParamTypeForDecl for clarity

David Blaikie dblaikie at gmail.com
Mon Oct 20 10:41:17 PDT 2014


Thanks! investigating.

On Mon, Oct 20, 2014 at 10:37 AM, David Majnemer <david.majnemer at gmail.com>
wrote:

> I've reproduced it independently:
> template <int (*)()> void g() {}
> struct S {
>   static int f();
> };
> auto x = g<S::f>;
>
> On Mon, Oct 20, 2014 at 10:31 AM, David Blaikie <dblaikie at gmail.com>
> wrote:
>
>>
>>
>> On Mon, Oct 20, 2014 at 10:28 AM, Yaron Keren <yaron.keren at gmail.com>
>> wrote:
>>
>>> Here is the failing code, an example from boost::multiprecision. The
>>> boost version is 1.56 (the latest). Compiled with -c -g, nothing special.
>>> Maybe you'd like to add this as a test? boost::multiprecision is very
>>> demanding code.
>>>
>>
>> It'd be helpful if you could provide the preprocessed source (or the
>> include-processed source) - the Clang crash handler should've mentioned two
>> files (foo-42.sh and foo-42.cpp) that make it easy to reproduce crashers
>> without the need to install external dependencies, etc.
>>
>> - David
>>
>>
>>>
>>> Yaron
>>>
>>>
>>> 2014-10-20 19:59 GMT+03:00 David Blaikie <dblaikie at gmail.com>:
>>>
>>>>
>>>>
>>>> On Mon, Oct 20, 2014 at 9:32 AM, Yaron Keren <yaron.keren at gmail.com>
>>>> wrote:
>>>>
>>>>> Hi David,
>>>>>
>>>>> Beyond renaming getTypeForDecl(), this revision also introduced
>>>>> functionality changes in CGDebugInfo.cpp,
>>>>>
>>>>
>>>> Yep, sorry - I could've separated those patches.
>>>>
>>>>
>>>>> specifically the
>>>>>
>>>>>   if (InstanceMember) {
>>>>>
>>>>> test was removed, leading to
>>>>>
>>>>>   http://llvm.org/bugs/show_bug.cgi?id=21312
>>>>>
>>>>> Was the condition removed by mistake?
>>>>>
>>>>
>>>> Not exactly - I intentionally removed it, but of course causing bugs
>>>> was a mistake.
>>>>
>>>> Do you have a (preferably minimized) reproduction of this crash?
>>>>
>>>>
>>>>>
>>>>> Yaron
>>>>>
>>>>>
>>>>>
>>>>> 2014-10-17 21:00 GMT+03:00 David Blaikie <dblaikie at gmail.com>:
>>>>>
>>>>>> Author: dblaikie
>>>>>> Date: Fri Oct 17 13:00:12 2014
>>>>>> New Revision: 220060
>>>>>>
>>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=220060&view=rev
>>>>>> Log:
>>>>>> Rename TemplateArgument::getTypeForDecl to getParamTypeForDecl for
>>>>>> clarity
>>>>>>
>>>>>> Code review feedback from Richard Smith on r219900.
>>>>>>
>>>>>> Modified:
>>>>>>     cfe/trunk/include/clang/AST/TemplateBase.h
>>>>>>     cfe/trunk/lib/AST/ASTContext.cpp
>>>>>>     cfe/trunk/lib/AST/ASTImporter.cpp
>>>>>>     cfe/trunk/lib/AST/ItaniumMangle.cpp
>>>>>>     cfe/trunk/lib/AST/MicrosoftMangle.cpp
>>>>>>     cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>>>>>>     cfe/trunk/lib/Serialization/ASTWriter.cpp
>>>>>>
>>>>>> Modified: cfe/trunk/include/clang/AST/TemplateBase.h
>>>>>> URL:
>>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TemplateBase.h?rev=220060&r1=220059&r2=220060&view=diff
>>>>>>
>>>>>> ==============================================================================
>>>>>> --- cfe/trunk/include/clang/AST/TemplateBase.h (original)
>>>>>> +++ cfe/trunk/include/clang/AST/TemplateBase.h Fri Oct 17 13:00:12
>>>>>> 2014
>>>>>> @@ -249,7 +249,7 @@ public:
>>>>>>      return DeclArg.D;
>>>>>>    }
>>>>>>
>>>>>> -  QualType getTypeForDecl() const {
>>>>>> +  QualType getParamTypeForDecl() const {
>>>>>>      assert(getKind() == Declaration && "Unexpected kind");
>>>>>>      return QualType::getFromOpaquePtr(DeclArg.QT);
>>>>>>    }
>>>>>>
>>>>>> Modified: cfe/trunk/lib/AST/ASTContext.cpp
>>>>>> URL:
>>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=220060&r1=220059&r2=220060&view=diff
>>>>>>
>>>>>> ==============================================================================
>>>>>> --- cfe/trunk/lib/AST/ASTContext.cpp (original)
>>>>>> +++ cfe/trunk/lib/AST/ASTContext.cpp Fri Oct 17 13:00:12 2014
>>>>>> @@ -4099,7 +4099,7 @@ ASTContext::getCanonicalTemplateArgument
>>>>>>
>>>>>>      case TemplateArgument::Declaration: {
>>>>>>        ValueDecl *D =
>>>>>> cast<ValueDecl>(Arg.getAsDecl()->getCanonicalDecl());
>>>>>> -      return TemplateArgument(D, Arg.getTypeForDecl());
>>>>>> +      return TemplateArgument(D, Arg.getParamTypeForDecl());
>>>>>>      }
>>>>>>
>>>>>>      case TemplateArgument::NullPtr:
>>>>>>
>>>>>> Modified: cfe/trunk/lib/AST/ASTImporter.cpp
>>>>>> URL:
>>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=220060&r1=220059&r2=220060&view=diff
>>>>>>
>>>>>> ==============================================================================
>>>>>> --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
>>>>>> +++ cfe/trunk/lib/AST/ASTImporter.cpp Fri Oct 17 13:00:12 2014
>>>>>> @@ -2094,7 +2094,7 @@ ASTNodeImporter::ImportTemplateArgument(
>>>>>>    case TemplateArgument::Declaration: {
>>>>>>      ValueDecl *FromD = From.getAsDecl();
>>>>>>      if (ValueDecl *To =
>>>>>> cast_or_null<ValueDecl>(Importer.Import(FromD)))
>>>>>> -      return TemplateArgument(To, From.getTypeForDecl());
>>>>>> +      return TemplateArgument(To, From.getParamTypeForDecl());
>>>>>>      return TemplateArgument();
>>>>>>    }
>>>>>>
>>>>>>
>>>>>> Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
>>>>>> URL:
>>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=220060&r1=220059&r2=220060&view=diff
>>>>>>
>>>>>> ==============================================================================
>>>>>> --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
>>>>>> +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Oct 17 13:00:12 2014
>>>>>> @@ -3403,7 +3403,7 @@ void CXXNameMangler::mangleTemplateArg(T
>>>>>>      // and pointer-to-function expressions are represented as a
>>>>>> declaration not
>>>>>>      // an expression. We compensate for it here to produce the
>>>>>> correct mangling.
>>>>>>      ValueDecl *D = A.getAsDecl();
>>>>>> -    bool compensateMangling = !A.getTypeForDecl()->isReferenceType();
>>>>>> +    bool compensateMangling =
>>>>>> !A.getParamTypeForDecl()->isReferenceType();
>>>>>>      if (compensateMangling) {
>>>>>>        Out << 'X';
>>>>>>        mangleOperatorName(OO_Amp, 1);
>>>>>>
>>>>>> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
>>>>>> URL:
>>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=220060&r1=220059&r2=220060&view=diff
>>>>>>
>>>>>> ==============================================================================
>>>>>> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
>>>>>> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Oct 17 13:00:12 2014
>>>>>> @@ -1139,7 +1139,7 @@ void MicrosoftCXXNameMangler::mangleTemp
>>>>>>        else
>>>>>>          mangle(FD, "$1?");
>>>>>>      } else {
>>>>>> -      mangle(ND, TA.getTypeForDecl()->isReferenceType() ? "$E?" :
>>>>>> "$1?");
>>>>>> +      mangle(ND, TA.getParamTypeForDecl()->isReferenceType() ? "$E?"
>>>>>> : "$1?");
>>>>>>      }
>>>>>>      break;
>>>>>>    }
>>>>>>
>>>>>> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>>>>>> URL:
>>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=220060&r1=220059&r2=220060&view=diff
>>>>>>
>>>>>> ==============================================================================
>>>>>> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
>>>>>> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Oct 17 13:00:12 2014
>>>>>> @@ -1255,32 +1255,29 @@ CollectTemplateParams(const TemplatePara
>>>>>>      } break;
>>>>>>      case TemplateArgument::Declaration: {
>>>>>>        const ValueDecl *D = TA.getAsDecl();
>>>>>> -      bool InstanceMember = D->isCXXInstanceMember();
>>>>>> -      QualType T = TA.getTypeForDecl();
>>>>>> +      QualType T = TA.getParamTypeForDecl();
>>>>>>        llvm::DIType TTy = getOrCreateType(T, Unit);
>>>>>>        llvm::Value *V = nullptr;
>>>>>>        // Variable pointer template parameters have a value that is
>>>>>> the address
>>>>>>        // of the variable.
>>>>>> -      if (const VarDecl *VD = dyn_cast<VarDecl>(D))
>>>>>> +      if (const auto *VD = dyn_cast<VarDecl>(D))
>>>>>>          V = CGM.GetAddrOfGlobalVar(VD);
>>>>>>        // Member function pointers have special support for building
>>>>>> them, though
>>>>>>        // this is currently unsupported in LLVM CodeGen.
>>>>>> -      if (InstanceMember) {
>>>>>> -        if (const CXXMethodDecl *method = dyn_cast<CXXMethodDecl>(D))
>>>>>> +      else if (const auto *method = dyn_cast<CXXMethodDecl>(D))
>>>>>>            V = CGM.getCXXABI().EmitMemberPointer(method);
>>>>>> -      } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
>>>>>> +      else if (const auto *FD = dyn_cast<FunctionDecl>(D))
>>>>>>          V = CGM.GetAddrOfFunction(FD);
>>>>>>        // Member data pointers have special handling too to compute
>>>>>> the fixed
>>>>>>        // offset within the object.
>>>>>> -      if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) {
>>>>>> +      else if (const auto *MPT =
>>>>>> dyn_cast<MemberPointerType>(T.getTypePtr())) {
>>>>>>          // These five lines (& possibly the above member function
>>>>>> pointer
>>>>>>          // handling) might be able to be refactored to use similar
>>>>>> code in
>>>>>>          // CodeGenModule::getMemberPointerConstant
>>>>>>          uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
>>>>>>          CharUnits chars =
>>>>>>              CGM.getContext().toCharUnitsFromBits((int64_t)
>>>>>> fieldOffset);
>>>>>> -        V = CGM.getCXXABI().EmitMemberDataPointer(
>>>>>> -            cast<MemberPointerType>(T.getTypePtr()), chars);
>>>>>> +        V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
>>>>>>        }
>>>>>>        llvm::DITemplateValueParameter TVP =
>>>>>>            DBuilder.createTemplateValueParameter(TheCU, Name, TTy,
>>>>>>
>>>>>> Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
>>>>>> URL:
>>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=220060&r1=220059&r2=220060&view=diff
>>>>>>
>>>>>> ==============================================================================
>>>>>> --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
>>>>>> +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Oct 17 13:00:12 2014
>>>>>> @@ -5372,7 +5372,7 @@ void ASTWriter::AddTemplateArgument(cons
>>>>>>      break;
>>>>>>    case TemplateArgument::Declaration:
>>>>>>      AddDeclRef(Arg.getAsDecl(), Record);
>>>>>> -    AddTypeRef(Arg.getTypeForDecl(), Record);
>>>>>> +    AddTypeRef(Arg.getParamTypeForDecl(), Record);
>>>>>>      break;
>>>>>>    case TemplateArgument::NullPtr:
>>>>>>      AddTypeRef(Arg.getNullPtrType(), Record);
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> cfe-commits mailing list
>>>>>> cfe-commits at cs.uiuc.edu
>>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>>>>
>>>>>
>>>>>
>>>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141020/96d7a8f0/attachment.html>


More information about the cfe-commits mailing list