https://github.com/Serosh-commits updated 
https://github.com/llvm/llvm-project/pull/176550

>From d6fe22b04c14e22c0bea172321b65cdb0e09ed34 Mon Sep 17 00:00:00 2001
From: Serosh <[email protected]>
Date: Sat, 17 Jan 2026 15:57:11 +0530
Subject: [PATCH 1/2] [clang][bytecode] Fix crash in void functions returning
 non-void expressions

The bytecode compiler was erroneously emitting an RVOPtr opcode for
void functions when they contained a non-void return expression.
This led to an assertion failure in the interpreter.

This fix ensures that discard() is used instead of visit() for such
expressions in void functions, and prevents the emission of RVO pointers.
It checks RE->containsErrors() to handle invalid return expressions
gracefully.

Fixes #176536
---
 clang/lib/AST/ByteCode/Compiler.cpp   | 3 +++
 clang/test/AST/ByteCode/functions.cpp | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 21f8db06919ed..c276ce7a90408 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5682,6 +5682,9 @@ bool Compiler<Emitter>::visitReturnStmt(const ReturnStmt 
*RS) {
       if (!this->visit(RE))
         return false;
     } else {
+      if (RE->containsErrors())
+        return false;
+
       InitLinkScope<Emitter> ILS(this, InitLink::RVO());
       // RVO - construct the value in the return location.
       if (!this->emitRVOPtr(RE))
diff --git a/clang/test/AST/ByteCode/functions.cpp 
b/clang/test/AST/ByteCode/functions.cpp
index 21d3ddaafaee3..6ee9e26aaf245 100644
--- a/clang/test/AST/ByteCode/functions.cpp
+++ b/clang/test/AST/ByteCode/functions.cpp
@@ -735,3 +735,10 @@ namespace PtrPtrCast {
   void foo() { ; }
   void bar(int *a) { a = (int *)(void *)(foo); }
 }
+//the extra test case 
+namespace GH176536 {
+  constexpr void foo(int n) {
+    return n > 1 ? foo(n - 1) : 0; // expected-error {{left operand to ? is 
void, but right operand is of type 'int'}}
+  }
+  static_assert((foo(2), true), ""); // expected-error {{static assertion 
expression is not an integral constant expression}}
+}

>From 09d67e69250dc43160f9f533b6247cad8a22a055 Mon Sep 17 00:00:00 2001
From: Serosh <[email protected]>
Date: Mon, 26 Jan 2026 21:43:03 +0530
Subject: [PATCH 2/2] Fix missing closing brace in functions.cpp test

---
 clang/test/AST/ByteCode/functions.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/test/AST/ByteCode/functions.cpp 
b/clang/test/AST/ByteCode/functions.cpp
index 9067924c87b55..5540ce0baf4bf 100644
--- a/clang/test/AST/ByteCode/functions.cpp
+++ b/clang/test/AST/ByteCode/functions.cpp
@@ -740,6 +740,7 @@ namespace GH176536 {
     return n > 1 ? foo(n - 1) : 0; // both-error {{left operand to ? is void, 
but right operand is of type 'int'}}
   }
   static_assert((foo(2), true), ""); // both-error {{static assertion 
expression is not an integral constant expression}}
+}
 
 namespace NestedDiags {
   constexpr int foo() { // both-error {{never produces a constant expression}}

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

Reply via email to