[cfe-commits] r39526 - in /cfe/cfe/trunk: Sema/SemaExpr.cpp Sema/SemaStmt.cpp include/clang/Basic/DiagnosticKinds.def

Steve Naroff snaroff at apple.com
Wed Jul 11 09:45:17 PDT 2007


Author: snaroff
Date: Wed Jul 11 11:45:17 2007
New Revision: 39526

URL: http://llvm.org/viewvc/llvm-project?rev=39526&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
- Many tweaks to various diagnostics.
- Fixed some location/range issues.
- Bug fix to Sema::ParseDeclStmt() - error return code is "true", not 0.

Modified:
    cfe/cfe/trunk/Sema/SemaExpr.cpp
    cfe/cfe/trunk/Sema/SemaStmt.cpp
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:45:17 2007
@@ -382,13 +382,13 @@
     unsigned NumArgsToCheck = NumArgsInCall;
     
     if (NumArgsInCall < NumArgsInProto)
-      Diag(LParenLoc, diag::err_typecheck_call_too_few_args,
+      Diag(RParenLoc, diag::err_typecheck_call_too_few_args,
            funcExpr->getSourceRange());
     else if (NumArgsInCall > NumArgsInProto) {
       if (!proto->isVariadic()) {
-        Diag(LParenLoc, diag::err_typecheck_call_too_many_args,
-             funcExpr->getSourceRange(),
-             ((Expr **)Args)[NumArgsInProto]->getSourceRange());
+        Diag(((Expr **)Args)[NumArgsInProto+1]->getLocStart(), 
+             diag::err_typecheck_call_too_many_args, funcExpr->getSourceRange(),
+             ((Expr **)Args)[NumArgsInProto+1]->getSourceRange());
       }
       NumArgsToCheck = NumArgsInProto;
     }
@@ -414,14 +414,14 @@
       case PointerFromInt:
         // check for null pointer constant (C99 6.3.2.3p3)
         if (!argExpr->isNullPointerConstant()) {
-          Diag(l, diag::ext_typecheck_passing_pointer_from_int, 
-               lhsType.getAsString(),
+          Diag(l, diag::ext_typecheck_passing_pointer_int, 
+               lhsType.getAsString(), rhsType.getAsString(),
                funcExpr->getSourceRange(), argExpr->getSourceRange());
         }
         break;
       case IntFromPointer:
-        Diag(l, diag::ext_typecheck_passing_int_from_pointer, 
-             rhsType.getAsString(),
+        Diag(l, diag::ext_typecheck_passing_pointer_int, 
+             lhsType.getAsString(), rhsType.getAsString(),
              funcExpr->getSourceRange(), argExpr->getSourceRange());
         break;
       case IncompatiblePointer:
@@ -889,11 +889,13 @@
   case PointerFromInt:
     // check for null pointer constant (C99 6.3.2.3p3)
     if (compoundType.isNull() && !rex->isNullPointerConstant())
-      Diag(loc, diag::ext_typecheck_assign_pointer_from_int,
+      Diag(loc, diag::ext_typecheck_assign_pointer_int,
+           lhsType.getAsString(), rhsType.getAsString(),
            lex->getSourceRange(), rex->getSourceRange());
     break;
-  case IntFromPointer:
-    Diag(loc, diag::ext_typecheck_assign_int_from_pointer,
+  case IntFromPointer: 
+    Diag(loc, diag::ext_typecheck_assign_pointer_int, 
+         lhsType.getAsString(), rhsType.getAsString(),
          lex->getSourceRange(), rex->getSourceRange());
     break;
   case IncompatiblePointer:

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaStmt.cpp Wed Jul 11 11:45:17 2007
@@ -26,7 +26,10 @@
 }
 
 Sema::StmtResult Sema::ParseDeclStmt(DeclTy *decl) {
-  return decl ? new DeclStmt(static_cast<Decl *>(decl)) : 0;
+  if (decl)
+    return new DeclStmt(static_cast<Decl *>(decl));
+  else 
+    return true; // error
 }
 
 Action::StmtResult 
@@ -248,16 +251,24 @@
   case PointerFromInt:
     // check for null pointer constant (C99 6.3.2.3p3)
     if (!((Expr *)RetValExp)->isNullPointerConstant())
-      Diag(ReturnLoc, diag::ext_typecheck_return_pointer_from_int);
+      Diag(ReturnLoc, diag::ext_typecheck_return_pointer_int,
+           lhsType.getAsString(), rhsType.getAsString(),
+           ((Expr *)RetValExp)->getSourceRange());
     break;
   case IntFromPointer:
-    Diag(ReturnLoc, diag::ext_typecheck_return_int_from_pointer);
+    Diag(ReturnLoc, diag::ext_typecheck_return_pointer_int,
+         lhsType.getAsString(), rhsType.getAsString(),
+         ((Expr *)RetValExp)->getSourceRange());
     break;
   case IncompatiblePointer:
-    Diag(ReturnLoc, diag::ext_typecheck_return_incompatible_pointer);
+    Diag(ReturnLoc, diag::ext_typecheck_return_incompatible_pointer,
+         lhsType.getAsString(), rhsType.getAsString(),
+         ((Expr *)RetValExp)->getSourceRange());
     break;
   case CompatiblePointerDiscardsQualifiers:
-    Diag(ReturnLoc, diag::ext_typecheck_return_discards_qualifiers);
+    Diag(ReturnLoc, diag::ext_typecheck_return_discards_qualifiers,
+         lhsType.getAsString(), rhsType.getAsString(),
+         ((Expr *)RetValExp)->getSourceRange());
     break;
   }
   return new ReturnStmt((Expr*)RetValExp);

Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=39526&r1=39525&r2=39526&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:45:17 2007
@@ -563,15 +563,13 @@
 DIAG(err_typecheck_assign_const, ERROR,
      "read-only variable is not assignable")
 DIAG(err_typecheck_assign_incompatible, ERROR,
-     "incompatible types in assignment ('%0' and '%1')")
-DIAG(ext_typecheck_assign_int_from_pointer, EXTENSION,
-     "assignment makes integer from pointer without a cast")
-DIAG(ext_typecheck_assign_pointer_from_int, EXTENSION,
-     "assignment makes pointer from integer without a cast")
+     "incompatible types assigning '%1' to '%0'")
+DIAG(ext_typecheck_assign_pointer_int, EXTENSION,
+     "incompatible types assigning '%1' to '%0'")
 DIAG(ext_typecheck_assign_incompatible_pointer, EXTENSION,
-     "assignment from incompatible pointer type ('%0' and '%1')")
+     "incompatible pointer types assigning '%1' to '%0'")
 DIAG(ext_typecheck_assign_discards_qualifiers, EXTENSION,
-     "assignment discards qualifiers from pointer target type ('%0' and '%1')")
+     "assigning '%1' to '%0' discards qualifiers")
 DIAG(err_typecheck_array_not_modifiable_lvalue, ERROR,
      "array type '%0' is not assignable")
 DIAG(err_typecheck_non_object_not_modifiable_lvalue, ERROR,
@@ -585,15 +583,13 @@
 DIAG(err_typecheck_call_too_many_args, ERROR,
      "too many arguments to function")
 DIAG(err_typecheck_passing_incompatible, ERROR,
-     "passing incompatible type '%0' to function expecting '%1'")
+     "incompatible types passing '%0' to function expecting '%1'")
 DIAG(ext_typecheck_passing_incompatible_pointer, EXTENSION,
-     "passing incompatible pointer '%0' to function expecting '%1'")
-DIAG(ext_typecheck_passing_int_from_pointer, EXTENSION,
-     "passing pointer '%0' to function expecting integer (without a cast)")
-DIAG(ext_typecheck_passing_pointer_from_int, EXTENSION,
-     "passing integer to function expecting '%0' (without a cast)")
+     "incompatible pointer types passing '%0' to function expecting '%1'")
+DIAG(ext_typecheck_passing_pointer_int, EXTENSION,
+     "incompatible types passing '%1' to function expecting '%0'")
 DIAG(ext_typecheck_passing_discards_qualifiers, EXTENSION,
-     "function call discards qualifiers (passing '%0' to '%1')")
+     "passing '%0' to '%1' discards qualifiers")
 DIAG(err_typecheck_cond_expect_scalar, ERROR,
      "used type '%0' where arithmetic or pointer type is required")
 DIAG(err_typecheck_cond_incompatible_operands, ERROR,
@@ -607,15 +603,13 @@
 DIAG(err_break_not_in_loop_or_switch, ERROR,
      "'break' statement not in loop or switch statement")
 DIAG(err_typecheck_return_incompatible, ERROR,
-     "incompatible types in return ('%0' and '%1')")
-DIAG(ext_typecheck_return_int_from_pointer, EXTENSION,
-     "return makes integer from pointer without a cast")
-DIAG(ext_typecheck_return_pointer_from_int, EXTENSION,
-     "return makes pointer from integer without a cast")
+     "incompatible type returning '%1', expected '%0'")
+DIAG(ext_typecheck_return_pointer_int, EXTENSION,
+     "incompatible type returning '%1', expected '%0'")
 DIAG(ext_typecheck_return_incompatible_pointer, EXTENSION,
-     "return from incompatible pointer type")
+     "incompatible pointer type returning '%1', expected '%0'")
 DIAG(ext_typecheck_return_discards_qualifiers, EXTENSION,
-     "return discards qualifiers from pointer target type")
+     "returning '%1' from function expecting '%0' discards qualifiers")
 DIAG(err_typecheck_statement_requires_scalar, ERROR,
      "statement requires expression of scalar type ('%0' invalid)")
      





More information about the cfe-commits mailing list