This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGfe0116aba833: [clang] Fix a crash when casting to an array type (authored by ayzhao).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D155523/new/ https://reviews.llvm.org/D155523 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaCast.cpp clang/test/SemaCXX/paren-list-agg-init.cpp Index: clang/test/SemaCXX/paren-list-agg-init.cpp =================================================================== --- clang/test/SemaCXX/paren-list-agg-init.cpp +++ clang/test/SemaCXX/paren-list-agg-init.cpp @@ -294,3 +294,8 @@ } } + +namespace gh63758 { + struct S {} s; + auto words = (char[])s; // expected-error {{C-style cast from 'struct S' to 'char[]' is not allowed}} +}; Index: clang/lib/Sema/SemaCast.cpp =================================================================== --- clang/lib/Sema/SemaCast.cpp +++ clang/lib/Sema/SemaCast.cpp @@ -454,9 +454,27 @@ switch (sequence.getFailureKind()) { default: return false; + case InitializationSequence::FK_ParenthesizedListInitFailed: + // In C++20, if the underlying destination type is a RecordType, Clang + // attempts to perform parentesized aggregate initialization if constructor + // overload fails: + // + // C++20 [expr.static.cast]p4: + // An expression E can be explicitly converted to a type T...if overload + // resolution for a direct-initialization...would find at least one viable + // function ([over.match.viable]), or if T is an aggregate type having a + // first element X and there is an implicit conversion sequence from E to + // the type of X. + // + // If that fails, then we'll generate the diagnostics from the failed + // previous constructor overload attempt. Array initialization, however, is + // not done after attempting constructor overloading, so we exit as there + // won't be a failed overload result. + if (destType->isArrayType()) + return false; + break; case InitializationSequence::FK_ConstructorOverloadFailed: case InitializationSequence::FK_UserConversionOverloadFailed: - case InitializationSequence::FK_ParenthesizedListInitFailed: break; } Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -634,6 +634,8 @@ that construct (`#62133 <https://github.com/llvm/llvm-project/issues/38717>_`). - Fix crash caused by PseudoObjectExprBitfields: NumSubExprs overflow. (`#63169 <https://github.com/llvm/llvm-project/issues/63169>_`) +- Fix crash when casting an object to an array type. + (`#63758 <https://github.com/llvm/llvm-project/issues/63758>_`) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang/test/SemaCXX/paren-list-agg-init.cpp =================================================================== --- clang/test/SemaCXX/paren-list-agg-init.cpp +++ clang/test/SemaCXX/paren-list-agg-init.cpp @@ -294,3 +294,8 @@ } } + +namespace gh63758 { + struct S {} s; + auto words = (char[])s; // expected-error {{C-style cast from 'struct S' to 'char[]' is not allowed}} +}; Index: clang/lib/Sema/SemaCast.cpp =================================================================== --- clang/lib/Sema/SemaCast.cpp +++ clang/lib/Sema/SemaCast.cpp @@ -454,9 +454,27 @@ switch (sequence.getFailureKind()) { default: return false; + case InitializationSequence::FK_ParenthesizedListInitFailed: + // In C++20, if the underlying destination type is a RecordType, Clang + // attempts to perform parentesized aggregate initialization if constructor + // overload fails: + // + // C++20 [expr.static.cast]p4: + // An expression E can be explicitly converted to a type T...if overload + // resolution for a direct-initialization...would find at least one viable + // function ([over.match.viable]), or if T is an aggregate type having a + // first element X and there is an implicit conversion sequence from E to + // the type of X. + // + // If that fails, then we'll generate the diagnostics from the failed + // previous constructor overload attempt. Array initialization, however, is + // not done after attempting constructor overloading, so we exit as there + // won't be a failed overload result. + if (destType->isArrayType()) + return false; + break; case InitializationSequence::FK_ConstructorOverloadFailed: case InitializationSequence::FK_UserConversionOverloadFailed: - case InitializationSequence::FK_ParenthesizedListInitFailed: break; } Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -634,6 +634,8 @@ that construct (`#62133 <https://github.com/llvm/llvm-project/issues/38717>_`). - Fix crash caused by PseudoObjectExprBitfields: NumSubExprs overflow. (`#63169 <https://github.com/llvm/llvm-project/issues/63169>_`) +- Fix crash when casting an object to an array type. + (`#63758 <https://github.com/llvm/llvm-project/issues/63758>_`) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits