From 834a72ac74cf4ff07ba6215545dba3db578f8a07 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 25 Jul 2008 23:18:17 +0000 Subject: Fix rdar://6095136, various crashes with incomplete enum types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54074 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Type.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/AST/Type.cpp') diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 0082b2f7b3..275406eaba 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -476,7 +476,8 @@ bool Type::isIntegerType() const { return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::LongLong; if (const TagType *TT = dyn_cast(CanonicalType)) - if (TT->getDecl()->isEnum()) + // Incomplete enum types are not treated as integer types. + if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) return true; if (const VectorType *VT = dyn_cast(CanonicalType)) return VT->getElementType()->isIntegerType(); @@ -490,8 +491,8 @@ bool Type::isIntegralType() const { return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::LongLong; if (const TagType *TT = dyn_cast(CanonicalType)) - if (TT->getDecl()->isEnum()) - return true; + if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) + return true; // Complete enum types are integral. if (const ASQualType *ASQT = dyn_cast(CanonicalType)) return ASQT->getBaseType()->isIntegralType(); return false; @@ -593,7 +594,7 @@ bool Type::isRealType() const { return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::LongDouble; if (const TagType *TT = dyn_cast(CanonicalType)) - return TT->getDecl()->isEnum(); + return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); if (const VectorType *VT = dyn_cast(CanonicalType)) return VT->getElementType()->isRealType(); if (const ASQualType *ASQT = dyn_cast(CanonicalType)) @@ -617,7 +618,9 @@ bool Type::isScalarType() const { if (const BuiltinType *BT = dyn_cast(CanonicalType)) return BT->getKind() != BuiltinType::Void; if (const TagType *TT = dyn_cast(CanonicalType)) { - if (TT->getDecl()->isEnum()) + // Enums are scalar types, but only if they are defined. Incomplete enums + // are not treated as scalar types. + if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) return true; return false; } -- cgit v1.2.3-18-g5258