https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/205070
Make sure it's initialized and that it points to a record. >From da4aec5b663ee8633749cbcbff694d8aaa5f0fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Mon, 22 Jun 2026 10:57:18 +0200 Subject: [PATCH] asdf --- clang/lib/AST/ByteCode/Interp.cpp | 6 ++++-- clang/test/AST/ByteCode/dynamic-cast.cpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index b022d71ae1e49..106ca1b9e789e 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -2019,10 +2019,12 @@ bool DynamicCast(InterpState &S, CodePtr OpPC, const Type *DestTypePtr, return false; } - // TODO: Other checks? - if (!Ptr.isBlockPointer()) + if (!Ptr.isBlockPointer() || !Ptr.getRecord()) return false; + if (!Ptr.isInitialized()) + return DiagnoseUninitialized(S, OpPC, Ptr, AK_Read); + // Our given pointer, limited by the base that's currently being initialized, // if any. PtrView LimitedPtr; diff --git a/clang/test/AST/ByteCode/dynamic-cast.cpp b/clang/test/AST/ByteCode/dynamic-cast.cpp index b782920eb8763..a40b455cecabf 100644 --- a/clang/test/AST/ByteCode/dynamic-cast.cpp +++ b/clang/test/AST/ByteCode/dynamic-cast.cpp @@ -294,3 +294,19 @@ namespace UnrelatedAndRootPtr{ } static_assert(f()); } + +namespace Invalid { + struct S { virtual void s(); }; + struct A : S {}; + struct B : A {}; + constexpr __UINTPTR_TYPE__ g = 0; + static_assert(&dynamic_cast<A&>((S&)(B&)g) == &(A&)(B&)g); // both-error {{not an integral constant expression}} \ + // both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}} + + struct X : S { : ; }; // both-error {{expected expression}} \ + // both-error {{a type specifier is required for all declarations}} + constexpr X x; // both-error {{must be initialized by a constant expression}} \ + // both-note {{declared here}} + static_assert(&dynamic_cast<S&>((X&)x), ""); // both-error {{not an integral constant expression}} \ + // both-note {{initializer of 'x' is not a constant expression}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
