[clang] [clang][bytecode] Fix assertion failure when returning function type (PR #180681)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 9 23:59:03 PST 2026


https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/180681

>From 733c4acba794b12fc0dd3f49213e1a36ca5c4ace Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 10 Feb 2026 06:44:06 +0100
Subject: [PATCH] [clang][bytecode] Fix assertion failure when returning
 function type

... as an rvalue. Which can't work, so reject.
---
 clang/lib/AST/ByteCode/Pointer.cpp  | 6 ++++++
 clang/test/AST/ByteCode/invalid.cpp | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp
index fb9202c6d66c8..c9eb6c9c986c5 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -937,6 +937,12 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx,
     llvm_unreachable("invalid value to return");
   };
 
+  // Can't return functions as rvalues.
+  if (ResultType->isFunctionType() || ResultType->isFunctionProtoType() ||
+      ResultType->isFunctionPointerType() ||
+      ResultType->isFunctionReferenceType())
+    return std::nullopt;
+
   // Invalid to read from.
   if (isDummy() || !isLive() || isPastEnd())
     return std::nullopt;
diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp
index f7d11a9be3f8e..6b98b2e9970af 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -164,3 +164,6 @@ namespace NamedLoops {
     } while (0);
   }
 }
+
+/// Pointer::toRValue() of a function type.
+void foo() { *(void (*)()) ""; } // both-warning {{expression result unused}}



More information about the cfe-commits mailing list