]> granicus.if.org Git - clang/commitdiff
Make sure that Type::getAs<ArrayType>() (or Type::getAs<subclass of
authorDouglas Gregor <dgregor@apple.com>
Mon, 9 Nov 2009 22:08:55 +0000 (22:08 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 9 Nov 2009 22:08:55 +0000 (22:08 +0000)
ArrayType>()) does not instantiate. Update all callers that used this
unsafe feature to use the appropriate ASTContext::getAs*ArrayType method.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86596 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Type.h
lib/Analysis/RegionStore.cpp
lib/Analysis/VLASizeChecker.cpp
lib/CodeGen/CGDecl.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaOverload.cpp
lib/Sema/SemaType.cpp

index e53b9787affc3c73d014013b9430cc3eaa66e663..8727650031950704f584ec76d9b20363969d3244 100644 (file)
@@ -2927,8 +2927,21 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
   return DB;
 }
 
+// Helper class template that is used by Type::getAs to ensure that one does
+// not try to look through a qualified type to get to an array type.
+template<typename T,
+         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
+                             llvm::is_base_of<ArrayType, T>::value)>
+struct ArrayType_cannot_be_used_with_getAs { };
+  
+template<typename T>
+struct ArrayType_cannot_be_used_with_getAs<T, true>;
+  
 /// Member-template getAs<specific type>'.
 template <typename T> const T *Type::getAs() const {
+  ArrayType_cannot_be_used_with_getAs<T> at;
+  (void)at;
+  
   // If this is directly a T type, return it.
   if (const T *Ty = dyn_cast<T>(this))
     return Ty;
index dbf8c42d273e9d3bde89b3328a68a60f734e76ce..45c42281ab2c1582872a5a7df793ba38ed69e42e 100644 (file)
@@ -1109,7 +1109,7 @@ SVal RegionStoreManager::RetrieveElement(const GRState* state,
     // FIXME: Handle loads from strings where the literal is treated as 
     // an integer, e.g., *((unsigned int*)"hello")
     ASTContext &Ctx = getContext();
-    QualType T = StrR->getValueType(Ctx)->getAs<ArrayType>()->getElementType();
+    QualType T = Ctx.getAsArrayType(StrR->getValueType(Ctx))->getElementType();
     if (T != Ctx.getCanonicalType(R->getElementType()))
       return UnknownVal();
     
index 98b755be53d8f53502d559115a68385f4b8be8c1..5cb700ed67b58a4739f5aa2719156ad4d4d0da29 100644 (file)
@@ -43,7 +43,8 @@ void VLASizeChecker::PreVisitDeclStmt(CheckerContext &C, const DeclStmt *DS) {
   if (!VD)
     return;
   
-  const VariableArrayType *VLA = VD->getType()->getAs<VariableArrayType>();
+  const VariableArrayType *VLA
+    = C.getASTContext().getAsVariableArrayType(VD->getType());
   if (!VLA)
     return;
 
index 2021ced31683cfb00ff10450138c55d5ee970297..2a28ef08a08ceaa16b92060971bf784f5b37a515 100644 (file)
@@ -507,7 +507,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
 
   // Handle CXX destruction of variables.
   QualType DtorTy(Ty);
-  if (const ArrayType *Array = DtorTy->getAs<ArrayType>())
+  while (const ArrayType *Array = getContext().getAsArrayType(DtorTy))
     DtorTy = getContext().getBaseElementType(Array);
   if (const RecordType *RT = DtorTy->getAs<RecordType>())
     if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
index cfea66bf5af4a7ff46fafb53639d75d4d103ff05..8bd934a561f6a41a59d83e589c0105bd71d86207 100644 (file)
@@ -3596,7 +3596,7 @@ Sema::DeclGroupPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
         // template <typename... Args> void f(Args... args) {
         //   int vals[] = { args };
         // }
-        const IncompleteArrayType *IAT = T->getAs<IncompleteArrayType>();
+        const IncompleteArrayType *IAT = Context.getAsIncompleteArrayType(T);
         Expr *Init = IDecl->getInit();
         if (IAT && Init &&
             (Init->isTypeDependent() || Init->isValueDependent())) {
index 69dac7d33e06c8a6ff715b3a7880a978bc485401..69e5a52307060bddb30f6c5799febbc699d3de2f 100644 (file)
@@ -2982,7 +2982,7 @@ BuiltinCandidateTypeSet::AddPointerWithMoreQualifiedTypeVariants(QualType Ty,
 
   QualType PointeeTy = PointerTy->getPointeeType();
   unsigned BaseCVR = PointeeTy.getCVRQualifiers();
-  if (const ConstantArrayType *Array = PointeeTy->getAs<ConstantArrayType>())
+  if (const ConstantArrayType *Array =Context.getAsConstantArrayType(PointeeTy))
     BaseCVR = Array->getElementType().getCVRQualifiers();
   bool hasVolatile = VisibleQuals.hasVolatile();
   bool hasRestrict = VisibleQuals.hasRestrict();
index 93ef1ea2ead5bde23600cc1729a5c4ce84161345..00dc809f51a822c641cca2b3fcc3519286a30788 100644 (file)
@@ -1704,7 +1704,7 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
   // class template specialization, or an array with known size of such,
   // try to instantiate it.
   QualType MaybeTemplate = T;
-  if (const ConstantArrayType *Array = T->getAs<ConstantArrayType>())
+  if (const ConstantArrayType *Array = Context.getAsConstantArrayType(T))
     MaybeTemplate = Array->getElementType();
   if (const RecordType *Record = MaybeTemplate->getAs<RecordType>()) {
     if (ClassTemplateSpecializationDecl *ClassTemplateSpec