[clang] 116c6b5 - [clang][bytecode] Add missing condition scope to CXXForRangeStmt (#221520)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 5 23:35:30 PDT 2026
Author: Timm Baeder
Date: 2026-09-06T08:35:25+02:00
New Revision: 116c6b570347e601bd0769b9354fca9f94f3a5fe
URL: https://github.com/llvm/llvm-project/commit/116c6b570347e601bd0769b9354fca9f94f3a5fe
DIFF: https://github.com/llvm/llvm-project/commit/116c6b570347e601bd0769b9354fca9f94f3a5fe.diff
LOG: [clang][bytecode] Add missing condition scope to CXXForRangeStmt (#221520)
Fixes https://github.com/llvm/llvm-project/issues/221401
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/initializer_list.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index a541d9b255e54..5ef09d2fcf004 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6939,6 +6939,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);
@@ -6961,6 +6962,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);
+}
More information about the cfe-commits
mailing list