]> granicus.if.org Git - clang/commitdiff
Fix a few enum-related fixme's
authorChris Lattner <sabre@nondot.org>
Mon, 27 Aug 2007 21:16:18 +0000 (21:16 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 27 Aug 2007 21:16:18 +0000 (21:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41513 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaDecl.cpp
include/clang/Basic/DiagnosticKinds.def

index ba2fc80590cc5e456554ced438ed79c98f9b1375..be61d735d75323c4e89349d39184e23beb90f7db 100644 (file)
@@ -936,6 +936,9 @@ Sema::DeclTy *Sema::ParseEnumConstant(Scope *S, DeclTy *theEnumDecl,
   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 @@ Sema::DeclTy *Sema::ParseEnumConstant(Scope *S, DeclTy *theEnumDecl,
       // 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.
index 67148549725e02b1c217a208b1361c7109a6fd5d..1ca8cf0b3a9bd3b195087a9a85261057ee4facb1 100644 (file)
@@ -285,6 +285,8 @@ DIAG(ext_mixed_decls_code, EXTENSION,
 
 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")