[cfe-commits] r107163 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/Sema/enum-packed.c

Douglas Gregor dgregor at apple.com
Tue Jun 29 10:12:35 PDT 2010


Author: dgregor
Date: Tue Jun 29 12:12:35 2010
New Revision: 107163

URL: http://llvm.org/viewvc/llvm-project?rev=107163&view=rev
Log:
With packed enums, an enumerator's value may be stored in more bits
than the enumeration type itself takes. Fixes PR7477.

Added:
    cfe/trunk/test/Sema/enum-packed.c   (with props)
Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=107163&r1=107162&r2=107163&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Jun 29 12:12:35 2010
@@ -836,6 +836,8 @@
         llvm::APSInt Val = (*EDI)->getInitVal();
         if(Val.getBitWidth() < CondWidth)
           Val.extend(CondWidth);
+        else if (Val.getBitWidth() > CondWidth)
+          Val.trunc(CondWidth);
         Val.setIsSigned(CondIsSigned);
         EnumVals.push_back(std::make_pair(Val, (*EDI)));
       }

Added: cfe/trunk/test/Sema/enum-packed.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum-packed.c?rev=107163&view=auto
==============================================================================
--- cfe/trunk/test/Sema/enum-packed.c (added)
+++ cfe/trunk/test/Sema/enum-packed.c Tue Jun 29 12:12:35 2010
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR7477
+enum __attribute__((packed)) E {
+  Ea, Eb, Ec, Ed
+};
+
+void test_E(enum E e) {
+  switch (e) {
+  case Ea:
+  case Eb:
+  case Ec:
+  case Ed:
+    break;
+  }
+}

Propchange: cfe/trunk/test/Sema/enum-packed.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/Sema/enum-packed.c
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/Sema/enum-packed.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list