From be3e4875d65309e391c8016b3d340700e8c2e457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 24 Oct 2025 17:27:10 +0200 Subject: [PATCH] [clang][bytecode] Handle discarded AddrLabelExprs properly emitDummyPtr() doesn't like to be called with DiscardResult set, so check this first. Fixes https://github.com/llvm/llvm-project/issues/164979 --- clang/lib/AST/ByteCode/Compiler.cpp | 2 ++ clang/test/AST/ByteCode/cxx11.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 836d22f6e5389..9d73c1ecfacdd 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -3942,6 +3942,8 @@ bool Compiler::VisitRecoveryExpr(const RecoveryExpr *E) { template bool Compiler::VisitAddrLabelExpr(const AddrLabelExpr *E) { assert(E->getType()->isVoidPointerType()); + if (DiscardResult) + return true; return this->emitDummyPtr(E, E); } diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp index 8efd3201d6200..427d3a106656b 100644 --- a/clang/test/AST/ByteCode/cxx11.cpp +++ b/clang/test/AST/ByteCode/cxx11.cpp @@ -370,3 +370,12 @@ namespace GH150709 { static_assert((e2[0].*mp)() == 1, ""); // ref-error {{constant expression}} static_assert((g.*mp)() == 1, ""); // ref-error {{constant expression}} } + +namespace DiscardedAddrLabel { + void foo(void) { + L: + *&&L; // both-error {{indirection not permitted}} \ + // both-warning {{expression result unused}} + } +} +