diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-01-24 17:14:04 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-24 17:14:04 -0500 |
| commit | d98a2b75c9b4a31de0ebfb1084a68b5be5ede17d (patch) | |
| tree | fa59a35b7473e20808f00a2bfb78bc4074f01d05 /tests/preprocessor | |
| parent | b8f294445b998eadb9b09e2b91eb462b881eaf2e (diff) | |
Fix for infinite recursion with macro invocation (#1177)
* First pass fix of macro expansion logic to stop recursive application (causting a recursive loop), whilst also allowing application on parameters to a macro.
* Added recursive-macro test.
Fixed macro application example.
Diffstat (limited to 'tests/preprocessor')
| -rw-r--r-- | tests/preprocessor/recursive-macro.slang | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/preprocessor/recursive-macro.slang b/tests/preprocessor/recursive-macro.slang new file mode 100644 index 000000000..1f776ca72 --- /dev/null +++ b/tests/preprocessor/recursive-macro.slang @@ -0,0 +1,25 @@ +//TEST(compute):SIMPLE: + +// Test for correct recursive macro behavior. In particular: + +// The letter of the spec is that we should macro expand +// each argument *before* substitution, and then go and +// macro-expand the substituted body. This means that we +// can invoke a macro as part of an argument to an +// invocation of the same macro: +// +// FOO( 1, FOO(22, 2, 2), 333 ); + +// Also in the case on NO_EXPAND, it will not be expanded in the substitution. + +#define ARG_EXPAND(x) ( x ) + +// This macro should expand to NO_EXPAND(int 'a'), and not multiply invoke NO_EXPAND, because +// one the args have been expanded. +#define NO_EXPAND(a) NO_EXPAND(int a) + +// Should expand to int NO_EXPAND(int b) +int NO_EXPAND(b) +{ + return b + ARG_EXPAND(ARG_EXPAND(1)); +}
\ No newline at end of file |
