Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/slang/slang-check-overload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,20 @@ int SemanticsVisitor::CompareLookupResultItems(
bool rightIsExtension = false;
bool leftIsFreeFormExtension = false;
bool rightIsFreeFormExtension = false;
bool leftIsExtern = left.declRef.getDecl()->hasModifier<ExternModifier>();
bool rigthIsExtern = right.declRef.getDecl()->hasModifier<ExternModifier>();

// If both left and right are extern, then they are equal.
// If only one of them is extern, then the other one is preferred.
// If neither is extern, then we continue with the rest of the checks.
if (leftIsExtern)
{
return (rigthIsExtern ? 0 : 1);
}
if (rigthIsExtern)
{
return (leftIsExtern ? -1 : 0);
}

// Prefer declarations that are not in free-form generic extensions, i.e.
// `extension<T:IFoo> T { /* declaration here should have lower precedence. */ }
Expand Down
32 changes: 32 additions & 0 deletions tests/library/ambiguous-extern-export-entry.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -dx12 -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-vk -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-cpu -compute -shaderobj

import "ambiguous-extern-export-lib1.slang";
import "ambiguous-extern-export-lib2.slang";

export static const int call_data_len = 6;
export static const int call_group_vector[call_data_len] = {1,2,3,4,5,6};

//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

[shader("compute")]
[numthreads(1, 1, 1)]
void computeMain()
{
initCallId1();
initCallId2();

for (int i = 0; i < call_data_len; i++)
{
outputBuffer[i] = call_id_1[i] + call_id_2[i];
}
// BUFFER: 2
// BUFFER-NEXT: 4
// BUFFER-NEXT: 6
// BUFFER-NEXT: 8
// BUFFER-NEXT: A
// BUFFER-NEXT: C
}
13 changes: 13 additions & 0 deletions tests/library/ambiguous-extern-export-lib1.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module "ambiguous-extern-export-lib1.slang";

public extern static const int call_data_len;
public extern static const int[call_data_len] call_group_vector;
public static int[call_data_len] call_id_1 = {};

public void initCallId1()
{
for (int i = 0; i < call_data_len; i++)
{
call_id_1[i] = call_group_vector[i];
}
}
15 changes: 15 additions & 0 deletions tests/library/ambiguous-extern-export-lib2.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

module "ambiguous-extern-export-lib2.slang";

public extern static const int call_data_len;
public extern static const int[call_data_len] call_group_vector;

public static int[call_data_len] call_id_2 = {};

public void initCallId2()
{
for (int i = 0; i < call_data_len; i++)
{
call_id_2[i] = call_group_vector[i];
}
}
Loading