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

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 24 08:28:55 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

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

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

---
Full diff: https://github.com/llvm/llvm-project/pull/165000.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2) 
- (modified) clang/test/AST/ByteCode/cxx11.cpp (+9) 


``````````diff
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<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}}
+  }
+}
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/165000


More information about the cfe-commits mailing list