Skip to content

Commit

Permalink
Ignoring constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
venkataram-nv committed Jul 3, 2024
1 parent c994e55 commit 76c1dcf
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 1,128 deletions.
1,092 changes: 0 additions & 1,092 deletions ir

This file was deleted.

36 changes: 30 additions & 6 deletions source/slang/slang-ir-use-uninitialized-values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Slang
bool metaOp(IRInst* inst) {
switch (inst->getOp())
{
// These instructions only look at the parameter's type,
// so passing an undefined value to them is permissible
case kIROp_IsBool:
case kIROp_IsInt:
case kIROp_IsUnsignedInt:
Expand Down Expand Up @@ -96,6 +98,23 @@ namespace Slang

return false;
}

bool constructor(IRFunc* func)
{
const UnownedStringSlice slice = toSlice("$init");

auto decoratorList = func->getDecorations();
for (auto head = decoratorList.first; head; head = head->next) {
if (auto name = as<IRNameHintDecoration>(head)) {
auto str = name->getName();
auto index = str.indexOf(slice);
if (index >= 0)
return true;
}
}

return false;
}

List<IRInst*> concernableUsers(IRInst* inst)
{
Expand Down Expand Up @@ -141,24 +160,25 @@ namespace Slang
{
case kIROp_loop:
// TODO: Ignore loops for now
// printf("LOOP: (%p)\n", as<IRLoop>(user));
// user->dump();
return;

// These instructions will store data...
case kIROp_Store:
case kIROp_SwizzledStore:
// TODO: for calls, should make check that the function is passing as an out param
// TODO: for calls, should make check that the function is passing as an out param
case kIROp_Call:
case kIROp_SPIRVAsm:
// For now assume that __intrinsic_asm blocks will do the right thing...
case kIROp_GenericAsm:
// For now assume that __intrinsic_asm blocks will do the right thing...
stores.add(user);
break;
// For SPIRV asm instructions, need to check out the entire
// block when doing reachability checks

case kIROp_SPIRVAsmOperandInst:
// For SPIRV asm instructions, need to check out the entire
// block when doing reachability checks
stores.add(user->getParent());
break;

// ... and the rest will load/use them
default:
loads.add(user);
Expand Down Expand Up @@ -238,6 +258,10 @@ namespace Slang
if (synthesized(func))
return;

// Also skip for constructors; can add more complex diagnosis for such cases later
if (constructor(func))
return;

auto firstBlock = func->getFirstBlock();
if (!firstBlock)
return;
Expand Down
3 changes: 1 addition & 2 deletions tests/autodiff/material2/MxLayeredMaterial.slang
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public struct MxLayeredMaterial : IMaterial
public UsedMaterialInstance setupMaterialInstance(out MaterialInstanceData miData)
{
float3 albedo = getAlbedo(baseColor);
UsedMaterialInstance mi;
for (uint i = 0; i < 3; i++) miData.data[i] = albedo[i];
return mi;
return UsedMaterialInstance();
}
}
2 changes: 1 addition & 1 deletion tests/autodiff/treat-as-differentiable-1.slang
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ float use(IFoo o, float x)
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
B b;
B b = B();
var p = diffPair(1.0);
__bwd_diff(use)(b, p, 1.0);
outputBuffer[0] = p.d;
Expand Down
2 changes: 1 addition & 1 deletion tests/bugs/interface-type-self-ref.slang
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ int f(IFoo p)
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
{
int index = dispatchThreadID.x;
Impl impl;
Impl impl = Impl();
outputBuffer[index] = f(impl);
}
2 changes: 1 addition & 1 deletion tests/bugs/specialize-existential-in-generic.slang
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface IFoo
struct Impl : IFoo
{
struct Assoc : IAssoc { int getInner() { return 1; } }
Assoc getValue() { Assoc r; return r; }
Assoc getValue() { Assoc r = Assoc(); return r; }
}

struct GenType<T : IFoo>
Expand Down
49 changes: 27 additions & 22 deletions tests/diagnostics/uninitialized-variables.slang
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
//TEST:SIMPLE(filecheck=CHK): -target spirv

// Using unitialized values
int use_undefined_value(int k)
{
int x;
x += k;
//CHK: error 41015: use of uninitialized value 'x'
return x;
}

// Returning uninitialized values
__generic<T>
T generic_undefined_return()
{
T x;
//CHK: warning 41018: returning without initializing 'x'
return x;
}

// No warnings here, even thought autodiff generates
// IR which frequently returns undefined values
struct DiffStruct : IDifferentiable
{
Texture2D tex;
}

[BackwardDifferentiable]
float f(float x)
{
return x;
}

// Structs and nested structs
struct Data
{
float value;
Expand All @@ -33,29 +36,31 @@ struct NestedData
Data data;
};

RWStructuredBuffer<Data> inputBuffer;
RWStructuredBuffer<Data> outputBuffer;
// Empty structures should not generate diagnostics
// for empty default constructors
struct EmptyStruct
{
__init() {}
};

[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
float4 main()
{
uint tid = dispatchThreadID.x;
Data inputData = Data(1.0);

Data inputData = inputBuffer[tid];
float undefVar;
Data undefData;
NestedData nestedData;

float uninitializedVariable;
float result = inputData.value;

// CHECK: warning
float outputData = inputData.value;
outputData += uninitializedVariable;
outputData += undefData.value;
outputData += nestedData.data.value;
//CHK: error 41015: use of uninitialized value 'undefVar'
result += undefVar;

//CHK: error 41015: use of uninitialized value 'undefData'
result += undefData.value;

var dp = diffPair(1.0);
__bwd_diff(f)(dp, 1.0);
outputData += dp.d.x;
//CHK: error 41015: use of uninitialized value 'nestedData'
result += nestedData.data.value;

outputBuffer[tid].value = outputData;
return float4(result);
}
2 changes: 1 addition & 1 deletion tests/experiments/generic/type-to-value-4.slang
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{

// Err.. even though IGetE doesn't require an instanciation, not clear how to set it. So lets try with instanciation
B b;
B b = B();
IGetE g = b;

let e = g.getE();
Expand Down
4 changes: 2 additions & 2 deletions tests/language-feature/if-let/if-let-1.slang
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ int test1<T>(T t)
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
MyImpl1 impl1;
MyImpl2 impl2;
MyImpl1 impl1 = MyImpl1();
MyImpl2 impl2 = MyImpl2();
// CHECK: 1
// CHECK: 7
outputBuffer[0] = test(impl1, 1);
Expand Down

0 comments on commit 76c1dcf

Please sign in to comment.