Skip to content

Commit 526c1cd

Browse files
committed
Support HLSL matrix initializers
fixes #159434 In HLSL matrices are `matrix_type` in all respects except that they support a constructor style syntax for initializing matrices. This change adds a translation of vector constructor arguments into initializer lists. This supports the following HLSL syntax: (1) HLSL matrices support constructor syntax (2) HLSL matrices are expanded to constituate components in constructor
1 parent 738e927 commit 526c1cd

File tree

6 files changed

+563
-23
lines changed

6 files changed

+563
-23
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6543,9 +6543,9 @@ def warn_extern_init : Warning<"'extern' variable has an initializer">,
65436543
def err_variable_object_no_init : Error<
65446544
"variable-sized object may not be initialized">;
65456545
def err_excess_initializers : Error<
6546-
"excess elements in %select{array|vector|scalar|union|struct}0 initializer">;
6546+
"excess elements in %select{array|vector|matrix|scalar|union|struct}0 initializer">;
65476547
def ext_excess_initializers : ExtWarn<
6548-
"excess elements in %select{array|vector|scalar|union|struct}0 initializer">,
6548+
"excess elements in %select{array|vector|matrix|scalar|union|struct}0 initializer">,
65496549
InGroup<ExcessInitializers>;
65506550
def err_excess_initializers_for_sizeless_type : Error<
65516551
"excess elements in initializer for indivisible sizeless type %0">;
@@ -11086,8 +11086,8 @@ def err_first_argument_to_cwsc_pdtor_call : Error<
1108611086
def err_second_argument_to_cwsc_not_pointer : Error<
1108711087
"second argument to __builtin_call_with_static_chain must be of pointer type">;
1108811088

11089-
def err_vector_incorrect_num_elements : Error<
11090-
"%select{too many|too few}0 elements in vector %select{initialization|operand}3 (expected %1 elements, have %2)">;
11089+
def err_tensor_incorrect_num_elements : Error<
11090+
"%select{too many|too few}0 elements in %select{vector|matrix}1 %select{initialization|operand}4 (expected %2 elements, have %3)">;
1109111091
def err_altivec_empty_initializer : Error<"expected initializer">;
1109211092

1109311093
def err_vector_incorrect_bit_count : Error<

clang/include/clang/Sema/Initialization.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class alignas(8) InitializedEntity {
9191
/// or vector.
9292
EK_VectorElement,
9393

94+
/// The entity being initialized is an element of a matrix.
95+
/// or matrix.
96+
EK_MatrixElement,
97+
9498
/// The entity being initialized is a field of block descriptor for
9599
/// the copied-in c++ object.
96100
EK_BlockElement,
@@ -205,8 +209,8 @@ class alignas(8) InitializedEntity {
205209
/// virtual base.
206210
llvm::PointerIntPair<const CXXBaseSpecifier *, 1> Base;
207211

208-
/// When Kind == EK_ArrayElement, EK_VectorElement, or
209-
/// EK_ComplexElement, the index of the array or vector element being
212+
/// When Kind == EK_ArrayElement, EK_VectorElement, or EK_MatrixElement,
213+
/// or EK_ComplexElement, the index of the array or vector element being
210214
/// initialized.
211215
unsigned Index;
212216

@@ -536,15 +540,15 @@ class alignas(8) InitializedEntity {
536540
/// element's index.
537541
unsigned getElementIndex() const {
538542
assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
539-
getKind() == EK_ComplexElement);
543+
getKind() == EK_MatrixElement || getKind() == EK_ComplexElement);
540544
return Index;
541545
}
542546

543547
/// If this is already the initializer for an array or vector
544548
/// element, sets the element index.
545549
void setElementIndex(unsigned Index) {
546550
assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
547-
getKind() == EK_ComplexElement);
551+
getKind() == EK_MatrixElement || getKind() == EK_ComplexElement);
548552
this->Index = Index;
549553
}
550554

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ getEntityLifetime(const InitializedEntity *Entity,
154154
case InitializedEntity::EK_LambdaToBlockConversionBlockElement:
155155
case InitializedEntity::EK_LambdaCapture:
156156
case InitializedEntity::EK_VectorElement:
157+
case clang::InitializedEntity::EK_MatrixElement:
157158
case InitializedEntity::EK_ComplexElement:
158159
return {nullptr, LK_FullExpression};
159160

0 commit comments

Comments
 (0)