Skip to content

Commit 63eba2f

Browse files
committed
Address review comments
1 parent 32892b6 commit 63eba2f

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,18 @@ def note_constexpr_pointer_subtraction_not_same_array : Note<
9090
def note_constexpr_pointer_subtraction_zero_size : Note<
9191
"subtraction of pointers to type %0 of zero size">;
9292
def note_constexpr_pointer_comparison_unspecified : Note<
93-
"comparison between '%0' and '%1' has unspecified value">;
93+
"comparison between pointers to unrelated objects '%0' and '%1' has unspecified value">;
9494
def note_constexpr_pointer_arith_unspecified : Note<
95-
"arithmetic involving '%0' and '%1' has unspecified value">;
95+
"arithmetic involving unrelated objects '%0' and '%1' has unspecified value">;
9696
def note_constexpr_pointer_constant_comparison : Note<
9797
"comparison of numeric address '%0' with pointer '%1' can only be performed "
9898
"at runtime">;
9999
def note_constexpr_literal_comparison : Note<
100-
"comparison of addresses of literals has unspecified value">;
100+
"comparison of addresses of potentially overlapping literals has unspecified value">;
101101
def note_constexpr_literal_arith : Note<
102-
"arithmetic on addresses of literals has unspecified value">;
102+
"arithmetic on addresses of potentially overlapping literals has unspecified value">;
103+
def note_constexpr_repeated_literal_eval : Note<
104+
"repeated evaluation of the same literal expression can produce different objects">;
103105
def note_constexpr_opaque_call_comparison : Note<
104106
"comparison against opaque constant address '%0' can only be performed at "
105107
"runtime">;

clang/lib/AST/ExprConstant.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14600,20 +14600,23 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
1460014600
return Error(E);
1460114601
const Expr *LHSExpr = LHSValue.Base.dyn_cast<const Expr *>();
1460214602
const Expr *RHSExpr = RHSValue.Base.dyn_cast<const Expr *>();
14603-
if (!LHSExpr || !RHSExpr) {
14604-
std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
14605-
std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
14606-
Info.FFDiag(E, diag::note_constexpr_pointer_arith_unspecified)
14607-
<< LHS << RHS;
14608-
return false;
14609-
}
1461014603

14611-
if (ArePotentiallyOverlappingStringLiterals(Info, LHSValue, RHSValue)) {
14612-
std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
14613-
std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
14614-
Info.FFDiag(E, diag::note_constexpr_literal_arith) << LHS << RHS;
14604+
auto DiagArith = [&](unsigned DiagID) {
14605+
std::string LHS = LHSValue.toString(Info.Ctx, LHSExpr->getType());
14606+
std::string RHS = RHSValue.toString(Info.Ctx, RHSExpr->getType());
14607+
Info.FFDiag(E, DiagID) << LHS << RHS;
14608+
if (LHSExpr && LHSExpr == RHSExpr)
14609+
Info.Note(LHSExpr->getExprLoc(),
14610+
diag::note_constexpr_repeated_literal_eval)
14611+
<< LHSExpr->getSourceRange();
1461514612
return false;
14616-
}
14613+
};
14614+
14615+
if (!LHSExpr || !RHSExpr)
14616+
return DiagArith(diag::note_constexpr_pointer_arith_unspecified);
14617+
14618+
if (ArePotentiallyOverlappingStringLiterals(Info, LHSValue, RHSValue))
14619+
return DiagArith(diag::note_constexpr_literal_arith);
1461714620

1461814621
const AddrLabelExpr *LHSAddrExpr = dyn_cast<AddrLabelExpr>(LHSExpr);
1461914622
const AddrLabelExpr *RHSAddrExpr = dyn_cast<AddrLabelExpr>(RHSExpr);

0 commit comments

Comments
 (0)