fhahn updated this revision to Diff 314635. fhahn added a comment.
In D94092#2479684 <https://reviews.llvm.org/D94092#2479684>, @erichkeane wrote: > I'm not sure how well Attr.td's constraints are enforced on type attributes, > as these often happen before parsing is completely done. I'd imagine this > code was put into place at least the 1st time for good reason, but I'm > curious as to why we wouldn't have tests that cover that (or, as you assert, > it could simply be that this is simply dead code). > > I'm generally OK with this (the asserts are unnecessary), but would like > @aaron.ballman to double check my expectations here. It would be great if we could get confirmation! I tried a few different things to construct matrix_type attributes with ArgIdents, but failed. The patch also adjusts the code for a bunch of attributes. So if there are indeed cases where ArgIdents can show up, we will get some examples for unit tests. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D94092/new/ https://reviews.llvm.org/D94092 Files: clang/lib/Sema/SemaType.cpp
Index: clang/lib/Sema/SemaType.cpp =================================================================== --- clang/lib/Sema/SemaType.cpp +++ clang/lib/Sema/SemaType.cpp @@ -6434,25 +6434,7 @@ 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<Expr *>(AddrSpace.get()); - } else { - ASArgExpr = static_cast<Expr *>(Attr.getArgAsExpr(0)); - } - + Expr *ASArgExpr = static_cast<Expr *>(Attr.getArgAsExpr(0)); LangAS ASIdx; if (!BuildAddressSpaceIndex(S, ASIdx, ASArgExpr, Attr.getLoc())) { Attr.setInvalid(); @@ -7658,25 +7640,7 @@ 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,26 +7659,7 @@ 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); // Create the vector type. QualType T = S.BuildExtVectorType(CurType, sizeExpr, Attr.getLoc()); if (!T.isNull()) @@ -7988,47 +7933,10 @@ 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); - } - + Expr *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); - } + Expr *ColsExpr = Attr.getArgAsExpr(1); // Create the matrix type. QualType T = S.BuildMatrixType(CurType, RowsExpr, ColsExpr, Attr.getLoc());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits