diff options
author | Ted Kremenek <kremenek@apple.com> | 2013-10-10 00:54:01 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2013-10-10 00:54:01 +0000 |
commit | e65ab9e80eec0e56235bd74c6d487e5a89f66146 (patch) | |
tree | ceb1fb9ddc399b69541c0dd546171b9ce0f857b5 /clang/lib/AST/ASTContext.cpp | |
parent | 394e36dc810f8261bcf69d788ad412b7a1c5798f (diff) | |
download | bcm5719-llvm-e65ab9e80eec0e56235bd74c6d487e5a89f66146.tar.gz bcm5719-llvm-e65ab9e80eec0e56235bd74c6d487e5a89f66146.zip |
Fix getIntegerTypeOrder() to properly handle enums by first unwrapping their underlying integer type. This is a precondition for calling getIntegerRank().
Fixes an assertion failure in a test case involving vectors.
Fixes <rdar://problem/15091442>
Please somebody check this.
llvm-svn: 192334
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 3b5bfe6d8c3..04711e330c0 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -4417,12 +4417,27 @@ Qualifiers::ObjCLifetime ASTContext::getInnerObjCOwnership(QualType T) const { return Qualifiers::OCL_None; } +static const Type *getIntegerTypeForEnum(const EnumType *ET) { + // Incomplete enum types are not treated as integer types. + // FIXME: In C++, enum types are never integer types. + if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) + return ET->getDecl()->getIntegerType().getTypePtr(); + return NULL; +} + /// getIntegerTypeOrder - Returns the highest ranked integer type: /// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If /// LHS < RHS, return -1. int ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) const { const Type *LHSC = getCanonicalType(LHS).getTypePtr(); const Type *RHSC = getCanonicalType(RHS).getTypePtr(); + + // Unwrap enums to their underlying type. + if (const EnumType *ET = dyn_cast<EnumType>(LHSC)) + LHSC = getIntegerTypeForEnum(ET); + if (const EnumType *ET = dyn_cast<EnumType>(RHSC)) + RHSC = getIntegerTypeForEnum(ET); + if (LHSC == RHSC) return 0; bool LHSUnsigned = LHSC->isUnsignedIntegerType(); |