[clang] [clang][bytecode] Fix assertion failure when returning function type (PR #180681)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 10 00:26:38 PST 2026
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/180681
>From efa56e9365044fdd9a5fa408cc86a2738cfa134a 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 8c641a20a0bd4..4979e52e0d666 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -170,3 +170,6 @@ constexpr int invalidUnaryOrTypeTrait() {
}
static_assert(invalidUnaryOrTypeTrait() == 11, ""); // both-error {{not an integral constant expression}}
+
+/// Pointer::toRValue() of a function type.
+void foo() { *(void (*)()) ""; } // both-warning {{expression result unused}}
More information about the cfe-commits
mailing list