diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2025-08-18 10:22:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-18 14:22:31 +0000 |
commit | f5dc3021cda339f7695272ad6e02b79f193c50c4 (patch) | |
tree | 873e31b60e186165b508aedbe21565464f8a81b0 /clang/lib/Sema/SemaInit.cpp | |
parent | b368e7f6a5db365aa8d9a514db018be9607f97d1 (diff) | |
download | llvm-f5dc3021cda339f7695272ad6e02b79f193c50c4.zip llvm-f5dc3021cda339f7695272ad6e02b79f193c50c4.tar.gz llvm-f5dc3021cda339f7695272ad6e02b79f193c50c4.tar.bz2 |
[C] Fix failing assertion with designated inits (#154120)
Incompatible pointer to integer conversion diagnostic checks would
trigger an assertion when the designated initializer is for an array of
unknown bounds.
Fixes #154046
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index d7cca4b..60f9d44 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -3294,8 +3294,9 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity, if (StringLiteral *SL = dyn_cast<StringLiteral>(SubExpr)) { // Get the length of the string. uint64_t StrLen = SL->getLength(); - if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen)) - StrLen = cast<ConstantArrayType>(AT)->getZExtSize(); + if (const auto *CAT = dyn_cast<ConstantArrayType>(AT); + CAT && CAT->getSize().ult(StrLen)) + StrLen = CAT->getZExtSize(); StructuredList->resizeInits(Context, StrLen); // Build a literal for each character in the string, and put them into @@ -3317,8 +3318,9 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity, // Get the length of the string. uint64_t StrLen = Str.size(); - if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen)) - StrLen = cast<ConstantArrayType>(AT)->getZExtSize(); + if (const auto *CAT = dyn_cast<ConstantArrayType>(AT); + CAT && CAT->getSize().ult(StrLen)) + StrLen = CAT->getZExtSize(); StructuredList->resizeInits(Context, StrLen); // Build a literal for each character in the string, and put them into |