Skip to content

Ignore unknown pragmas during lexing - #597

Merged
xavierleroy merged 1 commit into
masterfrom
remove-pragmas-early
Sep 29, 2026
Merged

xavierleroy merged 1 commit into
masterfrom
remove-pragmas-early

Conversation

@xavierleroy

Copy link
Copy Markdown
Contributor

Currently, the parser accepts #pragma directives that occur in declaration position. Elab ignores (with a warning) pragmas that are not global declarations. C2C ignores (with a warning) all remaining pragmas except the section, use_section and reserve_register pragmas handled in cfrontend/CPragmas.ml.

However, #pragma directives can occur anywhere in a C source file, incl. in the middle of a statement or an expression. Some system header files includes such weird pragmas.

This PR recognizes #pragma directives that are not handled in cfrontend/CPragmas.ml during lexical analysis and ignores them (with a warning). No PRAGMA token is generated for unhandled pragmas. This way, unhandled pragmas can occur anywhere in the source file and will not cause parsing errors.

Currently, the parser accepts `#pragma` directives that occur in declaration position.  Elab ignores (with a warning) pragmas that are not global declarations.  C2C ignores (with a warning) all remaining pragmas except the `section`, `use_section` and `reserve_register` pragmas handled in cfrontend/CPragmas.ml.

However, `#pragma` directives can occur anywhere in a C source file, incl. in the middle of a statement or an expression.  Some system header files includes such weird pragmas.

This PR recognizes `#pragma` directives that are not handled in cfrontend/CPragmas.ml during lexical analysis and ignores them (with a warning).  No `PRAGMA` token is generated for unhandled pragmas.  This way, unhandled pragmas can occur anywhere in the source file and will not cause parsing errors.

Co-authored-by: Bernhard Schommer <bernhardschommer@gmail.com>
@xavierleroy
xavierleroy merged commit 1eac8e8 into master Sep 29, 2026
19 checks passed
@xavierleroy
xavierleroy deleted the remove-pragmas-early branch September 30, 2026 15:42
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.

1 participant