diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-10-08 23:50:27 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-10-08 23:50:27 +0000 |
| commit | 0bf3140424a0a13a928a4e6bf0f112e6167a5636 (patch) | |
| tree | aef7f4fa057fc4672999ce4ec62b01064035c242 /clang/lib/CodeGen | |
| parent | 959fcc6c634cb4d4fd8bd8c8b4bc3e6b99ebc228 (diff) | |
| download | bcm5719-llvm-0bf3140424a0a13a928a4e6bf0f112e6167a5636.tar.gz bcm5719-llvm-0bf3140424a0a13a928a4e6bf0f112e6167a5636.zip | |
Implement C++0x scoped enumerations, from Daniel Wallin! (and tweaked a
bit by me).
llvm-svn: 116122
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenTypes.cpp | 10 |
2 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 78c1da5060c..e4ed5d64d90 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -599,11 +599,17 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, return V; } +static bool isBooleanUnderlyingType(QualType Ty) { + if (const EnumType *ET = dyn_cast<EnumType>(Ty)) + return ET->getDecl()->getIntegerType()->isBooleanType(); + return false; +} + void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, bool Volatile, unsigned Alignment, QualType Ty) { - if (Ty->isBooleanType()) { + if (Ty->isBooleanType() || isBooleanUnderlyingType(Ty)) { // Bool can have different representation in memory than in registers. const llvm::PointerType *DstPtr = cast<llvm::PointerType>(Addr->getType()); Value = Builder.CreateIntCast(Value, DstPtr->getElementType(), false); diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp index 5ab65c5779b..87cab311d4e 100644 --- a/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/clang/lib/CodeGen/CodeGenTypes.cpp @@ -424,9 +424,13 @@ const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) { if (TDTI != TagDeclTypes.end()) return TDTI->second; + const EnumDecl *ED = dyn_cast<EnumDecl>(TD); + // If this is still a forward declaration, just define an opaque // type to use for this tagged decl. - if (!TD->isDefinition()) { + // C++0x: If this is a enumeration type with fixed underlying type, + // consider it complete. + if (!TD->isDefinition() && !(ED && ED->isFixed())) { llvm::Type *ResultType = llvm::OpaqueType::get(getLLVMContext()); TagDeclTypes.insert(std::make_pair(Key, ResultType)); return ResultType; @@ -434,8 +438,8 @@ const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) { // Okay, this is a definition of a type. Compile the implementation now. - if (TD->isEnum()) // Don't bother storing enums in TagDeclTypes. - return ConvertTypeRecursive(cast<EnumDecl>(TD)->getIntegerType()); + if (ED) // Don't bother storing enums in TagDeclTypes. + return ConvertTypeRecursive(ED->getIntegerType()); // This decl could well be recursive. In this case, insert an opaque // definition of this type, which the recursive uses will get. We will then |

