Author: Timm Baeder Date: 2025-04-17T17:27:19+02:00 New Revision: ecbd2d5e148cc1f2e5795d13d752e2a1c79cce1a
URL: https://github.com/llvm/llvm-project/commit/ecbd2d5e148cc1f2e5795d13d752e2a1c79cce1a DIFF: https://github.com/llvm/llvm-project/commit/ecbd2d5e148cc1f2e5795d13d752e2a1c79cce1a.diff LOG: [clang][ExprConst] Diagnose ptr subs with non-zero offset (#135938) The attached test case was missing the note. Added: Modified: clang/lib/AST/ExprConstant.cpp clang/test/AST/ByteCode/arrays.cpp clang/test/SemaCXX/constant-expression-cxx11.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index d1cc722fb7945..b14ff21a8ebc2 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -14764,9 +14764,6 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { // Reject diff ering bases from the normal codepath; we special-case // comparisons to null. if (!HasSameBase(LHSValue, RHSValue)) { - // Handle &&A - &&B. - if (!LHSValue.Offset.isZero() || !RHSValue.Offset.isZero()) - return Error(E); const Expr *LHSExpr = LHSValue.Base.dyn_cast<const Expr *>(); const Expr *RHSExpr = RHSValue.Base.dyn_cast<const Expr *>(); diff --git a/clang/test/AST/ByteCode/arrays.cpp b/clang/test/AST/ByteCode/arrays.cpp index f60cc19b09bd2..e50839e0f0877 100644 --- a/clang/test/AST/ByteCode/arrays.cpp +++ b/clang/test/AST/ByteCode/arrays.cpp @@ -107,7 +107,7 @@ static_assert(k1 == 1, ""); static_assert((&arr[0] - &arr[1]) == -1, ""); constexpr int k2 = &arr2[1] - &arr[0]; // both-error {{must be initialized by a constant expression}} \ - // expected-note {{arithmetic involving unrelated objects}} + // both-note {{arithmetic involving unrelated objects}} static_assert((arr + 0) == arr, ""); static_assert(&arr[0] == arr, ""); diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index c35f3a5632a05..28016da925ef9 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -409,6 +409,10 @@ constexpr int a = 0; constexpr int b = 1; constexpr int n = &b - &a; // expected-error {{must be initialized by a constant expression}} \ // expected-note {{arithmetic involving unrelated objects '&b' and '&a' has unspecified value}} +constexpr static int arrk[2] = {1,2}; +constexpr static int arrk2[2] = {3,4}; +constexpr int k2 = &arrk[1] - &arrk2[0]; // expected-error {{must be initialized by a constant expression}} \ + // expected-note {{arithmetic involving unrelated objects}} namespace MaterializeTemporary { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits