[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 21:47:03 PST 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/180681
... as an rvalue. Which can't work, so reject.
>From db40f659781693d193a7e9c83b3847c7ddf61d21 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 c8298fa2c2b9b..bd4b226815c9c 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -151,3 +151,6 @@ namespace NullRecord {
};
S2 s = S2();
}
+
+/// Pointer::toRValue() of a function type.
+void foo() { *(void (*)()) ""; } // both-warning {{expression result unused}}
More information about the cfe-commits
mailing list