Skip to content

Commit aa2b0c6

Browse files
committed
[SPIR-V] Support sizeof(vk::BufferPointer)
This commit enables sizeof operator support for vk::BufferPointer types. It updates SemaExpr to allow vk::BufferPointer in sizeof expressions, and modifies ASTContext to correctly report the size and alignment of vk::BufferPointer as equivalent to uint64_t. Fixes #7998
1 parent 5f29bff commit aa2b0c6

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

tools/clang/lib/AST/ASTContext.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "llvm/Support/MathExtras.h"
4141
#include "llvm/Support/raw_ostream.h"
4242
#include "llvm/Support/MathExtras.h" // HLSL Change
43+
#include "clang/AST/HlslTypes.h" // HLSL Change
4344
#include <map>
4445

4546
using namespace clang;
@@ -1804,6 +1805,17 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
18041805

18051806
const RecordType *RT = cast<RecordType>(TT);
18061807
const RecordDecl *RD = RT->getDecl();
1808+
// HLSL Change Begins
1809+
#ifdef ENABLE_SPIRV_CODEGEN
1810+
if (hlsl::IsVKBufferPointerType(QualType(T, 0))) {
1811+
TypeInfo Info = getTypeInfo(UnsignedLongLongTy);
1812+
Width = Info.Width;
1813+
Align = Info.Align;
1814+
AlignIsRequired = Info.AlignIsRequired;
1815+
break;
1816+
}
1817+
#endif
1818+
// HLSL Change Ends
18071819
const ASTRecordLayout &Layout = getASTRecordLayout(RD);
18081820
Width = toBits(Layout.getSize());
18091821
Align = toBits(Layout.getAlignment());

tools/clang/lib/Sema/SemaExpr.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "clang/Sema/Template.h"
4646
#include "llvm/Support/ConvertUTF.h"
4747
#include "clang/Sema/SemaHLSL.h" // HLSL Change
48+
#include "clang/AST/HlslTypes.h" // HLSL Change
4849
using namespace clang;
4950
using namespace sema;
5051

@@ -3820,6 +3821,13 @@ bool Sema::CheckHLSLUnaryExprOrTypeTraitOperand(QualType ExprType,
38203821
return true;
38213822
}
38223823

3824+
// vk::BufferPointer is allowed in sizeof
3825+
#ifdef ENABLE_SPIRV_CODEGEN
3826+
if (hlsl::IsVKBufferPointerType(ExprType)) {
3827+
return false;
3828+
}
3829+
#endif
3830+
38233831
if (!hlsl::IsHLSLNumericOrAggregateOfNumericType(ExprType)) {
38243832
Diag(Loc, diag::err_hlsl_sizeof_nonnumeric) << ExprType;
38253833
return true;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %dxc -T cs_6_0 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
struct S {
4+
float a;
5+
};
6+
7+
[numthreads(1, 1, 1)]
8+
void main() {
9+
vk::BufferPointer<S> p = vk::BufferPointer<S>(0);
10+
// CHECK: %uint_8 = OpConstant %uint 8
11+
// CHECK: OpStore %size %uint_8
12+
uint size = sizeof(p);
13+
}

0 commit comments

Comments
 (0)