summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-07-30 17:17:24 -0400
committerGitHub <noreply@github.com>2024-07-30 14:17:24 -0700
commitff6519f0bc11ccb71fe5863d3de92660eeedfb5d (patch)
treee23d0d060150d1b48f884edc272247d5af8de49f
parentc94fd84eff090f326403e67e712bf38e9e27c36c (diff)
Set `nullptr` to the default value of the target VarDeclBase (#4757)
-rw-r--r--source/slang/slang-check-conversion.cpp6
-rw-r--r--tests/bugs/assign-nullptr.slang14
2 files changed, 19 insertions, 1 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp
index fafefa9dd..c66d4092e 100644
--- a/source/slang/slang-check-conversion.cpp
+++ b/source/slang/slang-check-conversion.cpp
@@ -903,7 +903,11 @@ namespace Slang
*outCost = kConversionCost_NullPtrToPtr;
}
if (outToExpr)
- *outToExpr = fromExpr;
+ {
+ auto* defaultExpr = getASTBuilder()->create<DefaultConstructExpr>();
+ defaultExpr->type = QualType(toType);
+ *outToExpr = defaultExpr;
+ }
return true;
}
// none_t can be cast into any Optional<T> type.
diff --git a/tests/bugs/assign-nullptr.slang b/tests/bugs/assign-nullptr.slang
new file mode 100644
index 000000000..aa9763e17
--- /dev/null
+++ b/tests/bugs/assign-nullptr.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry computeMain -O0
+
+//CHECK: %[[NULLPTR_VAL:[a-zA-Z0-9_]+]] = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_int %{{.*}}
+//CHECK: OpStore %ptr %[[NULLPTR_VAL]]
+
+[vk::push_constant] int* dest;
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int* ptr = nullptr;
+ if (dispatchThreadID.x % 2 == 0) ptr = dest;
+ if (ptr) *ptr = 123;
+
+}