Skip to content

Ignore unknown pragmas during lexing - #597

Open
xavierleroy wants to merge 1 commit into
masterfrom
remove-pragmas-early
Open

xavierleroy wants to merge 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>
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