[cfe-commits] r39574 - in /cfe/cfe/trunk/Sema: SemaExpr.cpp SemaStmt.cpp

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:45:46 PDT 2007


Author: clattner
Date: Wed Jul 11 11:45:46 2007
New Revision: 39574

URL: http://llvm.org/viewvc/llvm-project?rev=39574&view=rev
Log:
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():
       ~~~~~~~~^~~~~

Modified:
    cfe/cfe/trunk/Sema/SemaExpr.cpp
    cfe/cfe/trunk/Sema/SemaStmt.cpp

Modified: cfe/cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExpr.cpp?rev=39574&r1=39573&r2=39574&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:45:46 2007
@@ -573,17 +573,18 @@
   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 @@
 
     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.

Modified: cfe/cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaStmt.cpp?rev=39574&r1=39573&r2=39574&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaStmt.cpp Wed Jul 11 11:45:46 2007
@@ -39,16 +39,18 @@
 }
 
 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);
 }





More information about the cfe-commits mailing list