[clang] [ConstEval] Fix crash when comparing strings past the end (PR #137078)
Henrik G. Olsson via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 23 16:39:47 PDT 2025
================
@@ -119,6 +119,15 @@ constexpr auto b3 = name1() == name1(); // ref-error {{must be initialized by a
constexpr auto b4 = name1() == name2();
static_assert(!b4);
+constexpr auto bar(const char *p) { return p + __builtin_strlen(p); }
+constexpr auto b5 = bar(p1) == p1;
+static_assert(!b5);
+constexpr auto b6 = bar(p1) == ""; // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{comparison of addresses of potentially overlapping literals}}
+constexpr auto b7 = bar(p1) + 1 == ""; // both-error {{must be initialized by a constant expression}} \
+ // ref-note {{comparison against pointer '&"test1"[6]' that points past the end of a complete object has unspecified value}} \
+ // expected-note {{comparison against pointer '&"test1"[6] + 1' that points past the end of a complete object has unspecified value}}
----------------
hnrklssn wrote:
@tbaederr Not sure what causes the `&"test1"[6]'` vs `&"test1"[6]' + 1` discrepancy, but I thought I'd highlight it in case it isn't a known issue
https://github.com/llvm/llvm-project/pull/137078
More information about the cfe-commits
mailing list