https://github.com/PlutoDog95 created 
https://github.com/llvm/llvm-project/pull/196744

Summary

Avoid infinite recursion during variadic argument promotion of volatile
class types.

Clang could previously recurse indefinitely while attempting copy
initialization for variadic constructor arguments involving volatile
class objects, eventually crashing with stack exhaustion.

The recursion occurred when DefaultArgumentPromotion attempted to
materialize a temporary through PerformCopyInitialization, which
re-entered variadic argument promotion for the same type.

This patch prevents the recursive initialization path for volatile
qualified class types and adds a regression test covering the crash.


>From ad247c6fec263266ed206fb6eb4503751a8a71fc Mon Sep 17 00:00:00 2001
From: Vineet Agarwal <[email protected]>
Date: Sat, 9 May 2026 23:34:40 +0530
Subject: [PATCH] [clang] Avoid recursion during variadic promotion of volatile
 class types

Avoid recursive copy initialization when performing variadic
argument promotion on volatile class types.

Previously Clang could recurse indefinitely and crash with
stack exhaustion while handling variadic constructor calls.

Add a regression test for the issue.
---
 clang/lib/Sema/SemaExpr.cpp                      |  4 +++-
 clang/test/SemaCXX/volatile-vararg-recursion.cpp | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/volatile-vararg-recursion.cpp

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 98062afae4577..19f0b961a6fe7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -935,7 +935,9 @@ ExprResult Sema::DefaultArgumentPromotion(Expr *E) {
   //     is a prvalue for the temporary.
   // FIXME: add some way to gate this entire thing for correctness in
   // potentially potentially evaluated contexts.
-  if (getLangOpts().CPlusPlus && E->isGLValue() && !isUnevaluatedContext()) {
+  if (getLangOpts().CPlusPlus && E->isGLValue() &&
+      !isUnevaluatedContext() &&
+      !E->getType().isVolatileQualified()) {
     ExprResult Temp = PerformCopyInitialization(
                        InitializedEntity::InitializeTemporary(E->getType()),
                                                 E->getExprLoc(), E);
diff --git a/clang/test/SemaCXX/volatile-vararg-recursion.cpp 
b/clang/test/SemaCXX/volatile-vararg-recursion.cpp
new file mode 100644
index 0000000000000..cf3490baccdd4
--- /dev/null
+++ b/clang/test/SemaCXX/volatile-vararg-recursion.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace cwg535 {
+class X {
+  X(const X &);
+};
+
+struct B {
+  X y;
+  B(...);
+};
+
+extern volatile B b1;
+B b2(b1); // expected-error {{cannot pass object of non-trivial type 'volatile 
B' through variadic constructor; call will abort at runtime}}
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to