[clang] [CIR] Keep conditional cleanup scopes open during deactivation (PR #234303)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 11:58:49 PST 2026
================
@@ -766,3 +766,338 @@ void test_flag_cleared_before_cond_cleanup() {
// OGCG: call void @_ZN7PayloadD1Ev(ptr {{.*}} %[[AGG_TMP]])
// OGCG: call void @_ZN5GuardD1Ev(ptr {{.*}} %[[REF_TMP]])
// OGCG: resume { ptr, i32 }
+
+// The members that an aggregate initialization has constructed so far are
+// destroyed when a later member initializer is left early, here by a return
+// in a statement expression in an operand of a conditional operator. The
+// member cleanups are deactivated at the end of the initialization, while the
+// cleanup scope that the conditional operator opened for its operands is still
+// open: the flag that guards the cleanup of the first member is cleared inside
+// that scope.
+
+struct Obj {
+ char c;
+ Obj(char);
+ ~Obj();
+};
+
+struct Pair {
+ Obj a;
+ Obj b;
+};
+
+Obj copy(const Obj &);
+Obj make(bool);
+
+void struct_ternary(bool b, bool c) {
+ Pair p{Obj{'a'}, b ? ({
+ if (c)
+ return;
+ Obj{'b'};
+ })
+ : Obj{'c'}};
+}
+
+// The cleanup scope of the conditional operator is empty and canonicalized
+// away.
+//
+// CIR-LABEL: cir.func {{.*}} @_Z14struct_ternarybb(
----------------
andykaylor wrote:
No LLVM checks for this?
https://github.com/llvm/llvm-project/pull/234303
More information about the cfe-commits
mailing list