]> granicus.if.org Git - clang/commitdiff
Correct UnaryTransformTypeLoc to properly initialize.
authorErich Keane <erich.keane@intel.com>
Thu, 14 Dec 2017 23:37:08 +0000 (23:37 +0000)
committerErich Keane <erich.keane@intel.com>
Thu, 14 Dec 2017 23:37:08 +0000 (23:37 +0000)
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

include/clang/AST/TypeLoc.h
lib/AST/TypeLoc.cpp
test/SemaCXX/underlying_type.cpp

index 622054929523cf6cb234f2a2e73efddb6771793c..b805160a278071b20297f9eb333b95cc3478d801 100644 (file)
@@ -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
index 6e18fe25fcb502ecadf230b364e2bcef528e1af2..b05c5fc68096243406a03af75fab6e62e60ea390 100644 (file)
@@ -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);
index dd019ae6e277506d9757e741df33cbce17cf20bc..87f3b92802ad312b74470fc10a7541b1fc5a1644 100644 (file)
@@ -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>;
+}