https://github.com/Xinlong-Chen updated https://github.com/llvm/llvm-project/pull/183707
>From 72199cb2586014f14e041a72a8c3a03e4bbbd060 Mon Sep 17 00:00:00 2001 From: xinlongchen <[email protected]> Date: Fri, 27 Feb 2026 16:59:04 +0800 Subject: [PATCH] [clang] fix crash when evaluating __is_bitwise_cloneable on an invalid type --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/Type.cpp | 3 +++ clang/test/SemaCXX/builtin-is-bitwise-cloneable.cpp | 13 +++++++++++++ 3 files changed, 17 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 88023779e4bb7..8f6bd9b90c235 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -341,6 +341,7 @@ Miscellaneous Clang Crashes Fixed - Fixed an assertion when diagnosing address-space qualified ``new``/``delete`` in language-defined address spaces such as OpenCL ``__local``. (#GH178319) - Fixed an assertion failure in ObjC++ ARC when binding a rvalue reference to reference with different lifetimes (#GH178524) - Fixed a crash when subscripting a vector type with large unsigned integer values. (#GH180563) +- Fixed a crash when evaluating ``__is_bitwise_cloneable`` on invalid record types. (#GH183707) OpenACC Specific Changes ------------------------ diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index a85f08753a132..48c02303e9074 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -2934,6 +2934,9 @@ bool QualType::isBitwiseCloneableType(const ASTContext &Context) const { if (!RD) return true; + if (RD->isInvalidDecl()) + return false; + // Never allow memcpy when we're adding poisoned padding bits to the struct. // Accessing these posioned bits will trigger false alarms on // SanitizeAddressFieldPadding etc. diff --git a/clang/test/SemaCXX/builtin-is-bitwise-cloneable.cpp b/clang/test/SemaCXX/builtin-is-bitwise-cloneable.cpp index 1781cf48449f6..a12f85789fb8f 100644 --- a/clang/test/SemaCXX/builtin-is-bitwise-cloneable.cpp +++ b/clang/test/SemaCXX/builtin-is-bitwise-cloneable.cpp @@ -6,3 +6,16 @@ static_assert(__is_bitwise_cloneable(DynamicClass)); struct InComplete; // expected-note{{forward declaration}} static_assert(!__is_bitwise_cloneable(InComplete)); // expected-error{{incomplete type 'InComplete' used in type trait expression}} + +// A struct with an incomplete field type is not bitwise cloneable. +struct Bar; // expected-note{{forward declaration}} +struct Foo { + Bar bar; // expected-error{{field has incomplete type 'Bar'}} +}; +static_assert(!__is_bitwise_cloneable(Foo)); + +// Don't crash when the type has a member of invalid/unknown type. +struct ABC { // expected-note {{'ABC' declared here}} expected-note {{definition of 'ABC' is not complete until the closing '}'}} + ABCD ptr; // expected-error {{unknown type name 'ABCD'}} expected-error {{field has incomplete type 'ABC'}} +}; +static_assert(!__is_bitwise_cloneable(ABC)); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
