Skip to content

Fix macro expansion bugs in the shader compiler preprocessor - #165

Merged
ccpisheden merged 3 commits into
mainfrom
preprocessor-macro-fix
Nov 27, 2026
Merged

ccpisheden merged 3 commits into
mainfrom
preprocessor-macro-fix

Conversation

@ccpisheden

Copy link
Copy Markdown
Contributor

This PR fixes multiple macro expansion issues in the preprocessor. Also adds tests for basic preprocessor functionality.

  • Macro arguments are built from their expanded tokens instead of a range of source text, which spanned unrelated buffers when an argument started or ended in a macro. Nested calls left parameter names unexpanded, and an object-like macro at the start of an argument could expand forever.
  • Commas inside parentheses in an argument are kept in the argument.
  • Empty macro arguments no longer read from an empty token list.
  • '>>' in #if conditions shifted left.
  • Add preprocessor tests to ShaderCompilerTest.

Summary

Linked issue (optional)

Testing

  • Shader compilation works.
  • Tests pass, no issues.
  • CORTAO shaders now compile correctly with nested macros.

AI assistance

Claude used heavily, tweaks and fixes by me, tests redesigned by me.

- Macro arguments are built from their expanded tokens instead of a range of
  source text, which spanned unrelated buffers when an argument started or
  ended in a macro. Nested calls left parameter names unexpanded, and an
  object-like macro at the start of an argument could expand forever.
- Commas inside parentheses in an argument are kept in the argument.
- Empty macro arguments no longer read from an empty token list.
- '>>' in #if conditions shifted left.
- Add preprocessor tests to ShaderCompilerTest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions[bot]

This comment was marked as outdated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccpisheden
ccpisheden dismissed github-actions[bot]’s stale review November 27, 2026 15:14

Fixed in a91eeac; cpp-linter passes.

@ccpisheden
ccpisheden merged commit a0d4719 into main Nov 27, 2026
1 check passed
@ccpisheden
ccpisheden deleted the preprocessor-macro-fix branch November 27, 2026 16:35
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.

2 participants