With packed enums, an enumerator's value may be stored in more bits

than the enumeration type itself takes. Fixes PR7477.

llvm-svn: 107163
This commit is contained in:
Douglas Gregor 2010-06-29 17:12:35 +00:00
parent 5bee07ec68
commit 56980d688b
2 changed files with 18 additions and 0 deletions

View File

@ -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)));
}

View File

@ -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;
}
}