add a diagnostic:

t.c:1:12: warning: ISO C restricts enumerator values to range of 'int' (180388626432 is too large)
enum e {A, B = 42LL << 32, C = -4, D = 12456 };
           ^



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41530 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 5ab40ec..301813b 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -987,6 +987,7 @@
   // 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.
+  unsigned IntWidth = Context.getTypeSize(Context.IntTy, Enum->getLocation());
   
   
   // Verify that all the values are okay, and reverse the list.
@@ -995,6 +996,19 @@
     EnumConstantDecl *ECD =
       cast_or_null<EnumConstantDecl>(static_cast<Decl*>(Elements[i]));
     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();
+    if (InitVal.getBitWidth() > IntWidth) {
+      llvm::APSInt V(InitVal);
+      V.trunc(IntWidth);
+      V.extend(InitVal.getBitWidth());
+      if (V != InitVal)
+        Diag(ECD->getLocation(), diag::ext_enum_value_not_int,
+             InitVal.toString());
+    }
 
     ECD->setNextDeclarator(EltList);
     EltList = ECD;