[clang] 9af49ee - [clang][bytecode] Handle discarded AddrLabelExprs properly (#165000)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 27 02:28:14 PDT 2025


Author: Timm Baeder
Date: 2025-10-27T10:28:09+01:00
New Revision: 9af49ee4747e0871f196a643a4e4a362f0e80e43

URL: https://github.com/llvm/llvm-project/commit/9af49ee4747e0871f196a643a4e4a362f0e80e43
DIFF: https://github.com/llvm/llvm-project/commit/9af49ee4747e0871f196a643a4e4a362f0e80e43.diff

LOG: [clang][bytecode] Handle discarded AddrLabelExprs properly (#165000)

emitDummyPtr() doesn't like to be called with DiscardResult set, so
check this first.

Fixes https://github.com/llvm/llvm-project/issues/164979

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/test/AST/ByteCode/cxx11.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index f4ddbf40da951..6c088469a3ca2 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -3948,6 +3948,8 @@ bool Compiler<Emitter>::VisitRecoveryExpr(const RecoveryExpr *E) {
 template <class Emitter>
 bool Compiler<Emitter>::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}}
+  }
+}
+


        


More information about the cfe-commits mailing list