Skip to content

copilot-c99: Raise error when compiling empty array or struct. Refs #695.#713

Open
chathhorn-galois wants to merge 3 commits intoCopilot-Language:masterfrom
GaloisInc:chathhorn/issue695
Open

copilot-c99: Raise error when compiling empty array or struct. Refs #695.#713
chathhorn-galois wants to merge 3 commits intoCopilot-Language:masterfrom
GaloisInc:chathhorn/issue695

Conversation

@chathhorn-galois
Copy link
Collaborator

Copilot allows defining empty arrays (i.e., values of type Array 0) and empty structs (i.e., structs with no fields), but using empty arrays or structs in C99 is undefined behavior. copilot-c99 will often crash if you attempt to compile a Copilot specification that uses an empty array or struct with an unhelpful error message (NonEmpty.fromList: empty list), but even if it doesn't, you're left with an invalid C program.

This PR adds a check for attempts to translate specs that contain zero-length arrays or structs with no fields and raises an appropriate error, preventing such specs from being translated into invalid C.

Fixes #695.

…opilot-Language#695.

Because they are not supported by C99, this commit raises an appropriate error
when attempting to translate a zero-length array or a struct with no fields to
C99. Previously, Copilot would either crash with a confusing error or silently
translate the offending spec to invalid C99.
…Copilot-Language#695.

Because they are not supported by C99, attempting to translate a zero-length
array or a struct with no fields to C99 should fail. This commit adds a
regression test to check that attempting to compile specs containing
zero-length arrays or empty structs to C99 raises an apropriate error.
@ivanperez-keera ivanperez-keera changed the title copilot-c99: Raise an error when attempting to translate zero-length arrays or empty structs to C99. Refs #695. copilot-c99: Raise error when compiling zero-length arrays or empty structs to C99. Refs #695. Feb 25, 2026
@ivanperez-keera ivanperez-keera changed the title copilot-c99: Raise error when compiling zero-length arrays or empty structs to C99. Refs #695. copilot-c99: Raise error when compiling empty array or struct. Refs #695. Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

copilot-c99: Raise error when compiling an empty array or struct

1 participant