[clang] acd1c6c - [HLSL] Handle `this` in dynamic resource indexing validation (#239876)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 12 09:47:18 PST 2026
Author: Helena Kotas
Date: 2026-11-12T09:47:13-08:00
New Revision: acd1c6c90f3f36b8f320d4eb39ce8de4882fe461
URL: https://github.com/llvm/llvm-project/commit/acd1c6c90f3f36b8f320d4eb39ce8de4882fe461
DIFF: https://github.com/llvm/llvm-project/commit/acd1c6c90f3f36b8f320d4eb39ce8de4882fe461.diff
LOG: [HLSL] Handle `this` in dynamic resource indexing validation (#239876)
Fixes an `llvm_unreachable` assert in dynamic resource index validation
when a resource member is accessed in a member function using `this`.
Fixes #239858
Added:
clang/test/CodeGenHLSL/resources/resources-in-structs-this-access.hlsl
Modified:
clang/lib/Sema/SemaHLSL.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index b61e0a5ed7118..348f0d1a9f946 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -3671,6 +3671,8 @@ bool SemaHLSL::ActOnResourceMemberAccessExpr(MemberExpr *ME) {
E = SubME->getBase();
} else if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E)) {
E = ICE->getSubExpr();
+ } else if (isa<CXXThisExpr>(E)) {
+ return true;
} else {
llvm_unreachable("unexpected expr type in resource member access");
}
diff --git a/clang/test/CodeGenHLSL/resources/resources-in-structs-this-access.hlsl b/clang/test/CodeGenHLSL/resources/resources-in-structs-this-access.hlsl
new file mode 100644
index 0000000000000..b072fb4a00877
--- /dev/null
+++ b/clang/test/CodeGenHLSL/resources/resources-in-structs-this-access.hlsl
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -finclude-default-header -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt | FileCheck %s
+
+// Regression test for issue #239858
+
+// CHECK: %"class.hlsl::RWBuffer" = type { target("dx.TypedBuffer", i32, 1, 0, 1) }
+
+struct A {
+ RWBuffer<int> Buf;
+
+ int get(uint Index) const {
+ return this.Buf[Index] + this.Buf.Load(Index);;
+ }
+};
+
+// Global variables for resources in `a` and `array`
+//
+// CHECK-DAG: @a.Buf = internal global %"class.hlsl::RWBuffer" poison, align 4
+// CHECK-DAG: @[[aBufStr:.*]] = private unnamed_addr constant [6 x i8] c"a.Buf\00", align 1
+// CHECK-DAG: @array.0.Buf = internal global %"class.hlsl::RWBuffer" poison, align 4
+// CHECK-DAG: @[[array0BufStr:.*]] = private unnamed_addr constant [12 x i8] c"array.0.Buf\00", align 1
+// CHECK-DAG: @array.1.Buf = internal global %"class.hlsl::RWBuffer" poison, align 4
+// CHECK-DAG: @[[array1BufStr:.*]] = private unnamed_addr constant [12 x i8] c"array.1.Buf\00", align 1
+
+A a : register(u5);
+A array[2];
+
+[numthreads(8, 1, 1)]
+void main(uint3 ID : SV_GroupThreadID) {
+ a.Buf[ID.x] = a.get(ID.x) + array[1].get(ID.x);
+}
More information about the cfe-commits
mailing list