Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tools/clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExternalASTSource.h"
#include "clang/AST/HlslTypes.h" // HLSL Change
#include "clang/AST/Mangle.h"
#include "clang/AST/MangleNumberingContext.h"
#include "clang/AST/RecordLayout.h"
Expand All @@ -38,8 +39,8 @@
#include "llvm/ADT/Triple.h"
#include "llvm/Support/Capacity.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/MathExtras.h" // HLSL Change
#include "llvm/Support/raw_ostream.h"
#include <map>

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

const RecordType *RT = cast<RecordType>(TT);
const RecordDecl *RD = RT->getDecl();
// HLSL Change Begins
#ifdef ENABLE_SPIRV_CODEGEN
if (hlsl::IsVKBufferPointerType(QualType(T, 0))) {
TypeInfo Info = getTypeInfo(UnsignedLongLongTy);
Width = Info.Width;
Align = Info.Align;
AlignIsRequired = Info.AlignIsRequired;
break;
}
#endif
// HLSL Change Ends
const ASTRecordLayout &Layout = getASTRecordLayout(RD);
Width = toBits(Layout.getSize());
Align = toBits(Layout.getAlignment());
Expand Down
14 changes: 11 additions & 3 deletions tools/clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
//
//===----------------------------------------------------------------------===//

#include "clang/AST/OperationKinds.h"
#include "clang/Sema/SemaInternal.h"
#include "TreeTransform.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
Expand All @@ -25,6 +23,8 @@
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/HlslTypes.h" // HLSL Change
#include "clang/AST/OperationKinds.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/PartialDiagnostic.h"
Expand All @@ -42,9 +42,10 @@
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaFixItUtils.h"
#include "clang/Sema/SemaHLSL.h" // HLSL Change
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/Template.h"
#include "llvm/Support/ConvertUTF.h"
#include "clang/Sema/SemaHLSL.h" // HLSL Change
using namespace clang;
using namespace sema;

Expand Down Expand Up @@ -3820,6 +3821,13 @@ bool Sema::CheckHLSLUnaryExprOrTypeTraitOperand(QualType ExprType,
return true;
}

// vk::BufferPointer is allowed in sizeof
#ifdef ENABLE_SPIRV_CODEGEN
if (hlsl::IsVKBufferPointerType(ExprType)) {
return false;
}
#endif

if (!hlsl::IsHLSLNumericOrAggregateOfNumericType(ExprType)) {
Diag(Loc, diag::err_hlsl_sizeof_nonnumeric) << ExprType;
return true;
Expand Down
13 changes: 13 additions & 0 deletions tools/clang/test/CodeGenSPIRV/vk.buffer-pointer.sizeof.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %dxc -T cs_6_0 -E main -fcgl %s -spirv | FileCheck %s

struct S {
float a;
};

[numthreads(1, 1, 1)]
void main() {
vk::BufferPointer<S> p = vk::BufferPointer<S>(0);
// CHECK: %uint_8 = OpConstant %uint 8
// CHECK: OpStore %size %uint_8
uint size = sizeof(p);
}