diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2009-12-10 22:29:29 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2009-12-10 22:29:29 +0000 |
| commit | ee275c82ffd451499595d753d0dc3576f5e2280f (patch) | |
| tree | 523369107145862231b1e5cf208786e8604706aa /clang/lib/Sema/SemaDecl.cpp | |
| parent | 781161dc55edbbf5f95a9d6e52d1b9bd2348bdcb (diff) | |
| download | bcm5719-llvm-ee275c82ffd451499595d753d0dc3576f5e2280f.tar.gz bcm5719-llvm-ee275c82ffd451499595d753d0dc3576f5e2280f.zip | |
Clean up enum constants so that they're finally sane. Fixes PR3173 and a
recently introduced crash.
llvm-svn: 91070
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6574ad2e87d..c7a47c98c9f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5694,6 +5694,7 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, // First value, set to zero. EltTy = Context.IntTy; EnumVal.zextOrTrunc(static_cast<uint32_t>(Context.getTypeSize(EltTy))); + EnumVal.setIsSigned(true); } } @@ -5908,19 +5909,8 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, // enumerator value fits in an int, type it as an int, otherwise type it the // same as the enumerator decl itself. This means that in "enum { X = 1U }" // that X has type 'int', not 'unsigned'. - if (ECD->getType() == Context.IntTy) { - // Make sure the init value is signed. - llvm::APSInt IV = ECD->getInitVal(); - IV.setIsSigned(true); - ECD->setInitVal(IV); - - if (getLangOptions().CPlusPlus) - // C++ [dcl.enum]p4: Following the closing brace of an - // enum-specifier, each enumerator has the type of its - // enumeration. - ECD->setType(EnumType); - continue; // Already int type. - } + if (!getLangOptions().CPlusPlus && ECD->getType() == Context.IntTy) + continue; // Determine whether the value fits into an int. llvm::APSInt InitVal = ECD->getInitVal(); @@ -5935,7 +5925,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, QualType NewTy; unsigned NewWidth; bool NewSign; - if (FitsInInt) { + if (FitsInInt && !getLangOptions().CPlusPlus) { NewTy = Context.IntTy; NewWidth = IntWidth; NewSign = true; |

