Skip to content
Merged
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
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17567,6 +17567,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
// parsing of the struct).
if (TUK == TagUseKind::Definition &&
(!SkipBody || !SkipBody->ShouldSkip)) {
if (LangOpts.HLSL)
RD->addAttr(PackedAttr::CreateImplicit(Context));
AddAlignmentAttributesForRecord(RD);
AddMsStructLayoutForRecord(RD);
}
Expand Down Expand Up @@ -18257,6 +18259,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
// the #pragma tokens are effectively skipped over during the
// parsing of the struct).
if (TUK == TagUseKind::Definition && (!SkipBody || !SkipBody->ShouldSkip)) {
if (LangOpts.HLSL)
RD->addAttr(PackedAttr::CreateImplicit(Context));
AddAlignmentAttributesForRecord(RD);
AddMsStructLayoutForRecord(RD);
}
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,8 @@ DeclResult Sema::CheckClassTemplate(
// Add alignment attributes if necessary; these attributes are checked when
// the ASTContext lays out the structure.
if (TUK == TagUseKind::Definition && (!SkipBody || !SkipBody->ShouldSkip)) {
if (LangOpts.HLSL)
NewClass->addAttr(PackedAttr::CreateImplicit(Context));
AddAlignmentAttributesForRecord(NewClass);
AddMsStructLayoutForRecord(NewClass);
}
Expand Down Expand Up @@ -8655,6 +8657,8 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
// Add alignment attributes if necessary; these attributes are checked when
// the ASTContext lays out the structure.
if (TUK == TagUseKind::Definition && (!SkipBody || !SkipBody->ShouldSkip)) {
if (LangOpts.HLSL)
Specialization->addAttr(PackedAttr::CreateImplicit(Context));
AddAlignmentAttributesForRecord(Specialization);
AddMsStructLayoutForRecord(Specialization);
}
Expand Down
13 changes: 13 additions & 0 deletions clang/test/AST/HLSL/PackedStruct.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -ast-dump %s | FileCheck %s
// Structs are packed by default in HLSL

#include <hlsl/hlsl_basic_types.h>

// CHECK: CXXRecordDecl {{.*}} struct S definition
// CHECK: DefinitionData
// CHECK: PackedAttr {{.*}} Implicit
// CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct S
struct S {
float2 f;
int i;
};
6 changes: 3 additions & 3 deletions clang/test/CodeGenHLSL/ArrayAssignable.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct S {
// CHECK: @c1 = external addrspace(2) global [2 x float], align 4
// CHECK: @c2 = external addrspace(2) global [2 x <4 x i32>], align 16
// CHECK: @c3 = external addrspace(2) global [2 x [2 x i32]], align 4
// CHECK: @c4 = external addrspace(2) global [1 x target("dx.Layout", %S, 8, 0, 4)], align 4
// CHECK: @c4 = external addrspace(2) global [1 x target("dx.Layout", %S, 8, 0, 4)], align 1

cbuffer CBArrays : register(b0) {
float c1[2];
Expand Down Expand Up @@ -169,8 +169,8 @@ void arr_assign10() {
}

// CHECK-LABEL: define void {{.*}}arr_assign11
// CHECK: [[C:%.*]] = alloca [1 x %struct.S], align 4
// CHECK: call void @llvm.memcpy.p0.p2.i32(ptr align 4 [[C]], ptr addrspace(2) align 4 @c4, i32 8, i1 false)
// CHECK: [[C:%.*]] = alloca [1 x %struct.S], align 1
// CHECK: call void @llvm.memcpy.p0.p2.i32(ptr align 1 [[C]], ptr addrspace(2) align 1 @c4, i32 8, i1 false)
// CHECK-NEXT: ret void
void arr_assign11() {
S s = {1, 2.0};
Expand Down
6 changes: 3 additions & 3 deletions clang/test/CodeGenHLSL/ArrayTemporary.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void fn2(Obj O[4]) { }
// CHECK-LABEL: define void {{.*}}call2{{.*}}
// CHECK: [[Arr:%.*]] = alloca [4 x %struct.Obj]
// CHECK: [[Tmp:%.*]] = alloca [4 x %struct.Obj]
// CHECK: call void @llvm.memset.p0.i32(ptr align 4 [[Arr]], i8 0, i32 32, i1 false)
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[Tmp]], ptr align 4 [[Arr]], i32 32, i1 false)
// CHECK: call void {{.*}}fn2{{.*}}(ptr noundef byval([4 x %struct.Obj]) align 4 [[Tmp]])
// CHECK: call void @llvm.memset.p0.i32(ptr align 1 [[Arr]], i8 0, i32 32, i1 false)
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[Tmp]], ptr align 1 [[Arr]], i32 32, i1 false)
// CHECK: call void {{.*}}fn2{{.*}}(ptr noundef byval([4 x %struct.Obj]) align 1 [[Tmp]])
void call2() {
Obj Arr[4] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
fn2(Arr);
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGenHLSL/BasicFeatures/AggregateSplatCast.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct S {
// struct splats
// CHECK-LABEL: define void {{.*}}call3
// CHECK: [[A:%.*]] = alloca <1 x i32>, align 4
// CHECK: [[s:%.*]] = alloca %struct.S, align 4
// CHECK: [[s:%.*]] = alloca %struct.S, align 1
// CHECK-NEXT: store <1 x i32> splat (i32 1), ptr [[A]], align 4
// CHECK-NEXT: [[L:%.*]] = load <1 x i32>, ptr [[A]], align 4
// CHECK-NEXT: [[VL:%.*]] = extractelement <1 x i32> [[L]], i32 0
Expand All @@ -72,7 +72,7 @@ export void call3() {
// struct splat from vector of length 1
// CHECK-LABEL: define void {{.*}}call5
// CHECK: [[A:%.*]] = alloca <1 x i32>, align 4
// CHECK-NEXT: [[s:%.*]] = alloca %struct.S, align 4
// CHECK-NEXT: [[s:%.*]] = alloca %struct.S, align 1
// CHECK-NEXT: store <1 x i32> splat (i32 1), ptr [[A]], align 4
// CHECK-NEXT: [[L:%.*]] = load <1 x i32>, ptr [[A]], align 4
// CHECK-NEXT: [[VL:%.*]] = extractelement <1 x i32> [[L]], i32 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ struct S {

// flatten and truncate from a struct
// CHECK-LABEL: define void {{.*}}call7
// CHECK: [[s:%.*]] = alloca %struct.S, align 4
// CHECK: [[s:%.*]] = alloca %struct.S, align 1
// CHECK-NEXT: [[A:%.*]] = alloca [1 x i32], align 4
// CHECK-NEXT: [[Tmp:%.*]] = alloca %struct.S, align 4
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[s]], ptr align 4 {{.*}}, i32 8, i1 false)
// CHECK-NEXT: [[Tmp:%.*]] = alloca %struct.S, align 1
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[s]], ptr align 1 {{.*}}, i32 8, i1 false)
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[A]], ptr align 4 {{.*}}, i32 4, i1 false)
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[Tmp]], ptr align 4 [[s]], i32 8, i1 false)
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[Tmp]], ptr align 1 [[s]], i32 8, i1 false)
// CHECK-NEXT: [[G1:%.*]] = getelementptr inbounds [1 x i32], ptr [[A]], i32 0, i32 0
// CHECK-NEXT: [[G2:%.*]] = getelementptr inbounds %struct.S, ptr [[Tmp]], i32 0, i32 0
// CHECK-NEXT: [[G3:%.*]] = getelementptr inbounds %struct.S, ptr [[Tmp]], i32 0, i32 1
Expand All @@ -141,4 +141,3 @@ export void call7() {
int A[1] = {1};
A = (int[1])s;
}

Loading
Loading