summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2025-05-23 00:57:08 -0400
committerGitHub <noreply@github.com>2025-05-23 04:57:08 +0000
commit6209f69f335a604604a5032b0f5c38b4b8bc861a (patch)
tree4978f52e3a37b51cb7c198366c2e7e127d361215
parent3072cfea95aad2a9ddab0f517c8f18f634442a27 (diff)
Add default constructor for Ptr type (#7214)
* Add default constructor for Ptr type * Make pointers c-style type, remove __init() constructor
-rw-r--r--source/slang/slang-check-conversion.cpp3
-rw-r--r--tests/spirv/pointer-default-constructor.slang26
2 files changed, 28 insertions, 1 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp
index 705da89e3..fcbc83673 100644
--- a/source/slang/slang-check-conversion.cpp
+++ b/source/slang/slang-check-conversion.cpp
@@ -246,7 +246,8 @@ bool SemanticsVisitor::isCStyleType(Type* type, HashSet<Type*>& isVisit)
// 1. It has to be basic scalar, vector or matrix type, or user-defined struct.
if (as<VectorExpressionType>(type) || as<MatrixExpressionType>(type) ||
- as<BasicExpressionType>(type) || isDeclRefTypeOf<EnumDecl>(type).getDecl())
+ as<BasicExpressionType>(type) || isDeclRefTypeOf<EnumDecl>(type).getDecl() ||
+ as<PtrType>(type))
return cacheResult(true);
diff --git a/tests/spirv/pointer-default-constructor.slang b/tests/spirv/pointer-default-constructor.slang
new file mode 100644
index 000000000..6ab29f125
--- /dev/null
+++ b/tests/spirv/pointer-default-constructor.slang
@@ -0,0 +1,26 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -emit-spirv-directly -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<uint> outputBuffer;
+
+struct MyStruct
+{
+ int* ptr;
+}
+
+[shader("compute")]
+[numthreads(1, 1, 1)]
+void computeMain()
+{
+ float* a = {};
+ MyStruct ms = {};
+
+ // CHECK: 0
+ outputBuffer[0] = uint(uint64_t(a));
+ // CHECK: 1
+ outputBuffer[1] = uint(a == nullptr);
+ // CHECK: 0
+ outputBuffer[2] = uint(uint64_t(ms.ptr));
+ // CHECK: 1
+ outputBuffer[3] = uint(ms.ptr == nullptr);
+}