Skip to content

Fix recursive GLSL macro rescanning - #3751

Merged
paroj merged 1 commit into
OGRECave:masterfrom
snowyukitty:fix/glsl-recursive-macros
Oct 12, 2026
Merged

paroj merged 1 commit into
OGRECave:masterfrom
snowyukitty:fix/glsl-recursive-macros

Conversation

@snowyukitty

Copy link
Copy Markdown
Contributor

Closes #2635.

The supplementary preprocessor currently forgets which macro occurrences were disabled during an earlier expansion. Rescanning #define foo bar foo through an alias therefore expands the trailing foo repeatedly.

Carry disabled-macro ranges with tokens through rescans and argument substitution, so recursive occurrences stay suppressed while separate invocations still expand. Preserve the existing argument/directive rescan and borrowed-buffer handling. Evaluate expanded conditional-expression text with the same metadata so a suppressed identifier has the usual value of zero.

Add ten regression tests for the reported alias, repeated expansions, mutual recursion, function wrappers, recursive arguments, higher-order arguments and conditional expressions. Four passing controls cover argument-name isolation, concatenation, repeated allocated arguments, and strings/comments. On the unchanged base, each regression exceeds a three-second external timeout; all existing tests and new controls pass.

Validation on Linux / GCC 12:

  • Test_Ogre: 186 passed, 2 skipped.
  • All 31 preprocessor tests pass with AddressSanitizer and UndefinedBehaviorSanitizer.
  • glslangValidator -S vert accepts four shaders using the real OgreUnifiedShader.h and GLSL_GL3Support.glsl: GLSL 330 and GLES 300, each with FOO defined as 0 or undefined.
  • git diff --check passes.

The native CMake build enables tests and sample resource configuration; tools, language bindings, ImGui and the GLES2 render-system build are disabled. Windows/macOS and GPU visual tests were not run locally.

Related draft #1314 changes extension-conditional passthrough for #614 and shares these three files. At its unchanged head f77b471, its hunks in all three shared files apply cleanly to both the audited base and this candidate. Its goal and production methods differ; compatibility needs rechecking if it changes or lands.

@paroj
paroj merged commit 8fd7741 into OGRECave:master Oct 12, 2026
6 checks passed
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.

GLSLPreprocessor: may enter infinite recursion

2 participants