From 0c46c5d55a4dffce646eadb2dbd18f9b1fbb524a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 2 Jun 2007 23:53:17 +0000 Subject: [PATCH] Fix a fixme, produce diagnostics like this: ds.c:11:16: error: case label does not reduce to an integer constant case 0 ? 0 : foo(): ~~~~~~~~^~~~~ llvm-svn: 39574 --- clang/Sema/SemaExpr.cpp | 14 ++++++++------ clang/Sema/SemaStmt.cpp | 12 +++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index 64574a7db55f..5cfa4aa13590 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -573,17 +573,18 @@ QualType Sema::UsualArithmeticConversions(QualType t1, QualType t2) { QualType lhs = UsualUnaryConversion(t1); QualType rhs = UsualUnaryConversion(t2); - // if either operand is not of arithmetic type, no conversion is possible. + // If both types are identical, no conversion is needed. + if (lhs == rhs) + return lhs; + + // If either side is a non-arithmetic type (e.g. a pointer), we are done. + // The caller can deal with this (e.g. pointer + int). if (!lhs->isArithmeticType()) return lhs; if (!rhs->isArithmeticType()) return rhs; - // if both arithmetic types are identical, no conversion is needed. - if (lhs == rhs) - return lhs; - - // at this point, we have two different arithmetic types. + // At this point, we have two different arithmetic types. // Handle complex types first (C99 6.3.1.8p1). if (lhs->isComplexType() || rhs->isComplexType()) { @@ -595,6 +596,7 @@ QualType Sema::UsualArithmeticConversions(QualType t1, QualType t2) { return Context.maxComplexType(lhs, rhs); } + // Now handle "real" floating types (i.e. float, double, long double). if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) { // if we have an integer operand, the result is the real floating type. diff --git a/clang/Sema/SemaStmt.cpp b/clang/Sema/SemaStmt.cpp index b3cb42a90b33..d1a4addf5de8 100644 --- a/clang/Sema/SemaStmt.cpp +++ b/clang/Sema/SemaStmt.cpp @@ -39,16 +39,18 @@ Sema::ParseCompoundStmt(SourceLocation L, SourceLocation R, } Action::StmtResult -Sema::ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal, +Sema::ParseCaseStmt(SourceLocation CaseLoc, ExprTy *lhsval, SourceLocation DotDotDotLoc, ExprTy *RHSVal, SourceLocation ColonLoc, StmtTy *SubStmt) { + Expr *LHSVal = ((Expr *)lhsval); assert((LHSVal != 0) && "missing expression in case statement"); - SourceLocation expLoc; + SourceLocation ExpLoc; // C99 6.8.4.2p3: The expression shall be an integer constant. - if (!((Expr *)LHSVal)->isIntegerConstantExpr(&expLoc)) - // FIXME: Should pass in case expr as range. - return Diag(CaseLoc, diag::err_case_label_not_integer_constant_expr); + if (!LHSVal->isIntegerConstantExpr(&ExpLoc)) + return Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr, + LHSVal->getSourceRange()); + } return new CaseStmt((Expr*)LHSVal, (Expr*)RHSVal, (Stmt*)SubStmt); }