diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-06-29 17:12:35 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-06-29 17:12:35 +0000 |
commit | 6623584c0ec508110d75572eef092bf98fedf3f4 (patch) | |
tree | 8a747f7d0a07ba8d5170cc4f321657327626b5dc | |
parent | 9fde9c424f734e1ef45177999e3a04faad127414 (diff) |
With packed enums, an enumerator's value may be stored in more bits
than the enumeration type itself takes. Fixes PR7477.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107163 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 2 | ||||
-rw-r--r-- | test/Sema/enum-packed.c | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 738fc55823..8e163ef245 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -836,6 +836,8 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, 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))); } diff --git a/test/Sema/enum-packed.c b/test/Sema/enum-packed.c new file mode 100644 index 0000000000..0eb6c14dbe --- /dev/null +++ b/test/Sema/enum-packed.c @@ -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; + } +} |