From: Erich Keane Date: Thu, 14 Dec 2017 23:37:08 +0000 (+0000) Subject: Correct UnaryTransformTypeLoc to properly initialize. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d8dad1d7c666548d7c63a3d4baeecd2ad5805d3;p=clang Correct UnaryTransformTypeLoc to properly initialize. The initializeLocal function of UnaryTransformTypeLoc missed the UnderlyingTInfo member. This caused a null-dereference issue, as reported in PR23421. This patch correctly initializss the UnderlyingTInfo. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320765 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h index 6220549295..b805160a27 100644 --- a/include/clang/AST/TypeLoc.h +++ b/include/clang/AST/TypeLoc.h @@ -1961,11 +1961,7 @@ public: setRParenLoc(Range.getEnd()); } - void initializeLocal(ASTContext &Context, SourceLocation Loc) { - setKWLoc(Loc); - setRParenLoc(Loc); - setLParenLoc(Loc); - } + void initializeLocal(ASTContext &Context, SourceLocation Loc); }; class DeducedTypeLoc diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp index 6e18fe25fc..b05c5fc680 100644 --- a/lib/AST/TypeLoc.cpp +++ b/lib/AST/TypeLoc.cpp @@ -444,6 +444,15 @@ void TypeOfTypeLoc::initializeLocal(ASTContext &Context, getUnderlyingType(), Loc); } +void UnaryTransformTypeLoc::initializeLocal(ASTContext &Context, + SourceLocation Loc) { + setKWLoc(Loc); + setRParenLoc(Loc); + setLParenLoc(Loc); + this->setUnderlyingTInfo( + Context.getTrivialTypeSourceInfo(getTypePtr()->getBaseType(), Loc)); +} + void ElaboratedTypeLoc::initializeLocal(ASTContext &Context, SourceLocation Loc) { setElaboratedKeywordLoc(Loc); diff --git a/test/SemaCXX/underlying_type.cpp b/test/SemaCXX/underlying_type.cpp index dd019ae6e2..87f3b92802 100644 --- a/test/SemaCXX/underlying_type.cpp +++ b/test/SemaCXX/underlying_type.cpp @@ -62,3 +62,17 @@ enum E {}; void PR26014() { f(0); } // should not yield an ambiguity error. template void f(__underlying_type(T) v); // expected-error {{declaration type contains unexpanded parameter pack 'T'}} + +namespace PR23421 { +template +using underlying_type_t = __underlying_type(T); +// Should not crash. +template +struct make_unsigned_impl { using type = underlying_type_t; }; +using AnotherType = make_unsigned_impl::type; + +// also should not crash. +template +__underlying_type(T) ft(); +auto x = &ft; +}