llvm-project/clang/test/CodeGenHLSL/buffer-array-operator.hlsl
Helena Kotas e20bf28987
[HLSL] Replace element_type* handles in HLSLExternalSemaSource with __hlsl_resource_t builtin type (#110079)
Replace `element_type*` handles in HLSLExternalSemaSource with
`__hlsl_resource_t` builtin type.

The handle used to be defined as `element_type*` which was used by the
provisional subscript operator implementation. Now that the handle is
`__hlsl_resource_t` the subscript placeholder implementation was updated
to add `element_type* e;` field to the resource struct. and return a
reference to that. This field is just a temporary workaround until the
indexing is implemented properly in llvm/llvm-project#95956, at which
point the field will be removed. This seemed like a better solution than
disabling many of the existing tests that already use the `[]` operator.
One test has to be disabled nevertheless because an error based on
interactions of const and template instantiation (potential bug that can
be investigated once indexing is implemented the right way).

Fixes #84824
2024-09-29 20:41:54 -07:00

34 lines
1.4 KiB
HLSL

// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
// XFAIL: *
// Resource indexing will be properly implemented in llvm/llvm-project#95956
const RWBuffer<float> In;
RWBuffer<float> Out;
void fn(int Idx) {
Out[Idx] = In[Idx];
}
// This test is intended to verify reasonable code generation of the subscript
// operator. In this test case we should be generating both the const and
// non-const operators so we verify both cases.
// Non-const comes first.
// CHECK: ptr @"??A?$RWBuffer@M@hlsl@@QBAAAMI@Z"
// CHECK: %this1 = load ptr, ptr %this.addr, align 4
// CHECK-NEXT: %h = getelementptr inbounds nuw %"class.hlsl::RWBuffer", ptr %this1, i32 0, i32 0
// CHECK-NEXT: %0 = load ptr, ptr %h, align 4
// CHECK-NEXT: %1 = load i32, ptr %Idx.addr, align 4
// CHECK-NEXT: %arrayidx = getelementptr inbounds nuw float, ptr %0, i32 %1
// CHECK-NEXT: ret ptr %arrayidx
// Const comes next, and returns the pointer instead of the value.
// CHECK: ptr @"??A?$RWBuffer@M@hlsl@@QAAAAMI@Z"
// CHECK: %this1 = load ptr, ptr %this.addr, align 4
// CHECK-NEXT: %h = getelementptr inbounds nuw %"class.hlsl::RWBuffer", ptr %this1, i32 0, i32 0
// CHECK-NEXT: %0 = load ptr, ptr %h, align 4
// CHECK-NEXT: %1 = load i32, ptr %Idx.addr, align 4
// CHECK-NEXT: %arrayidx = getelementptr inbounds nuw float, ptr %0, i32 %1
// CHECK-NEXT: ret ptr %arrayidx