Skip to content
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

Protect against $NNN identifiers #541

Merged
merged 2 commits into from
Dec 6, 2024
Merged

Protect against $NNN identifiers #541

merged 2 commits into from
Dec 6, 2024

Conversation

xavierleroy
Copy link
Contributor

@xavierleroy xavierleroy commented Dec 2, 2024

As a popular extension to ISO C, CompCert C supports identifiers starting with $. In the generated assembly code, identifiers such as $123 can be confused for integer literals. That's the case for x86 (see #540) and for 32-bit ARM.

This PR fixes the issue like GCC does, by enclosing identifiers starting with $ in parentheses. Note that this is not necessary for macOS, since all C identifiers are prefixed by _, making _$123 unambiguous.

The ARM assembly language reference manual suggests the use of vertical bars |$123|, but these are not implemented by the GNU assembler.

A test was added to the small test suite.

Fixes: #540

They must be parenthesized in some contexts to avoid being confused for
immediate operands.

Fixes: #540
They must be parenthesized in some contexts.
@xavierleroy xavierleroy merged commit d4c6a8c into master Dec 6, 2024
6 of 7 checks passed
@xavierleroy xavierleroy deleted the dollar-ident branch December 6, 2024 14:28
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.

Compilation fails at assembling due to "juk after expression"
1 participant