summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2015-01-04 05:29:21 +0000
committerNico Weber <nicolasweber@gmx.de>2015-01-04 05:29:21 +0000
commit227822e11684462f1730a972398bd1a66613a5de (patch)
tree00660633e1f4ebf9c027fec7b756822ba72ffadb /clang
parent3632e034ba9dbe8f1fb41fb84c7b6588c2ea5e4f (diff)
downloadbcm5719-llvm-227822e11684462f1730a972398bd1a66613a5de.tar.gz
bcm5719-llvm-227822e11684462f1730a972398bd1a66613a5de.zip
Document that GetTypeForDeclarator() cannot return a null type.
Also add a few asserts for this. The existing code assumes this in a bunch of places already (see e.g. the assert at the top of ParseTypedefDecl(), and there are many unchecked calls on the result of GetTypeForDeclarator()), and from looking through the code this should always be true from what I can tell. This allows removing ASTContext::getNullTypeSourceInfo() too as that's now unused. No behavior change intended. llvm-svn: 225125
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/ASTContext.h4
-rw-r--r--clang/lib/AST/ASTContext.cpp2
-rw-r--r--clang/lib/Sema/SemaType.cpp25
3 files changed, 13 insertions, 18 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index ef87fa6dd90..195d748b5be 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -273,8 +273,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// \brief Declaration for the CUDA cudaConfigureCall function.
FunctionDecl *cudaConfigureCallDecl;
- TypeSourceInfo NullTypeSourceInfo;
-
/// \brief Keeps track of all declaration attributes.
///
/// Since so few decls have attrs, we keep them in a hash map instead of
@@ -2173,8 +2171,6 @@ public:
getTrivialTypeSourceInfo(QualType T,
SourceLocation Loc = SourceLocation()) const;
- TypeSourceInfo *getNullTypeSourceInfo() { return &NullTypeSourceInfo; }
-
/// \brief Add a deallocation callback that will be invoked when the
/// ASTContext is destroyed.
///
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a0b80174882..6b864d0f0ac 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -737,7 +737,7 @@ ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM,
FILEDecl(nullptr), jmp_bufDecl(nullptr), sigjmp_bufDecl(nullptr),
ucontext_tDecl(nullptr), BlockDescriptorType(nullptr),
BlockDescriptorExtendedType(nullptr), cudaConfigureCallDecl(nullptr),
- NullTypeSourceInfo(QualType()), FirstLocalImport(), LastLocalImport(),
+ FirstLocalImport(), LastLocalImport(),
SourceMgr(SM), LangOpts(LOpts),
SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFile, SM)),
AddrSpaceMap(nullptr), Target(nullptr), PrintingPolicy(LOpts),
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 95c3698bf1e..6d2fb20efa3 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1176,6 +1176,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
Result = Qualified;
}
+ assert(!Result.isNull() && "This function should not return a null type");
return Result;
}
@@ -2340,6 +2341,7 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
}
}
+ assert(!T.isNull() && "This function should not return a null type");
return T;
}
@@ -2489,7 +2491,8 @@ getCCForDeclaratorChunk(Sema &S, Declarator &D,
static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
QualType declSpecType,
TypeSourceInfo *TInfo) {
-
+ // The TypeSourceInfo that this function returns will not be a null type.
+ // If there is an error, this function will fill in a dummy type as fallback.
QualType T = declSpecType;
Declarator &D = state.getDeclarator();
Sema &S = state.getSema();
@@ -3074,6 +3077,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
processTypeAttrs(state, T, TAL_DeclChunk, attrs);
}
+ assert(!T.isNull() && "T must not be null after this point");
+
if (LangOpts.CPlusPlus && T->isFunctionType()) {
const FunctionProtoType *FnTy = T->getAs<FunctionProtoType>();
assert(FnTy && "Why oh why is there not a FunctionProtoType here?");
@@ -3162,12 +3167,11 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
}
// Apply any undistributed attributes from the declarator.
- if (!T.isNull())
- if (AttributeList *attrs = D.getAttributes())
- processTypeAttrs(state, T, TAL_DeclName, attrs);
+ if (AttributeList *attrs = D.getAttributes())
+ processTypeAttrs(state, T, TAL_DeclName, attrs);
// Diagnose any ignored type attributes.
- if (!T.isNull()) state.diagnoseIgnoredTypeAttrs(T);
+ state.diagnoseIgnoredTypeAttrs(T);
// C++0x [dcl.constexpr]p9:
// A constexpr specifier used in an object declaration declares the object
@@ -3178,7 +3182,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
// If there was an ellipsis in the declarator, the declaration declares a
// parameter pack whose type may be a pack expansion type.
- if (D.hasEllipsis() && !T.isNull()) {
+ if (D.hasEllipsis()) {
// C++0x [dcl.fct]p13:
// A declarator-id or abstract-declarator containing an ellipsis shall
// only be used in a parameter-declaration. Such a parameter-declaration
@@ -3249,9 +3253,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
}
}
- if (T.isNull())
- return Context.getNullTypeSourceInfo();
- else if (D.isInvalidType())
+ assert(!T.isNull() && "T must not be null at the end of this function");
+ if (D.isInvalidType())
return Context.getTrivialTypeSourceInfo(T);
return S.GetTypeSourceInfoForDeclarator(D, T, TInfo);
@@ -3270,8 +3273,6 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
TypeSourceInfo *ReturnTypeInfo = nullptr;
QualType T = GetDeclSpecTypeForDeclarator(state, ReturnTypeInfo);
- if (T.isNull())
- return Context.getNullTypeSourceInfo();
if (D.isPrototypeContext() && getLangOpts().ObjCAutoRefCount)
inferARCWriteback(state, T);
@@ -3385,8 +3386,6 @@ TypeSourceInfo *Sema::GetTypeForDeclaratorCast(Declarator &D, QualType FromTy) {
TypeSourceInfo *ReturnTypeInfo = nullptr;
QualType declSpecTy = GetDeclSpecTypeForDeclarator(state, ReturnTypeInfo);
- if (declSpecTy.isNull())
- return Context.getNullTypeSourceInfo();
if (getLangOpts().ObjCAutoRefCount) {
Qualifiers::ObjCLifetime ownership = Context.getInnerObjCOwnership(FromTy);
OpenPOWER on IntegriCloud