From 8a36695f1f3abaf98831d4512e74ebd5bce1494e Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 22 Jul 2025 22:53:19 +0000 Subject: Fix public unscoped enum constants not visible across module boundaries (#7864) * Initial plan * Fix public unscoped enum constants visibility across module boundaries Add visibility modifier copying in CompleteDecl for unscoped enum cases. When synthesizing static const declarations for unscoped enum cases, copy the visibility modifiers from the original enum declaration to ensure they have the same visibility scope across module boundaries. Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Create new visibility modifier instances instead of sharing existing ones Address reviewer feedback to avoid sharing modifier instances between declarations since modifiers form a linked list. Now creates new instances of the appropriate visibility modifier type (Public, Private, or Internal) instead of reusing the existing instance. Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Move unscoped enum visibility tests into subdirectory structure Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Use createByNodeType for visibility modifier creation as suggested Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * format code (#7867) Co-authored-by: slangbot <186143334+slangbot@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: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- .../unscoped_enum_lib.slang | 8 ++++++ .../unscoped_enum_user.slang | 29 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/language-feature/modules/unscoped-enum-visibility/unscoped_enum_lib.slang create mode 100644 tests/language-feature/modules/unscoped-enum-visibility/unscoped_enum_user.slang (limited to 'tests') diff --git a/tests/language-feature/modules/unscoped-enum-visibility/unscoped_enum_lib.slang b/tests/language-feature/modules/unscoped-enum-visibility/unscoped_enum_lib.slang new file mode 100644 index 000000000..7982d8baa --- /dev/null +++ b/tests/language-feature/modules/unscoped-enum-visibility/unscoped_enum_lib.slang @@ -0,0 +1,8 @@ +// Library module containing a public unscoped enum + +[UnscopedEnum] +public enum TestEnum +{ + CASE_A, + CASE_B +}; \ No newline at end of file diff --git a/tests/language-feature/modules/unscoped-enum-visibility/unscoped_enum_user.slang b/tests/language-feature/modules/unscoped-enum-visibility/unscoped_enum_user.slang new file mode 100644 index 000000000..e20f387fb --- /dev/null +++ b/tests/language-feature/modules/unscoped-enum-visibility/unscoped_enum_user.slang @@ -0,0 +1,29 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type +// +// Test for public unscoped enum constants visibility across module boundaries +// +// This test verifies that unscoped enum constants are visible across module +// boundaries when the enum is declared as public. +// + +import unscoped_enum_lib; + +//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4) +RWStructuredBuffer outputBuffer; + +[numthreads(1,1,1)] +void computeMain() +{ + // These should all be visible due to the public unscoped enum + TestEnum e1 = CASE_A; // Should work - unscoped access + TestEnum e2 = TestEnum.CASE_B; // Should work - scoped access + + // CHECK: 0 + outputBuffer[0] = (uint)e1; + // CHECK: 1 + outputBuffer[1] = (uint)e2; + // CHECK: 0 + outputBuffer[2] = (uint)CASE_A; + // CHECK: 1 + outputBuffer[3] = (uint)CASE_B; +} \ No newline at end of file -- cgit v1.2.3