[clang] a62d8e0 - [clang][bytecode] Reject functions with invalid parameters (#207157)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 2 06:45:01 PDT 2026
Author: Timm Baeder
Date: 2026-07-02T15:44:56+02:00
New Revision: a62d8e068fe04e9edc870f184d7ed635811eb1f1
URL: https://github.com/llvm/llvm-project/commit/a62d8e068fe04e9edc870f184d7ed635811eb1f1
DIFF: https://github.com/llvm/llvm-project/commit/a62d8e068fe04e9edc870f184d7ed635811eb1f1.diff
LOG: [clang][bytecode] Reject functions with invalid parameters (#207157)
They will just cause problems later when calling them.
Added:
Modified:
clang/lib/AST/ByteCode/Context.cpp
clang/test/AST/ByteCode/cxx23.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp
index 92a2ba57e08bf..4ca76ce3669d3 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -680,7 +680,8 @@ const Function *Context::getOrCreateFunction(const FunctionDecl *FuncDecl) {
bool IsConst = PD->getType().isConstQualified();
bool IsVolatile = PD->getType().isVolatileQualified();
- if (!getASTContext().hasSameType(PD->getType(),
+ if (PD->isInvalidDecl() ||
+ !getASTContext().hasSameType(PD->getType(),
FuncProto->getParamType(ParamIndex)))
return nullptr;
diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp
index ba7db75a589a1..5607ec9b59cb5 100644
--- a/clang/test/AST/ByteCode/cxx23.cpp
+++ b/clang/test/AST/ByteCode/cxx23.cpp
@@ -268,8 +268,11 @@ namespace ExplicitLambdaInstancePointer {
};
constexpr auto b = [](this K) { return 1; }; // all20-error {{explicit object parameters are incompatible with C++ standards before C++2b}} \
// all-error {{unknown type name 'K'}}
- constexpr int (*fp)(K) = b; // all-error {{unknown type name 'K'}}
- static_assert(fp(1) == 1, ""); // expected-error {{not an integral constant expression}}
+ constexpr int (*fp)(K) = b; // all-error {{unknown type name 'K'}} \
+ // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{declared here}}
+ static_assert(fp(1) == 1, ""); // expected-error {{not an integral constant expression}} \
+ // expected-note {{initializer of 'fp' is not a constant expression}}
}
namespace TwosComplementShifts {
@@ -658,4 +661,10 @@ namespace BrokenShuffleVector {
constexpr __m128 kf1{1.0f, 2.0f, 3.0f, 4.0f};
constexpr __m128 v_mm_cvtps_pd = _mm_cvtps_pd(kf1); // all-error {{must be initialized by a constant expression}}
}
+
+namespace BrokenExplicitInstanceParam {
+ auto b = [](this C) { return 1; }; // all-error {{unknown type name 'C'}}
+ static_assert( (&decltype(b)::operator())(1) == 1); // expected-error {{not an integral constant expression}}
+}
+
#endif
More information about the cfe-commits
mailing list