https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/200393
Calling Integral::getPtr() shouldn't happen for AddrLabelDiff integrals. >From 7f781d08d66d652e4e15a7781b1cc52ec6582d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Fri, 29 May 2026 14:58:39 +0200 Subject: [PATCH] [clang][bytecode] Fix an assertion failure in AddSubNonNumber Calling Integral::getPtr() shouldn't happen for AddrLabelDiff integrals. --- clang/lib/AST/ByteCode/Interp.h | 6 ++++++ clang/test/AST/ByteCode/c.c | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index a255a1fdf6f16..9300df85661dd 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -361,12 +361,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
