Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 26, 2025

The #pragma warning directives were not working correctly when modules included multiple files via __include. Pragma warning states (like disable, push, pop) were being lost when processing subsequent included files, causing warnings to appear even when they should have been suppressed.

Root Cause

The issue was in slang-preprocessor.cpp where a new WarningStateTracker was created for each file processed by the preprocessor. When __include directives processed additional files, they created fresh warning state trackers, losing the pragma warning state from previously processed files.

Example of the Issue

Consider this module structure:

// main.slang
module my_module;
__include "impl1.slang";
__include "impl2.slang";

// impl1.slang  
implementing my_module;
#pragma warning(disable: 30856)
// ... code that should suppress warning 30856

// impl2.slang
implementing my_module; 
// ... code that should still have warning 30856 suppressed

Before this fix, warning 30856 would incorrectly appear in impl2.slang even though it was disabled in impl1.slang.

Solution

Modified the preprocessor to check if the DiagnosticSink already has a WarningStateTracker before creating a new one. This ensures pragma warning states persist across all files in a module:

// 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);
}

Testing

Added comprehensive regression tests covering:

  • Multifile modules with pragma warning directives
  • Nested __include scenarios
  • Single-file pragma warnings (to ensure no regressions)
  • Push/pop pragma warning behavior across file boundaries

All existing pragma and warning-related tests continue to pass.

Fixes #7941.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@CLAassistant
Copy link

CLAassistant commented Jul 26, 2025

CLA assistant check
All committers have signed the CLA.

Copilot AI and others added 2 commits July 26, 2025 06:49
- 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>
- 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>
@Copilot Copilot AI changed the title [WIP] #pragma warning not working with multifile modules. Fix #pragma warning not working with multifile modules Jul 26, 2025
@Copilot Copilot AI requested a review from csyonghe July 26, 2025 06:52
Copilot finished work on behalf of csyonghe July 26, 2025 06:52
@csyonghe csyonghe added the pr: non-breaking PRs without breaking changes label Jul 27, 2025
@csyonghe csyonghe marked this pull request as ready for review July 29, 2025 18:45
@csyonghe csyonghe requested a review from a team as a code owner July 29, 2025 18:45
Copy link
Contributor

@kaizhangNV kaizhangNV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. I don't understand how it figure it out...

@csyonghe csyonghe enabled auto-merge July 29, 2025 18:56
@csyonghe csyonghe added this pull request to the merge queue Jul 29, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 30, 2025
@tdavidovicNV
Copy link

@csyonghe this got automatically pulled out of the merge queue for reason I don't fully understand. Seems like the build is just stuck on that machine.

@csyonghe csyonghe added this pull request to the merge queue Aug 5, 2025
Merged via the queue into master with commit 301ffb1 Aug 5, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: non-breaking PRs without breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#pragma warning not working with multifile modules.
6 participants