Author: rtrieu Date: Wed Aug 7 18:45:31 2019 New Revision: 368244 URL: http://llvm.org/viewvc/llvm-project?rev=368244&view=rev Log: Inline diagnostic text into .td file. NFC.
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=368244&r1=368243&r2=368244&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Aug 7 18:45:31 2019 @@ -8150,7 +8150,8 @@ def warn_unsupported_lifetime_extension // should result in a warning, since these always evaluate to a constant. // Array comparisons have similar warnings def warn_comparison_always : Warning< - "%select{self-|array }0comparison always evaluates to %select{a constant|%2}1">, + "%select{self-|array }0comparison always evaluates to " + "%select{a constant|true|false|'std::strong_ordering::equal'}1">, InGroup<TautologicalCompare>; def warn_comparison_bitwise_always : Warning< "bitwise comparison always evaluates to %select{false|true}0">, Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=368244&r1=368243&r2=368244&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Aug 7 18:45:31 2019 @@ -10174,45 +10174,55 @@ static void diagnoseTautologicalComparis // result. ValueDecl *DL = getCompareDecl(LHSStripped); ValueDecl *DR = getCompareDecl(RHSStripped); + + // Used for indexing into %select in warn_comparison_always + enum { + AlwaysConstant, + AlwaysTrue, + AlwaysFalse, + AlwaysEqual, // std::strong_ordering::equal from operator<=> + }; if (DL && DR && declaresSameEntity(DL, DR)) { - StringRef Result; + unsigned Result; switch (Opc) { case BO_EQ: case BO_LE: case BO_GE: - Result = "true"; + Result = AlwaysTrue; break; case BO_NE: case BO_LT: case BO_GT: - Result = "false"; + Result = AlwaysFalse; break; case BO_Cmp: - Result = "'std::strong_ordering::equal'"; + Result = AlwaysEqual; break; default: + Result = AlwaysConstant; break; } S.DiagRuntimeBehavior(Loc, nullptr, S.PDiag(diag::warn_comparison_always) - << 0 /*self-comparison*/ << !Result.empty() + << 0 /*self-comparison*/ << Result); } else if (DL && DR && DL->getType()->isArrayType() && DR->getType()->isArrayType() && !DL->isWeak() && !DR->isWeak()) { // What is it always going to evaluate to? - StringRef Result; + unsigned Result; switch(Opc) { case BO_EQ: // e.g. array1 == array2 - Result = "false"; + Result = AlwaysFalse; break; case BO_NE: // e.g. array1 != array2 - Result = "true"; + Result = AlwaysTrue; break; default: // e.g. array1 <= array2 // The best we can say is 'a constant' + Result = AlwaysConstant; break; } S.DiagRuntimeBehavior(Loc, nullptr, S.PDiag(diag::warn_comparison_always) << 1 /*array comparison*/ - << !Result.empty() << Result); + << Result); } if (isa<CastExpr>(LHSStripped)) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits