[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:53:08 PST 2026
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/180681
>From 2c627c9a3b0adfdcfac02e325cf07717b1099406 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 | 5 +++++
clang/test/AST/ByteCode/invalid.cpp | 3 +++
2 files changed, 8 insertions(+)
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp
index fb9202c6d66c8..8b496c5663ae6 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -937,6 +937,11 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx,
llvm_unreachable("invalid value to return");
};
+ // Can't return functions as rvalues.
+ if (ResultType->isFunctionType() || 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