summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMukund Keshava <mkeshava@nvidia.com>2025-02-18 00:55:34 +0530
committerGitHub <noreply@github.com>2025-02-17 11:25:34 -0800
commit7abc69e9d3d7bf2e15f9796ff1813f87aeb4745d (patch)
tree568485e128c8120f9f2149d352d92a9588d1f704
parente043428c5ac263fdb61072bd769fef769e8b08e4 (diff)
slang: Fix empty VARARGS issue(#6332) (#6372)
-rw-r--r--source/slang/slang-preprocessor.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/source/slang/slang-preprocessor.cpp b/source/slang/slang-preprocessor.cpp
index d3606235c..5a4e26f37 100644
--- a/source/slang/slang-preprocessor.cpp
+++ b/source/slang/slang-preprocessor.cpp
@@ -2011,6 +2011,13 @@ TokenReader MacroInvocation::_getArgTokens(Index paramIndex)
// to the parameter, and we construct a `TokenReader` that will play
// back the tokens of that argument.
//
+ // Special case: If we have no arguments but the macro expects one parameter,
+ // return an empty token range
+ if (m_args.getCount() == 0 && m_macro->params.getCount() == 1)
+ {
+ return TokenReader(argTokens, argTokens);
+ }
+
SLANG_ASSERT(paramIndex < m_args.getCount());
auto arg = m_args[paramIndex];
return TokenReader(argTokens + arg.beginTokenIndex, argTokens + arg.endTokenIndex);
@@ -2037,8 +2044,15 @@ TokenReader MacroInvocation::_getArgTokens(Index paramIndex)
// When there are no arguments for the varaidic parameter we will
// construct an empty token range that comes after the other arguments.
//
- auto arg = m_args[lastArgIndex];
- return TokenReader(argTokens + arg.endTokenIndex, argTokens + arg.endTokenIndex);
+ if (lastArgIndex >= 0)
+ {
+ auto arg = m_args[lastArgIndex];
+ return TokenReader(argTokens + arg.endTokenIndex, argTokens + arg.endTokenIndex);
+ }
+ else
+ {
+ return TokenReader(argTokens, argTokens);
+ }
}
// Because the `m_argTokens` array includes the commas between arguments,