From 56faab2d4fd40a8b352abd1dd5a4ada46765c170 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Wed, 30 May 2007 04:20:12 +0000 Subject: [PATCH] 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. llvm-svn: 39526 --- clang/Sema/SemaExpr.cpp | 24 +++++++------ clang/Sema/SemaStmt.cpp | 21 ++++++++--- clang/include/clang/Basic/DiagnosticKinds.def | 36 ++++++++----------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index 4693bc6234ed..5d55cff244fd 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -382,13 +382,13 @@ ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc, 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 @@ ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc, 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 @@ inline QualType Sema::CheckAssignmentOperands( // C99 6.5.16.1 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: diff --git a/clang/Sema/SemaStmt.cpp b/clang/Sema/SemaStmt.cpp index ebc0722828f7..83049bead1f4 100644 --- a/clang/Sema/SemaStmt.cpp +++ b/clang/Sema/SemaStmt.cpp @@ -26,7 +26,10 @@ Sema::StmtResult Sema::ParseNullStmt(SourceLocation SemiLoc) { } Sema::StmtResult Sema::ParseDeclStmt(DeclTy *decl) { - return decl ? new DeclStmt(static_cast(decl)) : 0; + if (decl) + return new DeclStmt(static_cast(decl)); + else + return true; // error } Action::StmtResult @@ -248,16 +251,24 @@ Sema::ParseReturnStmt(SourceLocation ReturnLoc, ExprTy *RetValExp) { 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); diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def index d5734da13b89..b9d4dad54ef3 100644 --- a/clang/include/clang/Basic/DiagnosticKinds.def +++ b/clang/include/clang/Basic/DiagnosticKinds.def @@ -563,15 +563,13 @@ DIAG(ext_typecheck_comparison_of_pointer_integer, EXTENSION, 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_few_args, ERROR, 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_continue_not_in_loop, ERROR, 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)")