Revision 58d7af37f45f88130641188b1e39b00569acd575 authored by T. Foley on 06 June 2021, 15:59:28 UTC, committed by GitHub on 06 June 2021, 15:59:28 UTC
* Fix a bug in preprocessor "busy" logic

This bug manifested in both incorrect preprocessor output for certain complicated cases, and also (more importantly) a use-after-free issue.

One of the "clever" design choices in the Slang preprocessor implementation is that the set of "busy" macros during expansion is implicitly defined by a linked list of those invocations that are actively being read from as part of the input stack. This logic works very well for checking whether a macro name is busy before triggering expansion, and for computing what macros should be considered busy during expansion of an object-like macro.

The problem case here was with function-like macros where the preprocessor was re-using the same list of busy macros that had been fetched when reading the macro name, but doing so *after* all the macro argument tokens had been read. Because additional tokens had been read from the input stream stack, there was no guarantee that the invocations that had been active before were still live.

The new logic computes the set of busy macros fresh before starting expansion of a function-like macro invocation. A test is included to ensure that the case that showed the use-after-free bug has been fixed.

In addition, the new logic is careful to compute the busy macros only based on where subsequent tokens will come from and not based on any macros that might have contributed to the argument tokens themselves. A test case has been added that relies on getting this detail correct.

* Update slang-preprocessor.cpp

Remove a test typo.

Co-authored-by: jsmall-nvidia <jsmall@nvidia.com>
1 parent 1617c2d
History
File Mode Size
.github
build
docs
examples
external
extras
prelude
source
tests
tools
.editorconfig -rw-r--r-- 937 bytes
.gitattributes -rw-r--r-- 95 bytes
.gitignore -rw-r--r-- 1.1 KB
.gitmodules -rw-r--r-- 951 bytes
CODE_OF_CONDUCT.md -rw-r--r-- 3.1 KB
LICENSE -rw-r--r-- 1.1 KB
README.md -rw-r--r-- 6.1 KB
github_build.sh -rw-r--r-- 495 bytes
github_test.sh -rw-r--r-- 546 bytes
premake.bat -rw-r--r-- 120 bytes
premake5.lua -rw-r--r-- 49.0 KB
slang-com-helper.h -rw-r--r-- 4.9 KB
slang-com-ptr.h -rw-r--r-- 4.9 KB
slang-gfx.h -rw-r--r-- 44.7 KB
slang-tag-version.h -rw-r--r-- 36 bytes
slang.h -rw-r--r-- 174.8 KB
slang.sln -rw-r--r-- 21.2 KB
test.bat -rw-r--r-- 1.4 KB

README.md

back to top