From 301ffb1944a01d33d0b82c135f3c4a86e80fde2e Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:13:19 -0700 Subject: Fix #pragma warning not working with multifile modules (#7942) * Initial plan * Fix pragma warning not working with multifile modules - Check if DiagnosticSink already has a WarningStateTracker before creating new one - This preserves pragma warning state across __include'd files - Add regression tests for multifile pragma warnings Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Add additional test cases for nested pragma warnings - Test nested __include scenarios with pragma warning directives - Verify pragma warnings work correctly with multiple levels of includes Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> Co-authored-by: Yong He --- source/slang/slang-preprocessor.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source/slang') diff --git a/source/slang/slang-preprocessor.cpp b/source/slang/slang-preprocessor.cpp index b29fa2716..a0e80473d 100644 --- a/source/slang/slang-preprocessor.cpp +++ b/source/slang/slang-preprocessor.cpp @@ -4878,9 +4878,14 @@ TokenList preprocessSource( desc.contentAssistInfo = &linkage->contentAssistInfo.preprocessorInfo; } - preprocessor::WarningStateTracker* wst = - new preprocessor::WarningStateTracker(desc.sourceManager); - desc.sink->setSourceWarningStateTracker(wst); + // Only create a new WarningStateTracker if the sink doesn't already have one. + // This ensures pragma warning states are preserved across included files. + if (!desc.sink->getSourceWarningStateTracker()) + { + preprocessor::WarningStateTracker* wst = + new preprocessor::WarningStateTracker(desc.sourceManager); + desc.sink->setSourceWarningStateTracker(wst); + } return preprocessSource(file, desc, outDetectedLanguage, outLanguageVersion); } -- cgit v1.2.3