Skip to content

Commit f0890c3

Browse files
committed
pr-feedback
1 parent c3f3d51 commit f0890c3

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

clang/lib/AST/Type.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5152,9 +5152,6 @@ bool Type::isHLSLIntangibleType() const {
51525152
CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
51535153
assert(RD != nullptr &&
51545154
"all HLSL structs and classes should be CXXRecordDecl");
5155-
5156-
if (!RD->isCompleteDefinition())
5157-
return false;
51585155
assert(RD->isCompleteDefinition() && "expecting complete type");
51595156
return RD->isHLSLIntangible();
51605157
}

clang/lib/Sema/SemaDecl.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6900,6 +6900,16 @@ void Sema::deduceHLSLAddressSpace(VarDecl *Decl) {
69006900
if (Type->isSamplerT() || Type->isVoidType())
69016901
return;
69026902

6903+
// Template instantiations can lack definition. In such case,
6904+
// we cannot deduce the AS.
6905+
// FIXME: figure out why RWBuffer<float> yields such declaration.
6906+
if (const RecordType *RT =
6907+
dyn_cast<RecordType>(Type->getUnqualifiedDesugaredType())) {
6908+
CXXRecordDecl *RD = Type->getAsCXXRecordDecl();
6909+
if (RD && !RD->isCompleteDefinition())
6910+
return;
6911+
}
6912+
69036913
// Resource handles.
69046914
if (Type->isHLSLIntangibleType())
69056915
return;
@@ -7807,9 +7817,6 @@ NamedDecl *Sema::ActOnVariableDeclarator(
78077817
NewVD = VarDecl::Create(Context, DC, D.getBeginLoc(),
78087818
D.getIdentifierLoc(), II, R, TInfo, SC);
78097819

7810-
if (getLangOpts().HLSL)
7811-
deduceHLSLAddressSpace(NewVD);
7812-
78137820
// If this is supposed to be a variable template, create it as such.
78147821
if (IsVariableTemplate) {
78157822
NewTemplate =
@@ -7995,9 +8002,6 @@ NamedDecl *Sema::ActOnVariableDeclarator(
79958002
}
79968003
}
79978004

7998-
if (getLangOpts().HLSL)
7999-
deduceHLSLAddressSpace(NewVD);
8000-
80018005
// WebAssembly tables are always in address space 1 (wasm_var). Don't apply
80028006
// address space if the table has local storage (semantic checks elsewhere
80038007
// will produce an error anyway).
@@ -8013,8 +8017,11 @@ NamedDecl *Sema::ActOnVariableDeclarator(
80138017
// Handle attributes prior to checking for duplicates in MergeVarDecl
80148018
ProcessDeclAttributes(S, NewVD, D);
80158019

8016-
if (getLangOpts().HLSL)
8020+
if (getLangOpts().HLSL) {
80178021
HLSL().ActOnVariableDeclarator(NewVD);
8022+
deduceHLSLAddressSpace(NewVD);
8023+
}
8024+
80188025
if (getLangOpts().OpenACC)
80198026
OpenACC().ActOnVariableDeclarator(NewVD);
80208027

clang/test/AST/HLSL/private.hlsl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -ast-dump -o - %s | FileCheck %s
2+
3+
// CHECK: VarDecl {{.*}} global_scalar 'hlsl_private int' static cinit
4+
static int global_scalar = 0;
5+
6+
// CHECK: VarDecl {{.*}} global_buffer 'RWBuffer<float>':'hlsl::RWBuffer<float>' static callinit
7+
RWBuffer<float> global_buffer;
8+
9+
class A {
10+
// CHECK: VarDecl {{.*}} a 'hlsl_private int' static
11+
static int a;
12+
};
13+
14+
class B {
15+
// CHECK: VarDecl {{.*}} b 'hlsl_private int' static
16+
static int b;
17+
};
18+
19+
// CHECK: VarDecl {{.*}} b 'hlsl_private int' cinit
20+
int B::b = 0;
21+
22+
export void foo() {
23+
// CHECK: VarDecl {{.*}} local_buffer 'RWBuffer<float>':'hlsl::RWBuffer<float>' cinit
24+
RWBuffer<float> local_buffer = global_buffer;
25+
26+
// CHECK: VarDecl {{.*}} static_local_buffer 'RWBuffer<float>':'hlsl::RWBuffer<float>' static cinit
27+
static RWBuffer<float> static_local_buffer = global_buffer;
28+
29+
// CHECK: VarDecl {{.*}} local_scalar 'int' cinit
30+
int local_scalar = global_scalar;
31+
32+
// CHECK: VarDecl {{.*}} static_scalar 'hlsl_private int' static cinit
33+
static int static_scalar = 0;
34+
}

0 commit comments

Comments
 (0)