From efa4b4e71de871a917381e3a2a456a05141291a5 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 17 Nov 2015 05:40:09 +0000 Subject: [PATCH] [Sema] Combine similar diagnostics using %select. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253315 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 26 ++++++++-------------- lib/Sema/SemaChecking.cpp | 8 +++---- lib/Sema/SemaDecl.cpp | 12 +++++----- lib/Sema/SemaExpr.cpp | 5 ++--- 4 files changed, 19 insertions(+), 32 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index d0518b9857..058d807203 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -4909,9 +4909,8 @@ def warn_floatingpoint_eq : Warning< "comparing floating point with == or != is unsafe">, InGroup>, DefaultIgnore; -def warn_division_by_zero : Warning<"division by zero is undefined">, - InGroup; -def warn_remainder_by_zero : Warning<"remainder by zero is undefined">, +def warn_remainder_division_by_zero : Warning< + "%select{remainder|division}0 by zero is undefined">, InGroup; def warn_shift_lhs_negative : Warning<"shifting a negative signed value is undefined">, InGroup>; @@ -6677,10 +6676,8 @@ def err_anonymous_union_with_storage_spec : Error< def err_anonymous_struct_not_member : Error< "anonymous %select{structs|structs and classes}0 must be " "%select{struct or union|class}0 members">; -def err_anonymous_union_member_redecl : Error< - "member of anonymous union redeclares %0">; -def err_anonymous_struct_member_redecl : Error< - "member of anonymous struct redeclares %0">; +def err_anonymous_record_member_redecl : Error< + "member of anonymous %select{struct|union}0 redeclares %1">; def err_anonymous_record_with_type : Error< "types cannot be declared in an anonymous %select{struct|union}0">; def ext_anonymous_record_with_type : Extension< @@ -7033,17 +7030,12 @@ def warn_null_ret : Warning< InGroup; // CHECK: returning address/reference of stack memory -def warn_ret_stack_addr : Warning< - "address of stack memory associated with local variable %0 returned">, - InGroup; -def warn_ret_stack_ref : Warning< - "reference to stack memory associated with local variable %0 returned">, - InGroup; -def warn_ret_local_temp_addr : Warning< - "returning address of local temporary object">, +def warn_ret_stack_addr_ref : Warning< + "%select{address of|reference to}0 stack memory associated with local " + "variable %1 returned">, InGroup; -def warn_ret_local_temp_ref : Warning< - "returning reference to local temporary object">, +def warn_ret_local_temp_addr_ref : Warning< + "returning %select{address of|reference to}0 local temporary object">, InGroup; def warn_ret_addr_label : Warning< "returning address of label, which is local">, diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 24940167be..9e53c478ef 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -5646,17 +5646,15 @@ CheckReturnStackAddr(Sema &S, Expr *RetValExp, QualType lhsType, } if (DeclRefExpr *DR = dyn_cast(stackE)) { //address of local var. - S.Diag(diagLoc, lhsType->isReferenceType() ? diag::warn_ret_stack_ref - : diag::warn_ret_stack_addr) + S.Diag(diagLoc, diag::warn_ret_stack_addr_ref) << lhsType->isReferenceType() << DR->getDecl()->getDeclName() << diagRange; } else if (isa(stackE)) { // local block. S.Diag(diagLoc, diag::err_ret_local_block) << diagRange; } else if (isa(stackE)) { // address of label. S.Diag(diagLoc, diag::warn_ret_addr_label) << diagRange; } else { // local temporary. - S.Diag(diagLoc, lhsType->isReferenceType() ? diag::warn_ret_local_temp_ref - : diag::warn_ret_local_temp_addr) - << diagRange; + S.Diag(diagLoc, diag::warn_ret_local_temp_addr_ref) + << lhsType->isReferenceType() << diagRange; } // Display the "trail" of reference variables that we followed until we diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 5215a7e0dc..47851a1844 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3913,7 +3913,7 @@ static bool CheckAnonMemberRedeclaration(Sema &SemaRef, DeclContext *Owner, DeclarationName Name, SourceLocation NameLoc, - unsigned diagnostic) { + bool IsUnion) { LookupResult R(SemaRef, Name, NameLoc, Sema::LookupMemberName, Sema::ForRedeclaration); if (!SemaRef.LookupName(R, S)) return false; @@ -3928,7 +3928,8 @@ static bool CheckAnonMemberRedeclaration(Sema &SemaRef, if (!SemaRef.isDeclInScope(PrevDecl, Owner, S)) return false; - SemaRef.Diag(NameLoc, diagnostic) << Name; + SemaRef.Diag(NameLoc, diag::err_anonymous_record_member_redecl) + << IsUnion << Name; SemaRef.Diag(PrevDecl->getLocation(), diag::note_previous_declaration); return true; @@ -3956,10 +3957,6 @@ static bool InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, AccessSpecifier AS, SmallVectorImpl &Chaining, bool MSAnonStruct) { - unsigned diagKind - = AnonRecord->isUnion() ? diag::err_anonymous_union_member_redecl - : diag::err_anonymous_struct_member_redecl; - bool Invalid = false; // Look every FieldDecl and IndirectFieldDecl with a name. @@ -3968,7 +3965,8 @@ static bool InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, cast(D)->getDeclName()) { ValueDecl *VD = cast(D); if (CheckAnonMemberRedeclaration(SemaRef, S, Owner, VD->getDeclName(), - VD->getLocation(), diagKind)) { + VD->getLocation(), + AnonRecord->isUnion())) { // C++ [class.union]p2: // The names of the members of an anonymous union shall be // distinct from the names of any other entity in the diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 8cd26c64ef..5efd30f6ef 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -7575,13 +7575,12 @@ static void DiagnoseBadDivideOrRemainderValues(Sema& S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsDiv) { // Check for division/remainder by zero. - unsigned Diag = (IsDiv) ? diag::warn_division_by_zero : - diag::warn_remainder_by_zero; llvm::APSInt RHSValue; if (!RHS.get()->isValueDependent() && RHS.get()->EvaluateAsInt(RHSValue, S.Context) && RHSValue == 0) S.DiagRuntimeBehavior(Loc, RHS.get(), - S.PDiag(Diag) << RHS.get()->getSourceRange()); + S.PDiag(diag::warn_remainder_division_by_zero) + << IsDiv << RHS.get()->getSourceRange()); } QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS, -- 2.40.0