C front-end: reject invalid array declarators#8773
Open
tautschnig wants to merge 1 commit intodiffblue:developfrom
Open
C front-end: reject invalid array declarators#8773tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig wants to merge 1 commit intodiffblue:developfrom
Conversation
Reject static, type qualifiers (restrict, const, volatile), and [*] in array declarators outside their valid contexts per C99 6.7.5.2/6.7.5.3: - [static N], [restrict], [restrict N], etc. are only valid in function parameter declarations - [*] is only valid in function prototype scope (declarations, not definitions) Implementation: the parser marks array types that use these constructs with flags (ID_C_array_fpm_qualifier for qualifiers/static, ID_C_array_vla_unspecified for [*]). The type-checker then rejects non-parameter declarations with the qualifier flag, and function definitions with the [*] flag. The [*] flag is preserved through array-to-pointer decay so it can be detected in function bodies. Fixes: diffblue#132 Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
79171e0 to
ceed2a2
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves the ANSI-C frontend’s handling of C99 array declarator qualifiers in function-parameter contexts by marking such syntax in the parsed types and enforcing scope rules during typechecking.
Changes:
- Add irep IDs to tag array declarators that use function-parameter-only qualifiers and to mark
[*](VLA unspecified). - Propagate the
[*]marker through array-to-pointer decay so it remains detectable during function-definition typechecking. - Enforce errors for invalid uses (e.g.,
[*]in function definitions; qualifiers likerestrict/staticoutside parameter declarations) and update regression expectations from KNOWNBUG to CORE.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/util/irep_ids.def | Introduces internal irep IDs for new parser/typechecker flags. |
| src/ansi-c/parser.y | Tags parsed array declarators with new flags when using qualifiers or [*]. |
| src/ansi-c/c_typecheck_type.cpp | Preserves the [*] marker across array-to-pointer decay for parameters. |
| src/ansi-c/c_typecheck_base.cpp | Adds semantic checks rejecting invalid array declarator qualifier usage by scope. |
| regression/ansi-c/Array_Declarator{2..7}/test.desc | Updates regression tests to expect conversion errors (and no “warning: ignoring”). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+812
to
+816
| const typet &decl_type = declarator.type(); | ||
| std::function<bool(const typet &)> has_array_fpm = | ||
| [&](const typet &t) -> bool | ||
| { | ||
| if(t.id() == ID_array && t.get_bool(ID_C_array_fpm_qualifier)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
According to the C standard (C99/C11):
These constructs are not valid in:
Fixes: #132