[cfe-commits] r86596 - in /cfe/trunk: 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
Douglas Gregor
dgregor at apple.com
Mon Nov 9 14:08:55 PST 2009
Author: dgregor
Date: Mon Nov 9 16:08:55 2009
New Revision: 86596
URL: http://llvm.org/viewvc/llvm-project?rev=86596&view=rev
Log:
Make sure that Type::getAs<ArrayType>() (or Type::getAs<subclass of
ArrayType>()) does not instantiate. Update all callers that used this
unsafe feature to use the appropriate ASTContext::getAs*ArrayType method.
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/Analysis/RegionStore.cpp
cfe/trunk/lib/Analysis/VLASizeChecker.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=86596&r1=86595&r2=86596&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Nov 9 16:08:55 2009
@@ -2927,8 +2927,21 @@
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;
Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=86596&r1=86595&r2=86596&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Mon Nov 9 16:08:55 2009
@@ -1109,7 +1109,7 @@
// 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();
Modified: cfe/trunk/lib/Analysis/VLASizeChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/VLASizeChecker.cpp?rev=86596&r1=86595&r2=86596&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/VLASizeChecker.cpp (original)
+++ cfe/trunk/lib/Analysis/VLASizeChecker.cpp Mon Nov 9 16:08:55 2009
@@ -43,7 +43,8 @@
if (!VD)
return;
- const VariableArrayType *VLA = VD->getType()->getAs<VariableArrayType>();
+ const VariableArrayType *VLA
+ = C.getASTContext().getAsVariableArrayType(VD->getType());
if (!VLA)
return;
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=86596&r1=86595&r2=86596&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon Nov 9 16:08:55 2009
@@ -507,7 +507,7 @@
// 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())) {
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=86596&r1=86595&r2=86596&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Nov 9 16:08:55 2009
@@ -3596,7 +3596,7 @@
// 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())) {
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=86596&r1=86595&r2=86596&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon Nov 9 16:08:55 2009
@@ -2982,7 +2982,7 @@
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();
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=86596&r1=86595&r2=86596&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Nov 9 16:08:55 2009
@@ -1704,7 +1704,7 @@
// 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
More information about the cfe-commits
mailing list