diff options
| author | Yong He <yonghe@outlook.com> | 2024-04-12 17:07:40 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-12 17:07:40 -0700 |
| commit | 31c704f2ba5588e0612158ea016552debf09ee98 (patch) | |
| tree | 0499d4c6ba2f60ee2456451969e555df55ad1bd0 | |
| parent | b937207dccd05f700855e9aeb3f7c375b595b827 (diff) | |
Fix micro expansion issue for __LINE__. (#3942)
| -rw-r--r-- | source/slang/slang-preprocessor.cpp | 12 | ||||
| -rw-r--r-- | tests/preprocessor/line-macro.slang | 14 |
2 files changed, 25 insertions, 1 deletions
diff --git a/source/slang/slang-preprocessor.cpp b/source/slang/slang-preprocessor.cpp index 702259381..c4a2bd95e 100644 --- a/source/slang/slang-preprocessor.cpp +++ b/source/slang/slang-preprocessor.cpp @@ -857,6 +857,11 @@ struct ExpansionInputStream : InputStream TokenType peekRawTokenType() { return peekRawToken().type; } + void setInitiatingMacroSourceLoc(SourceLoc loc) + { + m_initiatingMacroInvocationLoc = loc; + m_isInExpansion = true; + } private: /// The base stream that macro expansion is being applied to InputStream* m_base = nullptr; @@ -868,6 +873,10 @@ private: /// nested macro invocations might be in flight. SourceLoc m_initiatingMacroInvocationLoc; + /// Whether this ExpansionStream is created in the middle of + /// another macro expansion. + bool m_isInExpansion = false; + /// One token of lookahead Token m_lookaheadToken; @@ -1429,7 +1438,7 @@ void ExpansionInputStream::_maybeBeginMacroInvocation() // invocation location for things like `__LINE__` uses inside // of macro bodies. // - if(activeStream == m_base) + if(!m_isInExpansion && activeStream == m_base) { m_initiatingMacroInvocationLoc = token.loc; } @@ -2110,6 +2119,7 @@ void MacroInvocation::_initCurrentOpStream() // applies macro expansion to them. // ExpansionInputStream* expansion = new ExpansionInputStream(m_preprocessor, stream); + expansion->setInitiatingMacroSourceLoc(m_initiatingMacroInvocationLoc); m_currentOpStreams.push(expansion); } break; diff --git a/tests/preprocessor/line-macro.slang b/tests/preprocessor/line-macro.slang new file mode 100644 index 000000000..2b035357a --- /dev/null +++ b/tests/preprocessor/line-macro.slang @@ -0,0 +1,14 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer : register(u0); + +#define T(x) x +#define LL T(__LINE__) + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + // CHECK: 13 + outputBuffer[0] = LL; +}
\ No newline at end of file |
