[clang] [clang][bytecode] Add missing condition scope to CXXForRangeStmt (PR #221520)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 5 21:15:14 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Fixes https://github.com/llvm/llvm-project/issues/221401
---
Full diff: https://github.com/llvm/llvm-project/pull/221520.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3)
- (modified) clang/test/AST/ByteCode/initializer_list.cpp (+26-1)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 03f9478a6e4e0..4572c3a8307d6 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6940,6 +6940,7 @@ bool Compiler<Emitter>::visitCXXForRangeStmt(const CXXForRangeStmt *S) {
if (!this->visitStmt(EndStmt))
return false;
+ LocalScope<Emitter> CondScope(this);
// Now the condition as well as the loop variable assignment.
this->fallthrough(CondLabel);
this->emitLabel(CondLabel);
@@ -6962,6 +6963,8 @@ bool Compiler<Emitter>::visitCXXForRangeStmt(const CXXForRangeStmt *S) {
return false;
}
+ if (!CondScope.destroyLocals())
+ return false;
if (!this->jump(CondLabel, S))
return false;
diff --git a/clang/test/AST/ByteCode/initializer_list.cpp b/clang/test/AST/ByteCode/initializer_list.cpp
index f882e4ff1b124..b3adefc580cc3 100644
--- a/clang/test/AST/ByteCode/initializer_list.cpp
+++ b/clang/test/AST/ByteCode/initializer_list.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions -std=c++20 -verify=expected,both %s
-// RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref,both %s
+// RUN: %clang_cc1 -fms-extensions -std=c++20 -verify=ref,both %s
namespace std {
typedef decltype(sizeof(int)) size_t;
@@ -68,4 +68,29 @@ namespace rdar13395022 {
}
}
+namespace CopiedForRangeIterator {
+ struct holder {
+ int *p = nullptr;
+ constexpr holder() {
+ p = new int;
+ }
+ constexpr holder(holder&&) {
+ delete p;
+ p = new int;
+ }
+ constexpr holder(const holder&) {
+ delete p;
+ p = new int;
+ }
+ constexpr ~holder() {
+ delete p;
+ }
+ };
+ constexpr int copies() {
+ for (holder h : {holder(), holder()}) {
+ }
+ return 0;
+ }
+ static_assert(copies() == 0);
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/221520
More information about the cfe-commits
mailing list