aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-02-26 00:33:57 +0000
committerChris Lattner <sabre@nondot.org>2008-02-26 00:33:57 +0000
commit7768313c13d99efe596a503be83c57bf319e876f (patch)
tree03f10ffc320d951fa9d16acd01620466e1bddb41
parenta3343a86ea305a193418a65d8a4bd6a13bb590d1 (diff)
downloadllvm-7768313c13d99efe596a503be83c57bf319e876f.zip
llvm-7768313c13d99efe596a503be83c57bf319e876f.tar.gz
llvm-7768313c13d99efe596a503be83c57bf319e876f.tar.bz2
Fix PR2092 by making sure the sign of the enum value follows the
sign of its type in the early exit case. No testcase, because this doesn't manifest as a failure. llvm-svn: 47581
-rw-r--r--clang/Sema/SemaDecl.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index 808241c..1a0c3b2 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/Sema/SemaDecl.cpp
@@ -1498,7 +1498,7 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
else
Diag(IdLoc, diag::err_redefinition, Id->getName());
Diag(PrevDecl->getLocation(), diag::err_previous_definition);
- // FIXME: Don't leak memory: delete Val;
+ delete Val;
return 0;
}
}
@@ -1514,7 +1514,7 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
if (!Val->isIntegerConstantExpr(EnumVal, Context, &ExpLoc)) {
Diag(ExpLoc, diag::err_enum_value_not_integer_constant_expr,
Id->getName());
- // FIXME: Don't leak memory: delete Val;
+ delete Val;
Val = 0; // Just forget about it.
} else {
EltTy = Val->getType();
@@ -1577,9 +1577,9 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
if (!ECD) continue; // Already issued a diagnostic.
// If the enum value doesn't fit in an int, emit an extension warning.
- assert(ECD->getInitVal().getBitWidth() >= IntWidth &&
- "Should have promoted value to int");
const llvm::APSInt &InitVal = ECD->getInitVal();
+ assert(InitVal.getBitWidth() >= IntWidth &&
+ "Should have promoted value to int");
if (InitVal.getBitWidth() > IntWidth) {
llvm::APSInt V(InitVal);
V.trunc(IntWidth);
@@ -1590,7 +1590,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
}
// Keep track of the size of positive and negative values.
- if (InitVal.isUnsigned() || !InitVal.isNegative())
+ if (InitVal.isUnsigned() || InitVal.isNonNegative())
NumPositiveBits = std::max(NumPositiveBits,
(unsigned)InitVal.getActiveBits());
else
@@ -1664,8 +1664,13 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
// 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)
+ if (ECD->getType() == Context.IntTy) {
+ // Make sure the init value is signed.
+ llvm::APSInt IV = ECD->getInitVal();
+ IV.setIsSigned(true);
+ ECD->setInitVal(IV);
continue; // Already int type.
+ }
// Determine whether the value fits into an int.
llvm::APSInt InitVal = ECD->getInitVal();