summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-preprocessor.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-04-12 17:07:40 -0700
committerGitHub <noreply@github.com>2024-04-12 17:07:40 -0700
commit31c704f2ba5588e0612158ea016552debf09ee98 (patch)
tree0499d4c6ba2f60ee2456451969e555df55ad1bd0 /source/slang/slang-preprocessor.cpp
parentb937207dccd05f700855e9aeb3f7c375b595b827 (diff)
Fix micro expansion issue for __LINE__. (#3942)
Diffstat (limited to 'source/slang/slang-preprocessor.cpp')
-rw-r--r--source/slang/slang-preprocessor.cpp12
1 files changed, 11 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;