[clang] [Clang][Sema] Refactor handling of vector subscript expressions (NFC) (PR #92778)
https://github.com/momchil-velikov closed https://github.com/llvm/llvm-project/pull/92778 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Refactor handling of vector subscript expressions (NFC) (PR #92778)
https://github.com/efriedma-quic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/92778 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Refactor handling of vector subscript expressions (NFC) (PR #92778)
https://github.com/momchil-velikov edited https://github.com/llvm/llvm-project/pull/92778 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Refactor handling of vector subscript expressions (NFC) (PR #92778)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Momchil Velikov (momchil-velikov) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/92778.diff 2 Files Affected: - (modified) clang/include/clang/AST/Type.h (+5) - (modified) clang/lib/Sema/SemaExpr.cpp (+14-30) ``diff diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index da3834f19ca04..9a5c6e8d562c3 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -2523,6 +2523,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { bool isVectorType() const;// GCC vector type. bool isExtVectorType() const; // Extended vector type. bool isExtVectorBoolType() const; // Extended vector type with bool element. + bool isSubscriptableVectorType() const; bool isMatrixType() const;// Matrix type. bool isConstantMatrixType() const;// Constant matrix type. bool isDependentAddressSpaceType() const; // value-dependent address space qualifier @@ -7729,6 +7730,10 @@ inline bool Type::isExtVectorBoolType() const { return cast(CanonicalType)->getElementType()->isBooleanType(); } +inline bool Type::isSubscriptableVectorType() const { + return isVectorType() || isSveVLSBuiltinType(); +} + inline bool Type::isMatrixType() const { return isa(CanonicalType); } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 5ecfdee21f09d..c86f1d9c8076e 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5283,36 +5283,22 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, << ResultType << BaseExpr->getSourceRange(); return ExprError(); } - } else if (const VectorType *VTy = LHSTy->getAs()) { -BaseExpr = LHSExp;// vectors: V[123] -IndexExpr = RHSExp; -// We apply C++ DR1213 to vector subscripting too. -if (getLangOpts().CPlusPlus11 && LHSExp->isPRValue()) { - ExprResult Materialized = TemporaryMaterializationConversion(LHSExp); - if (Materialized.isInvalid()) -return ExprError(); - LHSExp = Materialized.get(); + } else if (LHSTy->isSubscriptableVectorType()) { +if (LHSTy->isBuiltinType() && +LHSTy->getAs()->isSveVLSBuiltinType()) { + const BuiltinType *BTy = LHSTy->getAs(); + if (BTy->isSVEBool()) +return ExprError(Diag(LLoc, diag::err_subscript_svbool_t) + << LHSExp->getSourceRange() + << RHSExp->getSourceRange()); + ResultType = BTy->getSveEltType(Context); +} else { + const VectorType *VTy = LHSTy->getAs(); + ResultType = VTy->getElementType(); } -VK = LHSExp->getValueKind(); -if (VK != VK_PRValue) - OK = OK_VectorComponent; - -ResultType = VTy->getElementType(); -QualType BaseType = BaseExpr->getType(); -Qualifiers BaseQuals = BaseType.getQualifiers(); -Qualifiers MemberQuals = ResultType.getQualifiers(); -Qualifiers Combined = BaseQuals + MemberQuals; -if (Combined != MemberQuals) - ResultType = Context.getQualifiedType(ResultType, Combined); - } else if (LHSTy->isBuiltinType() && - LHSTy->getAs()->isSveVLSBuiltinType()) { -const BuiltinType *BTy = LHSTy->getAs(); -if (BTy->isSVEBool()) - return ExprError(Diag(LLoc, diag::err_subscript_svbool_t) - << LHSExp->getSourceRange() << RHSExp->getSourceRange()); - -BaseExpr = LHSExp; +BaseExpr = LHSExp; // vectors: V[123] IndexExpr = RHSExp; +// We apply C++ DR1213 to vector subscripting too. if (getLangOpts().CPlusPlus11 && LHSExp->isPRValue()) { ExprResult Materialized = TemporaryMaterializationConversion(LHSExp); if (Materialized.isInvalid()) @@ -5323,8 +5309,6 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, if (VK != VK_PRValue) OK = OK_VectorComponent; -ResultType = BTy->getSveEltType(Context); - QualType BaseType = BaseExpr->getType(); Qualifiers BaseQuals = BaseType.getQualifiers(); Qualifiers MemberQuals = ResultType.getQualifiers(); `` https://github.com/llvm/llvm-project/pull/92778 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Refactor handling of vector subscript expressions (NFC) (PR #92778)
https://github.com/momchil-velikov created https://github.com/llvm/llvm-project/pull/92778 None >From 435f3104e68ef278196417c293093131258c549d Mon Sep 17 00:00:00 2001 From: Momchil Velikov Date: Mon, 20 May 2024 15:43:31 +0100 Subject: [PATCH] [Clang][Sema] Refactor handling of vector subscript expressions (NFC) Change-Id: I514431a482ffa0a2d906c019b6e374bf4607571e --- clang/include/clang/AST/Type.h | 5 clang/lib/Sema/SemaExpr.cpp| 44 +++--- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index da3834f19ca04..9a5c6e8d562c3 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -2523,6 +2523,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { bool isVectorType() const;// GCC vector type. bool isExtVectorType() const; // Extended vector type. bool isExtVectorBoolType() const; // Extended vector type with bool element. + bool isSubscriptableVectorType() const; bool isMatrixType() const;// Matrix type. bool isConstantMatrixType() const;// Constant matrix type. bool isDependentAddressSpaceType() const; // value-dependent address space qualifier @@ -7729,6 +7730,10 @@ inline bool Type::isExtVectorBoolType() const { return cast(CanonicalType)->getElementType()->isBooleanType(); } +inline bool Type::isSubscriptableVectorType() const { + return isVectorType() || isSveVLSBuiltinType(); +} + inline bool Type::isMatrixType() const { return isa(CanonicalType); } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 5ecfdee21f09d..c86f1d9c8076e 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5283,36 +5283,22 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, << ResultType << BaseExpr->getSourceRange(); return ExprError(); } - } else if (const VectorType *VTy = LHSTy->getAs()) { -BaseExpr = LHSExp;// vectors: V[123] -IndexExpr = RHSExp; -// We apply C++ DR1213 to vector subscripting too. -if (getLangOpts().CPlusPlus11 && LHSExp->isPRValue()) { - ExprResult Materialized = TemporaryMaterializationConversion(LHSExp); - if (Materialized.isInvalid()) -return ExprError(); - LHSExp = Materialized.get(); + } else if (LHSTy->isSubscriptableVectorType()) { +if (LHSTy->isBuiltinType() && +LHSTy->getAs()->isSveVLSBuiltinType()) { + const BuiltinType *BTy = LHSTy->getAs(); + if (BTy->isSVEBool()) +return ExprError(Diag(LLoc, diag::err_subscript_svbool_t) + << LHSExp->getSourceRange() + << RHSExp->getSourceRange()); + ResultType = BTy->getSveEltType(Context); +} else { + const VectorType *VTy = LHSTy->getAs(); + ResultType = VTy->getElementType(); } -VK = LHSExp->getValueKind(); -if (VK != VK_PRValue) - OK = OK_VectorComponent; - -ResultType = VTy->getElementType(); -QualType BaseType = BaseExpr->getType(); -Qualifiers BaseQuals = BaseType.getQualifiers(); -Qualifiers MemberQuals = ResultType.getQualifiers(); -Qualifiers Combined = BaseQuals + MemberQuals; -if (Combined != MemberQuals) - ResultType = Context.getQualifiedType(ResultType, Combined); - } else if (LHSTy->isBuiltinType() && - LHSTy->getAs()->isSveVLSBuiltinType()) { -const BuiltinType *BTy = LHSTy->getAs(); -if (BTy->isSVEBool()) - return ExprError(Diag(LLoc, diag::err_subscript_svbool_t) - << LHSExp->getSourceRange() << RHSExp->getSourceRange()); - -BaseExpr = LHSExp; +BaseExpr = LHSExp; // vectors: V[123] IndexExpr = RHSExp; +// We apply C++ DR1213 to vector subscripting too. if (getLangOpts().CPlusPlus11 && LHSExp->isPRValue()) { ExprResult Materialized = TemporaryMaterializationConversion(LHSExp); if (Materialized.isInvalid()) @@ -5323,8 +5309,6 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, if (VK != VK_PRValue) OK = OK_VectorComponent; -ResultType = BTy->getSveEltType(Context); - QualType BaseType = BaseExpr->getType(); Qualifiers BaseQuals = BaseType.getQualifiers(); Qualifiers MemberQuals = ResultType.getQualifiers(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits