From abcf38a064f2d322f410af70bddfa256c96c174c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 24 Feb 2011 07:31:28 +0000 Subject: [PATCH] compute the integer width, not the memory width here. We want to know that _Bool is 1 bit, not 8. This fixes an assertion on the testcase, which is PR9304 and rdar://9045501. llvm-svn: 126368 --- clang/lib/Sema/SemaStmt.cpp | 3 +-- clang/test/SemaCXX/switch.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 64827ff17797..89957e60deca 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -502,8 +502,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, bool HasDependentValue = CondExpr->isTypeDependent() || CondExpr->isValueDependent(); unsigned CondWidth - = HasDependentValue? 0 - : static_cast(Context.getTypeSize(CondTypeBeforePromotion)); + = HasDependentValue ? 0 : Context.getIntWidth(CondTypeBeforePromotion); bool CondIsSigned = CondTypeBeforePromotion->isSignedIntegerType(); // Accumulate all of the case values in a vector so that we can sort them diff --git a/clang/test/SemaCXX/switch.cpp b/clang/test/SemaCXX/switch.cpp index fc13630bbf12..3882a1f952ca 100644 --- a/clang/test/SemaCXX/switch.cpp +++ b/clang/test/SemaCXX/switch.cpp @@ -57,3 +57,10 @@ namespace test3 { template void foo(); template void foo(); //expected-note {{in instantiation}} } + +// PR9304 and rdar://9045501 +void click_check_header_sizes() { + switch (0 == 8) { // expected-warning {{switch condition has boolean value}} + case 0: ; + } +}