Skip to content

transpile: handle all cases of extra braces in string initializers #1265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 19, 2025

Conversation

kkysen
Copy link
Contributor

@kkysen kkysen commented Jul 4, 2025

We need to handle the 4 cases in str_init.c with identical initializers:

  • ptr_extra_braces
  • array_extra_braces
  • array_of_ptrs
  • array_of_arrays

All 4 have different types, but the same initializer, which is possible because C allows extra braces around any initializer element. For non-string literal elements, the clang AST already fixes this up, but doesn't for string literals, so we need to handle them specially. The default logic handles all except array_extra_braces.

array_extra_braces is uniquely identified by:

  • there being only one element in the initializer list
  • the element type of the array being CTypeKind::Char (w/o this, array_of_arrays is included)
  • the expr kind being a string literal (CExprKind::Literal of a CLiteral::String).

@kkysen kkysen force-pushed the kkysen/char-2d-array-str-init branch from e6873c4 to 543be56 Compare July 4, 2025 21:22
@kkysen kkysen force-pushed the kkysen/char-2d-array-str-init branch 4 times, most recently from 358cd60 to a96cdf9 Compare July 18, 2025 20:08
@kkysen kkysen changed the title transpile: add a snapshot test for 2D char array initialization w/ string literals w/ broken tests disabled transpile: handle all cases of extra braces in string initializers Jul 18, 2025
@kkysen kkysen requested a review from fw-immunant July 18, 2025 20:20
@kkysen kkysen force-pushed the kkysen/char-2d-array-str-init branch from 2c6b20c to 155a24f Compare July 18, 2025 20:22
Copy link
Contributor

@fw-immunant fw-immunant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes LGTM, but history is a bit messy. Could you squash down the changes to test cases so we just have the before (adding test cases, some commented out) and after (all passing) states? Or even split out the insta update commit and squash everything else.

@fw-immunant
Copy link
Contributor

I'm also curious, will this interact with #1218?

Copy link
Contributor Author

@kkysen kkysen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes LGTM, but history is a bit messy. Could you squash down the changes to test cases so we just have the before (adding test cases, some commented out) and after (all passing) states? Or even split out the insta update commit and squash everything else.

Okay, I can do that. I didn't squash the renaming function commit since it was a bit messy with the snapshots, but I can do that if you prefer. Squashing the comment commit should be simple.

I'm also curious, will this interact with #1218?

I'm not sure. Let me check.

kkysen added 3 commits July 18, 2025 19:23
…string literals w/ broken tests disabled

This tests #1264 with a series of minimizing test cases until they start passing.
The root issue stems from `array_of_arrays`, where we try to initialize
a 2D `char` array with a string literal.

For now, the broken tests are all disabled, and I'll enable them along with the fix.
@kkysen kkysen force-pushed the kkysen/char-2d-array-str-init branch from 155a24f to cbaf7ff Compare July 19, 2025 02:23
@kkysen
Copy link
Contributor Author

kkysen commented Jul 19, 2025

I'm also curious, will this interact with #1218?

Yes, but it should be pretty easy to combine them. The if is_string_literal(*single) case just needs to be updated with the new logic here.

@kkysen kkysen merged commit 73720d3 into master Jul 19, 2025
5 checks passed
@kkysen kkysen deleted the kkysen/char-2d-array-str-init branch July 19, 2025 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

curl: Transpiler emits single-dimensional initializer for 2D entries in struct alpn_spec
2 participants