Author: Timm Baeder Date: 2026-02-10T10:54:45+01:00 New Revision: 3230de5e651648ba3ce81094b72311af37c465e4
URL: https://github.com/llvm/llvm-project/commit/3230de5e651648ba3ce81094b72311af37c465e4 DIFF: https://github.com/llvm/llvm-project/commit/3230de5e651648ba3ce81094b72311af37c465e4.diff LOG: [clang][bytecode] Fix assertion failure when returning function type (#180681) ... as an rvalue. Which can't work, so reject. Added: Modified: clang/lib/AST/ByteCode/Pointer.cpp clang/test/AST/ByteCode/invalid.cpp Removed: ################################################################################ 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}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
