llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> ... as an rvalue. Which can't work, so reject. --- Full diff: https://github.com/llvm/llvm-project/pull/180681.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Pointer.cpp (+6) - (modified) clang/test/AST/ByteCode/invalid.cpp (+3) ``````````diff 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}} `````````` </details> https://github.com/llvm/llvm-project/pull/180681 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
