Переглянути джерело

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
Erich Keane 7 роки тому
батько
коміт
2d8dad1d7c
3 змінених файлів з 24 додано та 5 видалено
  1. 1 5
      include/clang/AST/TypeLoc.h
  2. 9 0
      lib/AST/TypeLoc.cpp
  3. 14 0
      test/SemaCXX/underlying_type.cpp

+ 1 - 5
include/clang/AST/TypeLoc.h

@@ -1961,11 +1961,7 @@ public:
     setRParenLoc(Range.getEnd());
     setRParenLoc(Range.getEnd());
   }
   }
 
 
-  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
-    setKWLoc(Loc);
-    setRParenLoc(Loc);
-    setLParenLoc(Loc);
-  }
+  void initializeLocal(ASTContext &Context, SourceLocation Loc);
 };
 };
 
 
 class DeducedTypeLoc
 class DeducedTypeLoc

+ 9 - 0
lib/AST/TypeLoc.cpp

@@ -444,6 +444,15 @@ void TypeOfTypeLoc::initializeLocal(ASTContext &Context,
       getUnderlyingType(), Loc);
       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, 
 void ElaboratedTypeLoc::initializeLocal(ASTContext &Context, 
                                         SourceLocation Loc) {
                                         SourceLocation Loc) {
   setElaboratedKeywordLoc(Loc);
   setElaboratedKeywordLoc(Loc);

+ 14 - 0
test/SemaCXX/underlying_type.cpp

@@ -62,3 +62,17 @@ enum E {};
 void PR26014() { f<E>(0); } // should not yield an ambiguity error.
 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'}}
 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>;
+}