From cf24393421ca807899c599a53ddc5dcedb7c71dc Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 14 Jun 2023 20:49:59 +0200 Subject: [PATCH] Merge commit 69d42eef4bec from llvm-project (by Dimitry Andric): [Clang] Show type in enum out of range diagnostic When the diagnostic for an out of range enum value is printed, it currently does not show the actual enum type in question, for example: v8/src/base/bit-field.h:43:29: error: integer value 7 is outside the valid range of values [0, 3] for this enumeration type [-Wenum-constexpr-conversion] static constexpr T kMax = static_cast(kNumValues - 1); ^ This can make it cumbersome to find the cause for the problem. Add the enum type to the diagnostic message, to make it easier. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D152788 PR: 271047 MFC after: 1 month --- .../clang/include/clang/Basic/DiagnosticASTKinds.td | 4 ++-- contrib/llvm-project/clang/lib/AST/ExprConstant.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/contrib/llvm-project/clang/include/clang/Basic/DiagnosticASTKinds.td b/contrib/llvm-project/clang/include/clang/Basic/DiagnosticASTKinds.td index 28120d13fd9e..4e2e0bd3079c 100644 --- a/contrib/llvm-project/clang/include/clang/Basic/DiagnosticASTKinds.td +++ b/contrib/llvm-project/clang/include/clang/Basic/DiagnosticASTKinds.td @@ -393,8 +393,8 @@ def warn_fixedpoint_constant_overflow : Warning< "overflow in expression; result is %0 with type %1">, InGroup>; def warn_constexpr_unscoped_enum_out_of_range : Warning< - "integer value %0 is outside the valid range of values [%1, %2] for this " - "enumeration type">, DefaultError, InGroup>; + "integer value %0 is outside the valid range of values [%1, %2] for the " + "enumeration type %3">, DefaultError, InGroup>; // This is a temporary diagnostic, and shall be removed once our // implementation is complete, and like the preceding constexpr notes belongs diff --git a/contrib/llvm-project/clang/lib/AST/ExprConstant.cpp b/contrib/llvm-project/clang/lib/AST/ExprConstant.cpp index 464104139cb2..db6c07d4ab7f 100644 --- a/contrib/llvm-project/clang/lib/AST/ExprConstant.cpp +++ b/contrib/llvm-project/clang/lib/AST/ExprConstant.cpp @@ -13682,12 +13682,13 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) { Info.Ctx.getDiagnostics().Report( E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range) << llvm::toString(Result.getInt(), 10) << Min.getSExtValue() - << Max.getSExtValue(); + << Max.getSExtValue() << ED; else if (!ED->getNumNegativeBits() && ConstexprVar && Max.ult(Result.getInt().getZExtValue())) - Info.Ctx.getDiagnostics().Report(E->getExprLoc(), - diag::warn_constexpr_unscoped_enum_out_of_range) - << llvm::toString(Result.getInt(),10) << Min.getZExtValue() << Max.getZExtValue(); + Info.Ctx.getDiagnostics().Report( + E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range) + << llvm::toString(Result.getInt(), 10) << Min.getZExtValue() + << Max.getZExtValue() << ED; } }