diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2008-06-28 06:23:08 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2008-06-28 06:23:08 +0000 |
| commit | 4f89ccb1dfc8cd1b21db5571308bfda676068090 (patch) | |
| tree | 6a0b3ec39d175ab2b0fd4ac29293382e4b23fbd2 /clang/lib/AST | |
| parent | 853fbea313b8be8cbfd2ac94e3e366300621aad6 (diff) | |
| download | bcm5719-llvm-4f89ccb1dfc8cd1b21db5571308bfda676068090.tar.gz bcm5719-llvm-4f89ccb1dfc8cd1b21db5571308bfda676068090.zip | |
Fix for PR2501; this patch makes usual arithmetic conversions for
integers which have the same width and different signedness work
correctly. (The testcase in PR2501 uses a comparison between long and
unsigned int).
llvm-svn: 52853
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 35 | ||||
| -rw-r--r-- | clang/lib/AST/Type.cpp | 7 |
2 files changed, 42 insertions, 0 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 11ca78a4798..08a2bb1357b 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1757,6 +1757,41 @@ bool ASTContext::typesAreCompatible(QualType LHS_NC, QualType RHS_NC) { } //===----------------------------------------------------------------------===// +// Integer Predicates +//===----------------------------------------------------------------------===// +unsigned ASTContext::getIntWidth(QualType T) { + if (T == BoolTy) + return 1; + // At the moment, only bool has padding bits + return (unsigned)getTypeSize(T); +} + +QualType ASTContext::getCorrespondingUnsignedType(QualType T) { + assert(T->isSignedIntegerType() && "Unexpected type"); + if (const EnumType* ETy = T->getAsEnumType()) + T = ETy->getDecl()->getIntegerType(); + const BuiltinType* BTy = T->getAsBuiltinType(); + assert (BTy && "Unexpected signed integer type"); + switch (BTy->getKind()) { + case BuiltinType::Char_S: + case BuiltinType::SChar: + return UnsignedCharTy; + case BuiltinType::Short: + return UnsignedShortTy; + case BuiltinType::Int: + return UnsignedIntTy; + case BuiltinType::Long: + return UnsignedLongTy; + case BuiltinType::LongLong: + return UnsignedLongLongTy; + default: + assert(0 && "Unexpected signed integer type"); + return QualType(); + } +} + + +//===----------------------------------------------------------------------===// // Serialization Support //===----------------------------------------------------------------------===// diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 7e09bb1ae37..bf32c5306d7 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -390,6 +390,13 @@ const RecordType *Type::getAsUnionType() const { return 0; } +const EnumType *Type::getAsEnumType() const { + // Check the canonicalized unqualified type directly; the more complex + // version is unnecessary because there isn't any typedef information + // to preserve. + return dyn_cast<EnumType>(CanonicalType.getUnqualifiedType()); +} + const ComplexType *Type::getAsComplexType() const { // Are we directly a complex type? if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) |

