Author: Timm Baeder Date: 2026-05-30T14:54:08+02:00 New Revision: d46e7dcee756766e9f23dd2ce3179e5e9a6cd536
URL: https://github.com/llvm/llvm-project/commit/d46e7dcee756766e9f23dd2ce3179e5e9a6cd536 DIFF: https://github.com/llvm/llvm-project/commit/d46e7dcee756766e9f23dd2ce3179e5e9a6cd536.diff LOG: [clang][bytecode] Fix an assertion failure in AddSubNonNumber (#200393) Calling Integral::getPtr() shouldn't happen for AddrLabelDiff integrals. Added: Modified: clang/lib/AST/ByteCode/Interp.h clang/test/AST/ByteCode/c.c Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index ef6619b7e2536..86795e13a14ff 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -362,12 +362,18 @@ static bool AddSubNonNumber(InterpState &S, CodePtr OpPC, T LHS, T RHS) { typename T::ReprT Offset; IntegralKind Kind; if (LHS.isNumber()) { + if (RHS.getKind() == IntegralKind::AddrLabelDiff) + return Invalid(S, OpPC); + Number = static_cast<typename T::ReprT>(LHS); Ptr = RHS.getPtr(); Offset = RHS.getOffset(); Kind = RHS.getKind(); } else { assert(RHS.isNumber()); + if (LHS.getKind() == IntegralKind::AddrLabelDiff) + return Invalid(S, OpPC); + Number = static_cast<typename T::ReprT>(RHS); Ptr = LHS.getPtr(); Offset = LHS.getOffset(); diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c index e82336e9731ba..4c39299db5ffa 100644 --- a/clang/test/AST/ByteCode/c.c +++ b/clang/test/AST/ByteCode/c.c @@ -466,3 +466,11 @@ void evaluatevalue(void) { const struct Oops s = {0, 0.}; *(int *)(&s.a) = 42; // all-warning {{cast from 'const int *' to 'int *' drops const qualifier}} } + +void AddrLabelDiffSub(void) { + _Static_assert((long)&&bar - (long)&&baz - 42 == foo, ""); // all-warning {{comparison between pointer and integer ('long' and 'int (*)()')}} \ + // all-error {{not an integral constant expression}} \ + // all-error {{use of undeclared label 'bar'}} \ + // all-error {{use of undeclared label 'baz'}} \ + // pedantic-warning 2{{use of GNU address-of-label extension}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
