From 31c704f2ba5588e0612158ea016552debf09ee98 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 12 Apr 2024 17:07:40 -0700 Subject: Fix micro expansion issue for __LINE__. (#3942) --- source/slang/slang-preprocessor.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-preprocessor.cpp') 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; -- cgit v1.2.3