diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2798,7 +2798,7 @@ if (Info.checkingForUndefinedBehavior()) Info.Ctx.getDiagnostics().Report(E->getExprLoc(), diag::warn_integer_constant_overflow) - << toString(Result, 10) << E->getType(); + << toString(Result, 10) << E->getType() << E->getSourceRange(); return HandleOverflow(Info, E, Value, E->getType()); } return true; @@ -13643,7 +13643,7 @@ if (Info.checkingForUndefinedBehavior()) Info.Ctx.getDiagnostics().Report(E->getExprLoc(), diag::warn_integer_constant_overflow) - << toString(Value, 10) << E->getType(); + << toString(Value, 10) << E->getType() << E->getSourceRange(); if (!HandleOverflow(Info, E, -Value.extend(Value.getBitWidth() + 1), E->getType())) diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -271,7 +271,8 @@ SmallString<32> Trunc; Value.trunc(Result.bitWidth()).toString(Trunc, 10); auto Loc = E->getExprLoc(); - S.report(Loc, diag::warn_integer_constant_overflow) << Trunc << Type; + S.report(Loc, diag::warn_integer_constant_overflow) + << Trunc << Type << E->getSourceRange(); return true; } else { S.CCEDiag(E, diag::note_constexpr_overflow) << Value << Type; @@ -478,7 +479,8 @@ SmallString<32> Trunc; NegatedValue.trunc(Result.bitWidth()).toString(Trunc, 10); auto Loc = E->getExprLoc(); - S.report(Loc, diag::warn_integer_constant_overflow) << Trunc << Type; + S.report(Loc, diag::warn_integer_constant_overflow) + << Trunc << Type << E->getSourceRange(); return true; } @@ -531,7 +533,8 @@ SmallString<32> Trunc; APResult.trunc(Result.bitWidth()).toString(Trunc, 10); auto Loc = E->getExprLoc(); - S.report(Loc, diag::warn_integer_constant_overflow) << Trunc << Type; + S.report(Loc, diag::warn_integer_constant_overflow) + << Trunc << Type << E->getSourceRange(); return true; } diff --git a/clang/test/Misc/constexpr-source-ranges.cpp b/clang/test/Misc/constexpr-source-ranges.cpp --- a/clang/test/Misc/constexpr-source-ranges.cpp +++ b/clang/test/Misc/constexpr-source-ranges.cpp @@ -34,3 +34,10 @@ } static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, ""); // CHECK: constexpr-source-ranges.cpp:35:23:{35:23-35:39} + +namespace overflow { +// CHECK: :{[[@LINE+1]]:9-[[@LINE+1]]:29}: +int x = -1 + __INT_MAX__ + 2 + 3; +// CHECK: :{[[@LINE+1]]:9-[[@LINE+1]]:19}: +int a = -(1 << 31) + 1; +}