diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-04-02 06:59:01 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-04-02 06:59:01 +0000 | 
| commit | b3a176da9f0dbe32bab8e66f472a203f5ec86cc6 (patch) | |
| tree | d9d8f8d1e4297da66bc64198484e5b7a236a3f00 /clang | |
| parent | daaa8ba77ecf8c4c26b397c123df9378524e0377 (diff) | |
| download | bcm5719-llvm-b3a176da9f0dbe32bab8e66f472a203f5ec86cc6.tar.gz bcm5719-llvm-b3a176da9f0dbe32bab8e66f472a203f5ec86cc6.zip | |
Various parts of the standard require something to be an "incomplete or 
object type".  Add a predicate that checks exactly this, as it is equivalent
to checking ot see if the type is *not* a function type, which is faster
to check.
llvm-svn: 49082
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/Type.h | 6 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 20 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 7 | 
3 files changed, 19 insertions, 14 deletions
| diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 60cbfc83adb..de3f6bda50c 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -261,6 +261,12 @@ public:    /// determine its size (e.g. void, or a fwd declared struct). Clients of this    /// routine will need to determine if the size is actually required.      bool isIncompleteType() const; + +  /// isIncompleteOrObjectType - Return true if this is an incomplete or object +  /// type, in other words, not a function type. +  bool isIncompleteOrObjectType() const { +    return !isFunctionType(); +  }    /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array    /// types that have a non-constant expression. This does not include "[]". diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 1cd23522e8f..05926018601 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -443,7 +443,8 @@ ActOnArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,    // C99 6.5.2.1p1: "shall have type "pointer to *object* type".  In practice,    // the following check catches trying to index a pointer to a function (e.g. -  // void (*)(int)). Functions are not objects in C99. +  // void (*)(int)) and pointers to incomplete types.  Functions are not +  // objects in C99.    if (!ResultType->isObjectType())      return Diag(BaseExpr->getLocStart(),                   diag::err_typecheck_subscript_not_object, @@ -837,7 +838,7 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15        // ignore qualifiers on void (C99 6.5.15p3, clause 6)        if (lhptee->isVoidType() && -          (rhptee->isObjectType() || rhptee->isIncompleteType())) { +          rhptee->isIncompleteOrObjectType()) {          // Figure out necessary qualifiers (C99 6.5.15p6)          QualType destPointee=lhptee.getQualifiedType(rhptee.getCVRQualifiers());          QualType destType = Context.getPointerType(destPointee); @@ -845,8 +846,7 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15          ImpCastExprToType(rex, destType); // promote to void*          return destType;        } -      if (rhptee->isVoidType() && -          (lhptee->isObjectType() || lhptee->isIncompleteType())) { +      if (rhptee->isVoidType() && lhptee->isIncompleteOrObjectType()) {          QualType destPointee=rhptee.getQualifiedType(lhptee.getCVRQualifiers());          QualType destType = Context.getPointerType(destPointee);          ImpCastExprToType(lex, destType); // add qualifiers if necessary @@ -1127,21 +1127,21 @@ Sema::CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType) {    // incomplete type and the other is a pointer to a qualified or unqualified     // version of void...    if (lhptee->isVoidType()) { -    if (rhptee->isObjectType() || rhptee->isIncompleteType()) +    if (rhptee->isIncompleteOrObjectType())        return ConvTy;      // As an extension, we allow cast to/from void* to function pointer. -    if (rhptee->isFunctionType()) -      return FunctionVoidPointer; +    assert(rhptee->isFunctionType()); +    return FunctionVoidPointer;    }    if (rhptee->isVoidType()) { -    if (lhptee->isObjectType() || lhptee->isIncompleteType()) +    if (lhptee->isIncompleteOrObjectType())        return ConvTy;      // As an extension, we allow cast to/from void* to function pointer. -    if (lhptee->isFunctionType()) -      return FunctionVoidPointer; +    assert(lhptee->isFunctionType()); +    return FunctionVoidPointer;    }    // C99 6.5.16.1p1 (constraint 3): both operands are pointers to qualified or  diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index a1cabcff64e..76bb63b1add 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -167,8 +167,7 @@ QualType Sema::ConvertDeclSpecToType(DeclSpec &DS) {        // If we have a pointer or reference, the pointee must have an object or        // incomplete type. -      if (!EltTy.isNull() && !EltTy->isObjectType() && -          !EltTy->isIncompleteType()) { +      if (!EltTy.isNull() && !EltTy->isIncompleteOrObjectType()) {          Diag(DS.getRestrictSpecLoc(),               diag::err_typecheck_invalid_restrict_invalid_pointee,               EltTy.getAsString(), DS.getSourceRange()); @@ -229,7 +228,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {        // Enforce C99 6.7.3p2: "Types other than pointer types derived from        // object or incomplete types shall not be restrict-qualified."        if ((DeclType.Ptr.TypeQuals & QualType::Restrict) && -          !T->isObjectType() && !T->isIncompleteType()) { +          !T->isIncompleteOrObjectType()) {          Diag(DeclType.Loc,               diag::err_typecheck_invalid_restrict_invalid_pointee,               T.getAsString()); @@ -256,7 +255,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {        // Enforce C99 6.7.3p2: "Types other than pointer types derived from        // object or incomplete types shall not be restrict-qualified."        if (DeclType.Ref.HasRestrict && -          !T->isObjectType() && !T->isIncompleteType()) { +          !T->isIncompleteOrObjectType()) {          Diag(DeclType.Loc,               diag::err_typecheck_invalid_restrict_invalid_pointee,               T.getAsString()); | 

