r320765 - Correct UnaryTransformTypeLoc to properly initialize.
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 14 15:37:09 PST 2017
Author: erichkeane
Date: Thu Dec 14 15:37:08 2017
New Revision: 320765
URL: http://llvm.org/viewvc/llvm-project?rev=320765&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/test/SemaCXX/underlying_type.cpp
Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=320765&r1=320764&r2=320765&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Thu Dec 14 15:37:08 2017
@@ -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
Modified: cfe/trunk/lib/AST/TypeLoc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypeLoc.cpp?rev=320765&r1=320764&r2=320765&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypeLoc.cpp (original)
+++ cfe/trunk/lib/AST/TypeLoc.cpp Thu Dec 14 15:37:08 2017
@@ -444,6 +444,15 @@ void TypeOfTypeLoc::initializeLocal(ASTC
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);
Modified: cfe/trunk/test/SemaCXX/underlying_type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/underlying_type.cpp?rev=320765&r1=320764&r2=320765&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/underlying_type.cpp (original)
+++ cfe/trunk/test/SemaCXX/underlying_type.cpp Thu Dec 14 15:37:08 2017
@@ -62,3 +62,17 @@ enum E {};
void PR26014() { f<E>(0); } // should not yield an ambiguity error.
template<typename ...T> void f(__underlying_type(T) v); // expected-error {{declaration type contains unexpanded parameter pack 'T'}}
+
+namespace PR23421 {
+template <class T>
+using underlying_type_t = __underlying_type(T);
+// Should not crash.
+template <class T>
+struct make_unsigned_impl { using type = underlying_type_t<T>; };
+using AnotherType = make_unsigned_impl<E>::type;
+
+// also should not crash.
+template <typename T>
+__underlying_type(T) ft();
+auto x = &ft<E>;
+}
More information about the cfe-commits
mailing list