summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-07-22 22:53:19 +0000
committerGitHub <noreply@github.com>2025-07-22 22:53:19 +0000
commit8a36695f1f3abaf98831d4512e74ebd5bce1494e (patch)
tree54705e7f8d6eea7db55e20f3de96ed4629f2b5ad
parentb16d4e955fdba3d68d156f944260f8b7a157fd4d (diff)
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 <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
-rw-r--r--source/slang/slang-parser.cpp9
-rw-r--r--tests/language-feature/modules/unscoped-enum-visibility/unscoped_enum_lib.slang8
-rw-r--r--tests/language-feature/modules/unscoped-enum-visibility/unscoped_enum_user.slang29
3 files changed, 46 insertions, 0 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index a12f216b1..891db2867 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -4972,6 +4972,15 @@ static void CompleteDecl(
staticConstDecl->nameAndLoc = enumCase->nameAndLoc;
addModifier(staticConstDecl, parser->astBuilder->create<HLSLStaticModifier>());
addModifier(staticConstDecl, parser->astBuilder->create<ConstModifier>());
+
+ // Copy visibility modifiers from the enum declaration
+ if (auto visibilityModifier = modifiers.findModifier<VisibilityModifier>())
+ {
+ auto newVisibilityModifier = as<VisibilityModifier>(
+ parser->astBuilder->createByNodeType(visibilityModifier->astNodeType));
+ addModifier(staticConstDecl, newVisibilityModifier);
+ }
+
auto valueExpr = parser->astBuilder->create<VarExpr>();
valueExpr->declRef = DeclRef<Decl>(enumCase);
staticConstDecl->initExpr = valueExpr;
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<uint> 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