[cfe-commits] r41513 - in /cfe/trunk: Sema/SemaDecl.cpp include/clang/Basic/DiagnosticKinds.def
Chris Lattner
sabre at nondot.org
Mon Aug 27 14:16:19 PDT 2007
Author: lattner
Date: Mon Aug 27 16:16:18 2007
New Revision: 41513
URL: http://llvm.org/viewvc/llvm-project?rev=41513&view=rev
Log:
Fix a few enum-related fixme's
Modified:
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=41513&r1=41512&r2=41513&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Mon Aug 27 16:16:18 2007
@@ -936,6 +936,9 @@
llvm::APSInt EnumVal(32);
QualType EltTy;
if (Val) {
+ // Make sure to promote the operand type to int.
+ UsualUnaryConversions(Val);
+
// C99 6.7.2.2p2: Make sure we have an integer constant expression.
SourceLocation ExpLoc;
if (!Val->isIntegerConstantExpr(EnumVal, Context, &ExpLoc)) {
@@ -952,17 +955,19 @@
// Assign the last value + 1.
EnumVal = LastEnumConst->getInitVal();
++EnumVal;
- // FIXME: detect overflow!
+
+ // Check for overflow on increment.
+ if (EnumVal < LastEnumConst->getInitVal())
+ Diag(IdLoc, diag::warn_enum_value_overflow);
+
EltTy = LastEnumConst->getType();
} else {
// First value, set to zero.
EltTy = Context.IntTy;
- // FIXME: Resize EnumVal to the size of int.
+ EnumVal.zextOrTrunc(Context.getTypeSize(EltTy, IdLoc));
}
}
- // TODO: Default promotions to int/uint.
-
// TODO: If the result value doesn't fit in an int, it must be a long or long
// long value. ISO C does not support this, but GCC does as an extension,
// emit a warning.
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=41513&r1=41512&r2=41513&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Mon Aug 27 16:16:18 2007
@@ -285,6 +285,8 @@
DIAG(ext_empty_struct_union_enum, EXTENSION,
"use of empty %0 extension")
+DIAG(warn_enum_value_overflow, WARNING,
+ "overflow in enumeration value")
DIAG(ext_ident_list_in_param, EXTENSION,
"type-less parameter names in function declaration")
More information about the cfe-commits
mailing list