From 7ef9139a391a6d526afab0216a97f9d65a6b5563 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Wed, 6 Jan 2021 14:59:27 +0000 Subject: [PATCH] [Clang] Remove unnecessary Attr.isArgIdent checks. The MatrixType, ExtVectorType, VectorSize and AddressSpace attributes have arguments defined as ExprArguments in Attr.td. So their arguments should never be ArgIdents and the logic to handle this case can be removed. The logic has been replaced by an assertion to ensure the arguments are always ArgExpressions Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D94092 --- clang/lib/Sema/SemaType.cpp | 109 +++----------------------------------------- 1 file changed, 6 insertions(+), 103 deletions(-) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 00ec0c4a0ce..3f564541d41 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -6434,25 +6434,7 @@ static void HandleAddressSpaceTypeAttribute(QualType &Type, return; } - Expr *ASArgExpr; - if (Attr.isArgIdent(0)) { - // Special case where the argument is a template id. - CXXScopeSpec SS; - SourceLocation TemplateKWLoc; - UnqualifiedId id; - id.setIdentifier(Attr.getArgAsIdent(0)->Ident, Attr.getLoc()); - - ExprResult AddrSpace = S.ActOnIdExpression( - S.getCurScope(), SS, TemplateKWLoc, id, /*HasTrailingLParen=*/false, - /*IsAddressOfOperand=*/false); - if (AddrSpace.isInvalid()) - return; - - ASArgExpr = static_cast(AddrSpace.get()); - } else { - ASArgExpr = static_cast(Attr.getArgAsExpr(0)); - } - + Expr *ASArgExpr = static_cast(Attr.getArgAsExpr(0)); LangAS ASIdx; if (!BuildAddressSpaceIndex(S, ASIdx, ASArgExpr, Attr.getLoc())) { Attr.setInvalid(); @@ -7658,25 +7640,7 @@ static void HandleVectorSizeAttr(QualType &CurType, const ParsedAttr &Attr, return; } - Expr *SizeExpr; - // Special case where the argument is a template id. - if (Attr.isArgIdent(0)) { - CXXScopeSpec SS; - SourceLocation TemplateKWLoc; - UnqualifiedId Id; - Id.setIdentifier(Attr.getArgAsIdent(0)->Ident, Attr.getLoc()); - - ExprResult Size = S.ActOnIdExpression(S.getCurScope(), SS, TemplateKWLoc, - Id, /*HasTrailingLParen=*/false, - /*IsAddressOfOperand=*/false); - - if (Size.isInvalid()) - return; - SizeExpr = Size.get(); - } else { - SizeExpr = Attr.getArgAsExpr(0); - } - + Expr *SizeExpr = Attr.getArgAsExpr(0); QualType T = S.BuildVectorType(CurType, SizeExpr, Attr.getLoc()); if (!T.isNull()) CurType = T; @@ -7695,28 +7659,8 @@ static void HandleExtVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr, return; } - Expr *sizeExpr; - - // Special case where the argument is a template id. - if (Attr.isArgIdent(0)) { - CXXScopeSpec SS; - SourceLocation TemplateKWLoc; - UnqualifiedId id; - id.setIdentifier(Attr.getArgAsIdent(0)->Ident, Attr.getLoc()); - - ExprResult Size = S.ActOnIdExpression(S.getCurScope(), SS, TemplateKWLoc, - id, /*HasTrailingLParen=*/false, - /*IsAddressOfOperand=*/false); - if (Size.isInvalid()) - return; - - sizeExpr = Size.get(); - } else { - sizeExpr = Attr.getArgAsExpr(0); - } - - // Create the vector type. - QualType T = S.BuildExtVectorType(CurType, sizeExpr, Attr.getLoc()); + Expr *SizeExpr = Attr.getArgAsExpr(0); + QualType T = S.BuildExtVectorType(CurType, SizeExpr, Attr.getLoc()); if (!T.isNull()) CurType = T; } @@ -7988,49 +7932,8 @@ static void HandleMatrixTypeAttr(QualType &CurType, const ParsedAttr &Attr, return; } - Expr *RowsExpr = nullptr; - Expr *ColsExpr = nullptr; - - // TODO: Refactor parameter extraction into separate function - // Get the number of rows - if (Attr.isArgIdent(0)) { - CXXScopeSpec SS; - SourceLocation TemplateKeywordLoc; - UnqualifiedId id; - id.setIdentifier(Attr.getArgAsIdent(0)->Ident, Attr.getLoc()); - ExprResult Rows = S.ActOnIdExpression(S.getCurScope(), SS, - TemplateKeywordLoc, id, false, false); - - if (Rows.isInvalid()) - // TODO: maybe a good error message would be nice here - return; - RowsExpr = Rows.get(); - } else { - assert(Attr.isArgExpr(0) && - "Argument to should either be an identity or expression"); - RowsExpr = Attr.getArgAsExpr(0); - } - - // Get the number of columns - if (Attr.isArgIdent(1)) { - CXXScopeSpec SS; - SourceLocation TemplateKeywordLoc; - UnqualifiedId id; - id.setIdentifier(Attr.getArgAsIdent(1)->Ident, Attr.getLoc()); - ExprResult Columns = S.ActOnIdExpression( - S.getCurScope(), SS, TemplateKeywordLoc, id, false, false); - - if (Columns.isInvalid()) - // TODO: a good error message would be nice here - return; - RowsExpr = Columns.get(); - } else { - assert(Attr.isArgExpr(1) && - "Argument to should either be an identity or expression"); - ColsExpr = Attr.getArgAsExpr(1); - } - - // Create the matrix type. + Expr *RowsExpr = Attr.getArgAsExpr(0); + Expr *ColsExpr = Attr.getArgAsExpr(1); QualType T = S.BuildMatrixType(CurType, RowsExpr, ColsExpr, Attr.getLoc()); if (!T.isNull()) CurType = T; -- 2.11.0