[cfe-commits] r49082 - in /cfe/trunk: include/clang/AST/Type.h lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp
Chris Lattner
sabre at nondot.org
Tue Apr 1 23:59:01 PDT 2008
Author: lattner
Date: Wed Apr 2 01:59:01 2008
New Revision: 49082
URL: http://llvm.org/viewvc/llvm-project?rev=49082&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/Sema/SemaExpr.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=49082&r1=49081&r2=49082&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Apr 2 01:59:01 2008
@@ -261,6 +261,12 @@
/// 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 "[]".
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=49082&r1=49081&r2=49082&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Apr 2 01:59:01 2008
@@ -443,7 +443,8 @@
// 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 @@
// 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 @@
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 @@
// 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
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=49082&r1=49081&r2=49082&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Apr 2 01:59:01 2008
@@ -167,8 +167,7 @@
// 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 @@
// 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 @@
// 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());
More information about the cfe-commits
mailing list