diff options
| author | Copilot <198982749+Copilot@users.noreply.github.com> | 2025-08-04 17:13:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-05 00:13:19 +0000 |
| commit | 301ffb1944a01d33d0b82c135f3c4a86e80fde2e (patch) | |
| tree | 94d0f6f6253ed21c17150f03cd5c421a66824435 | |
| parent | 41314741d9bfca95abba40e58720b4ce2f2653dd (diff) | |
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 <yonghe@outlook.com>
| -rw-r--r-- | source/slang/slang-preprocessor.cpp | 11 | ||||
| -rw-r--r-- | tests/diagnostics/nested-pragma-impl1.slang | 12 | ||||
| -rw-r--r-- | tests/diagnostics/nested-pragma-impl2.slang | 10 | ||||
| -rw-r--r-- | tests/diagnostics/nested-pragma-main.slang | 9 | ||||
| -rw-r--r-- | tests/diagnostics/pragma-warning-multifile-impl1.slang | 16 | ||||
| -rw-r--r-- | tests/diagnostics/pragma-warning-multifile-impl2.slang | 11 | ||||
| -rw-r--r-- | tests/diagnostics/pragma-warning-multifile-main.slang | 8 | ||||
| -rw-r--r-- | tests/diagnostics/pragma-warning-single-file.slang | 26 |
8 files changed, 100 insertions, 3 deletions
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); } diff --git a/tests/diagnostics/nested-pragma-impl1.slang b/tests/diagnostics/nested-pragma-impl1.slang new file mode 100644 index 000000000..305162651 --- /dev/null +++ b/tests/diagnostics/nested-pragma-impl1.slang @@ -0,0 +1,12 @@ +implementing nested_pragma_test; + +__include "nested-pragma-impl2.slang"; + +namespace impl1 +{ + interface IConvertibleFrom<From> {} + + // This should NOT produce warning 30856 due to outer pragma disable + extension<From : __BuiltinIntegerType, To : IConvertibleFrom<From>, let N : int> + vector<To, N> : IConvertibleFrom<vector<From, N>> {} +}
\ No newline at end of file diff --git a/tests/diagnostics/nested-pragma-impl2.slang b/tests/diagnostics/nested-pragma-impl2.slang new file mode 100644 index 000000000..9a7e57562 --- /dev/null +++ b/tests/diagnostics/nested-pragma-impl2.slang @@ -0,0 +1,10 @@ +implementing nested_pragma_test; + +namespace impl2 +{ + interface IConvertibleFrom<From> {} + + // This should also NOT produce warning 30856 due to outer pragma disable + extension<From : __BuiltinFloatingPointType, To : IConvertibleFrom<From>, let N : int> + vector<To, N> : IConvertibleFrom<vector<From, N>> {} +}
\ No newline at end of file diff --git a/tests/diagnostics/nested-pragma-main.slang b/tests/diagnostics/nested-pragma-main.slang new file mode 100644 index 000000000..1795f7d68 --- /dev/null +++ b/tests/diagnostics/nested-pragma-main.slang @@ -0,0 +1,9 @@ +//TEST:SIMPLE(filecheck=CHECK): + +module nested_pragma_test; + +#pragma warning(disable: 30856) + +__include "nested-pragma-impl1.slang"; + +// CHECK-NOT: warning 30856
\ No newline at end of file diff --git a/tests/diagnostics/pragma-warning-multifile-impl1.slang b/tests/diagnostics/pragma-warning-multifile-impl1.slang new file mode 100644 index 000000000..464c0de39 --- /dev/null +++ b/tests/diagnostics/pragma-warning-multifile-impl1.slang @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +implementing test_pragma_warning; + +#pragma warning(push) +#pragma warning(disable: 30856) + +namespace impl1 +{ + interface IConvertibleFrom<From> {} + + // This should NOT produce warning 30856 due to pragma disable + extension<From : __BuiltinIntegerType, To : IConvertibleFrom<From>, let N : int> + vector<To, N> : IConvertibleFrom<vector<From, N>> {} +} + +#pragma warning(pop)
\ No newline at end of file diff --git a/tests/diagnostics/pragma-warning-multifile-impl2.slang b/tests/diagnostics/pragma-warning-multifile-impl2.slang new file mode 100644 index 000000000..16bffe6a8 --- /dev/null +++ b/tests/diagnostics/pragma-warning-multifile-impl2.slang @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +implementing test_pragma_warning; + +namespace impl2 +{ + interface IConvertibleFrom<From> {} + + // This should still NOT produce warning 30856 (but currently does due to the bug) + extension<From : __BuiltinFloatingPointType, To : IConvertibleFrom<From>, let N : int> + vector<To, N> : IConvertibleFrom<vector<From, N>> {} +}
\ No newline at end of file diff --git a/tests/diagnostics/pragma-warning-multifile-main.slang b/tests/diagnostics/pragma-warning-multifile-main.slang new file mode 100644 index 000000000..262b9abd1 --- /dev/null +++ b/tests/diagnostics/pragma-warning-multifile-main.slang @@ -0,0 +1,8 @@ +//TEST:SIMPLE(filecheck=CHECK): + +module test_pragma_warning; + +__include "pragma-warning-multifile-impl1.slang"; +__include "pragma-warning-multifile-impl2.slang"; + +// CHECK-NOT: warning 30856
\ No newline at end of file diff --git a/tests/diagnostics/pragma-warning-single-file.slang b/tests/diagnostics/pragma-warning-single-file.slang new file mode 100644 index 000000000..df1e2b77e --- /dev/null +++ b/tests/diagnostics/pragma-warning-single-file.slang @@ -0,0 +1,26 @@ +//TEST:SIMPLE(filecheck=CHECK): + +module test_pragma_warning_single; + +namespace test1 +{ + interface IConvertibleFrom<From> {} + + // This SHOULD produce warning 30856 because it's not disabled + extension<From : __BuiltinIntegerType, To : IConvertibleFrom<From>, let N : int> + vector<To, N> : IConvertibleFrom<vector<From, N>> {} +} + +#pragma warning(disable: 30856) + +namespace test2 +{ + interface IConvertibleFrom<From> {} + + // This should NOT produce warning 30856 due to pragma disable + extension<From : __BuiltinFloatingPointType, To : IConvertibleFrom<From>, let N : int> + vector<To, N> : IConvertibleFrom<vector<From, N>> {} +} + +// CHECK: warning 30856 +// CHECK-NOT: 30856
\ No newline at end of file |
