Skip to content
Draft
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
2 changes: 2 additions & 0 deletions clang/include/clang/AST/ComputeDependence.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ArrayInitLoopExpr;
class ImplicitValueInitExpr;
class InitListExpr;
class ExtVectorElementExpr;
class MatrixElementExpr;
class BlockExpr;
class AsTypeExpr;
class DeclRefExpr;
Expand Down Expand Up @@ -133,6 +134,7 @@ ExprDependence computeDependence(ArrayInitLoopExpr *E);
ExprDependence computeDependence(ImplicitValueInitExpr *E);
ExprDependence computeDependence(InitListExpr *E);
ExprDependence computeDependence(ExtVectorElementExpr *E);
ExprDependence computeDependence(MatrixElementExpr *E);
ExprDependence computeDependence(BlockExpr *E,
bool ContainsUnexpandedParameterPack);
ExprDependence computeDependence(AsTypeExpr *E);
Expand Down
107 changes: 68 additions & 39 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class Expr : public ValueStmt {
LV_NotObjectType,
LV_IncompleteVoidType,
LV_DuplicateVectorComponents,
LV_DuplicateMatrixComponents,
LV_InvalidExpression,
LV_InvalidMessageExpression,
LV_MemberFunction,
Expand All @@ -306,8 +307,9 @@ class Expr : public ValueStmt {
MLV_NotObjectType,
MLV_IncompleteVoidType,
MLV_DuplicateVectorComponents,
MLV_DuplicateMatrixComponents,
MLV_InvalidExpression,
MLV_LValueCast, // Specialized form of MLV_InvalidExpression.
MLV_LValueCast, // Specialized form of MLV_InvalidExpression.
MLV_IncompleteType,
MLV_ConstQualified,
MLV_ConstQualifiedField,
Expand Down Expand Up @@ -340,16 +342,17 @@ class Expr : public ValueStmt {
enum Kinds {
CL_LValue,
CL_XValue,
CL_Function, // Functions cannot be lvalues in C.
CL_Void, // Void cannot be an lvalue in C.
CL_Function, // Functions cannot be lvalues in C.
CL_Void, // Void cannot be an lvalue in C.
CL_AddressableVoid, // Void expression whose address can be taken in C.
CL_DuplicateVectorComponents, // A vector shuffle with dupes.
CL_DuplicateMatrixComponents, // A matrix shuffle with dupes.
CL_MemberFunction, // An expression referring to a member function
CL_SubObjCPropertySetting,
CL_ClassTemporary, // A temporary of class type, or subobject thereof.
CL_ArrayTemporary, // A temporary of array type.
CL_ClassTemporary, // A temporary of class type, or subobject thereof.
CL_ArrayTemporary, // A temporary of array type.
CL_ObjCMessageRValue, // ObjC message is an rvalue
CL_PRValue // A prvalue for any other reason, of any other type
CL_PRValue // A prvalue for any other reason, of any other type
};
/// The results of modification testing.
enum ModifiableType {
Expand Down Expand Up @@ -6488,30 +6491,24 @@ class GenericSelectionExpr final
// Clang Extensions
//===----------------------------------------------------------------------===//

/// ExtVectorElementExpr - This represents access to specific elements of a
/// vector, and may occur on the left hand side or right hand side. For example
/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector.
///
/// Note that the base may have either vector or pointer to vector type, just
/// like a struct field reference.
///
class ExtVectorElementExpr : public Expr {
template <class Derived> class ElementAccessExprBase : public Expr {
protected:
Stmt *Base;
IdentifierInfo *Accessor;
SourceLocation AccessorLoc;
public:
ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base,
IdentifierInfo &accessor, SourceLocation loc)
: Expr(ExtVectorElementExprClass, ty, VK,
(VK == VK_PRValue ? OK_Ordinary : OK_VectorComponent)),
Base(base), Accessor(&accessor), AccessorLoc(loc) {
setDependence(computeDependence(this));

ElementAccessExprBase(StmtClass SC, QualType Ty, ExprValueKind VK, Expr *Base,
IdentifierInfo &Accessor, SourceLocation Loc,
ExprObjectKind OK)
: Expr(SC, Ty, VK, OK), Base(Base), Accessor(&Accessor),
AccessorLoc(Loc) {
setDependence(computeDependence(static_cast<Derived *>(this)));
}

/// Build an empty vector element expression.
explicit ExtVectorElementExpr(EmptyShell Empty)
: Expr(ExtVectorElementExprClass, Empty) { }
explicit ElementAccessExprBase(StmtClass SC, EmptyShell Empty)
: Expr(SC, Empty) {}

public:
const Expr *getBase() const { return cast<Expr>(Base); }
Expr *getBase() { return cast<Expr>(Base); }
void setBase(Expr *E) { Base = E; }
Expand All @@ -6522,34 +6519,66 @@ class ExtVectorElementExpr : public Expr {
SourceLocation getAccessorLoc() const { return AccessorLoc; }
void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }

/// getNumElements - Get the number of components being selected.
unsigned getNumElements() const;

/// containsDuplicateElements - Return true if any element access is
/// repeated.
bool containsDuplicateElements() const;

/// getEncodedElementAccess - Encode the elements accessed into an llvm
/// aggregate Constant of ConstantInt(s).
void getEncodedElementAccess(SmallVectorImpl<uint32_t> &Elts) const;

SourceLocation getBeginLoc() const LLVM_READONLY {
return getBase()->getBeginLoc();
}
SourceLocation getEndLoc() const LLVM_READONLY { return AccessorLoc; }

child_range children() { return child_range(&Base, &Base + 1); }
const_child_range children() const {
return const_child_range(&Base, &Base + 1);
}
};

/// ExtVectorElementExpr - This represents access to specific elements of a
/// vector, and may occur on the left hand side or right hand side. For example
/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector.
///
/// Note that the base may have either vector or pointer to vector type, just
/// like a struct field reference.
///
class ExtVectorElementExpr
: public ElementAccessExprBase<ExtVectorElementExpr> {
public:
ExtVectorElementExpr(QualType Ty, ExprValueKind VK, Expr *Base,
IdentifierInfo &Accessor, SourceLocation Loc)
: ElementAccessExprBase(
ExtVectorElementExprClass, Ty, VK, Base, Accessor, Loc,
(VK == VK_PRValue ? OK_Ordinary : OK_VectorComponent)) {}

explicit ExtVectorElementExpr(EmptyShell Empty)
: ElementAccessExprBase(ExtVectorElementExprClass, Empty) {}

unsigned getNumElements() const;
bool containsDuplicateElements() const;
void getEncodedElementAccess(SmallVectorImpl<uint32_t> &Elts) const;

/// isArrow - Return true if the base expression is a pointer to vector,
/// return false if the base expression is a vector.
bool isArrow() const;

static bool classof(const Stmt *T) {
return T->getStmtClass() == ExtVectorElementExprClass;
}
};

// Iterators
child_range children() { return child_range(&Base, &Base+1); }
const_child_range children() const {
return const_child_range(&Base, &Base + 1);
class MatrixElementExpr : public ElementAccessExprBase<MatrixElementExpr> {
public:
MatrixElementExpr(QualType Ty, ExprValueKind VK, Expr *Base,
IdentifierInfo &Accessor, SourceLocation Loc)
: ElementAccessExprBase(
MatrixElementExprClass, Ty, VK, Base, Accessor, Loc,
OK_Ordinary /*TODO: Should we add a new OK_MatrixComponent?*/) {}

explicit MatrixElementExpr(EmptyShell Empty)
: ElementAccessExprBase(MatrixElementExprClass, Empty) {}

unsigned getNumElements() const;
bool containsDuplicateElements() const;
void getEncodedElementAccess(SmallVectorImpl<uint32_t> &Elts) const;

static bool classof(const Stmt *T) {
return T->getStmtClass() == MatrixElementExprClass;
}
};

Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2940,6 +2940,7 @@ DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {})
DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
DEF_TRAVERSE_STMT(MatrixElementExpr, {})
DEF_TRAVERSE_STMT(GNUNullExpr, {})
DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
DEF_TRAVERSE_STMT(NoInitExpr, {})
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/AST/TextNodeDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class TextNodeDumper
void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
void VisitMemberExpr(const MemberExpr *Node);
void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
void VisitMatrixElementExpr(const MatrixElementExpr *Node);
void VisitBinaryOperator(const BinaryOperator *Node);
void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
void VisitAddrLabelExpr(const AddrLabelExpr *Node);
Expand Down
12 changes: 12 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -9336,6 +9336,8 @@ def err_typecheck_lvalue_casts_not_supported : Error<

def err_typecheck_duplicate_vector_components_not_mlvalue : Error<
"vector is not assignable (contains duplicate components)">;
def err_typecheck_duplicate_matrix_components_not_mlvalue : Error<
"matrix is not assignable (contains duplicate components)">;
def err_block_decl_ref_not_modifiable_lvalue : Error<
"variable is not assignable (missing __block type specifier)">;
def err_lambda_decl_ref_not_modifiable_lvalue : Error<
Expand Down Expand Up @@ -13061,6 +13063,7 @@ def err_builtin_matrix_stride_too_small: Error<
"stride must be greater or equal to the number of rows">;
def err_builtin_matrix_invalid_dimension: Error<
"%0 dimension is outside the allowed range [1, %1]">;
def err_builtin_matrix_invalid_member: Error<"invalid matrix member '%0' expected %1">;

def warn_mismatched_import : Warning<
"import %select{module|name}0 (%1) does not match the import %select{module|name}0 (%2) of the "
Expand Down Expand Up @@ -13318,6 +13321,15 @@ def err_hlsl_builtin_scalar_vector_mismatch
"%select{all|second and third}0 arguments to %1 must be of scalar or "
"vector type with matching scalar element type%diff{: $ vs $|}2,3">;

def err_hlsl_matrix_element_not_in_bounds : Error<
"matrix %select{row|column}0 element accessor is out of bounds of %select{zero|one}1 based indexing">;

def err_hlsl_matrix_index_out_of_bounds : Error<
"matrix %select{row|column}0 index %1 is out of bounds of %select{rows|columns}0 size %2">;

def err_hlsl_matrix_swizzle_invalid_length : Error<
"matrix swizzle length must be between 1 and 4 but is %0">;

def warn_hlsl_impcast_vector_truncation : Warning<
"implicit conversion truncates vector: %0 to %1">, InGroup<VectorConversion>;

Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/StmtNodes.td
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def CStyleCastExpr : StmtNode<ExplicitCastExpr>;
def OMPArrayShapingExpr : StmtNode<Expr>;
def CompoundLiteralExpr : StmtNode<Expr>;
def ExtVectorElementExpr : StmtNode<Expr>;
def MatrixElementExpr : StmtNode<Expr>;
def InitListExpr : StmtNode<Expr>;
def DesignatedInitExpr : StmtNode<Expr>;
def DesignatedInitUpdateExpr : StmtNode<Expr>;
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Sema/SemaHLSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ class SemaHLSL : public SemaBase {
bool transformInitList(const InitializedEntity &Entity, InitListExpr *Init);
bool handleInitialization(VarDecl *VDecl, Expr *&Init);
void deduceAddressSpace(VarDecl *Decl);
QualType CheckMatrixComponent(Sema &S, QualType baseType, ExprValueKind &VK,
SourceLocation OpLoc,
const IdentifierInfo *CompName,
SourceLocation CompLoc);

private:
// HLSL resource type attributes need to be processed all at once.
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Serialization/ASTBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,9 @@ enum StmtCode {
/// An ExtVectorElementExpr record.
EXPR_EXT_VECTOR_ELEMENT,

/// A MatrixElementExpr record.
EXPR_MATRIX_ELEMENT,

/// An InitListExpr record.
EXPR_INIT_LIST,

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/ComputeDependence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ ExprDependence clang::computeDependence(ExtVectorElementExpr *E) {
return E->getBase()->getDependence();
}

ExprDependence clang::computeDependence(MatrixElementExpr *E) {
return E->getBase()->getDependence();
}

ExprDependence clang::computeDependence(BlockExpr *E,
bool ContainsUnexpandedParameterPack) {
auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
Expand Down
Loading