[PATCH] D100713: [clang] NFC: refactor multiple implementations of getDecltypeForParenthesizedExpr
This revision was automatically updated to reflect the committed changes. mizvekov marked an inline comment as done. Closed by commit rG0c7cd4a87313: [clang] NFC: refactor multiple implementations of… (authored by mizvekov). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D100713/new/ https://reviews.llvm.org/D100713 Files: clang/include/clang/AST/ASTContext.h clang/include/clang/Sema/Sema.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ExprObjC.cpp clang/lib/Sema/SemaConcept.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaType.cpp clang/lib/StaticAnalyzer/Core/CallEvent.cpp Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp === --- clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -73,26 +73,7 @@ const Expr *E = getOriginExpr(); if (!E) return Ctx.VoidTy; - assert(E); - - QualType ResultTy = E->getType(); - - // A function that returns a reference to 'int' will have a result type - // of simply 'int'. Check the origin expr's value kind to recover the - // proper type. - switch (E->getValueKind()) { - case VK_LValue: -ResultTy = Ctx.getLValueReferenceType(ResultTy); -break; - case VK_XValue: -ResultTy = Ctx.getRValueReferenceType(ResultTy); -break; - case VK_PRValue: -// No adjustment is necessary. -break; - } - - return ResultTy; + return Ctx.getReferenceQualifiedType(E); } static bool isCallback(QualType T) { Index: clang/lib/Sema/SemaType.cpp === --- clang/lib/Sema/SemaType.cpp +++ clang/lib/Sema/SemaType.cpp @@ -8891,29 +8891,6 @@ return Context.getTypeOfExprType(E); } -/// getDecltypeForParenthesizedExpr - Given an expr, will return the type for -/// that expression, as in [dcl.type.simple]p4 but without taking id-expressions -/// and class member access into account. -QualType Sema::getDecltypeForParenthesizedExpr(Expr *E) { - // C++11 [dcl.type.simple]p4: - // [...] - QualType T = E->getType(); - switch (E->getValueKind()) { - // - otherwise, if e is an xvalue, decltype(e) is T&&, where T is the - // type of e; - case VK_XValue: -return Context.getRValueReferenceType(T); - // - otherwise, if e is an lvalue, decltype(e) is T&, where T is the - // type of e; - case VK_LValue: -return Context.getLValueReferenceType(T); - // - otherwise, decltype(e) is the type of e. - case VK_PRValue: -return T; - } - llvm_unreachable("Unknown value kind"); -} - /// getDecltypeForExpr - Given an expr, will return the decltype for /// that expression, according to the rules in C++11 /// [dcl.type.simple]p4 and C++11 [expr.lambda.prim]p18. @@ -8983,7 +8960,7 @@ } } - return S.getDecltypeForParenthesizedExpr(E); + return S.Context.getReferenceQualifiedType(E); } QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc, Index: clang/lib/Sema/SemaExprCXX.cpp === --- clang/lib/Sema/SemaExprCXX.cpp +++ clang/lib/Sema/SemaExprCXX.cpp @@ -5891,10 +5891,8 @@ // -- If E2 is an xvalue: E1 can be converted to match E2 if E1 can be // implicitly converted to the type "rvalue reference to R2", subject to // the constraint that the reference must bind directly. - if (To->isLValue() || To->isXValue()) { -QualType T = To->isLValue() ? Self.Context.getLValueReferenceType(ToType) -: Self.Context.getRValueReferenceType(ToType); - + if (To->isGLValue()) { +QualType T = Self.Context.getReferenceQualifiedType(To); InitializedEntity Entity = InitializedEntity::InitializeTemporary(T); InitializationSequence InitSeq(Self, Entity, Kind, From); @@ -8743,7 +8741,7 @@ TemplateParameterList *TPL = ReturnTypeRequirement.getTypeConstraintTemplateParameterList(); QualType MatchedType = -getDecltypeForParenthesizedExpr(E).getCanonicalType(); +Context.getReferenceQualifiedType(E).getCanonicalType(); llvm::SmallVector Args; Args.push_back(TemplateArgument(MatchedType)); TemplateArgumentList TAL(TemplateArgumentList::OnStack, Args); Index: clang/lib/Sema/SemaExpr.cpp === --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -19402,14 +19402,7 @@ if (ParamTypes.empty() && Proto->isVariadic()) { // the special case ArgTypes.reserve(E->getNumArgs()); for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { -Expr *Arg = E->getArg(i); -QualType ArgType = Arg->getType(); -if (E->isLValue()) { - ArgType = S.Context.getLValueReferenceType(ArgType); -} else if (E->isXValue()) { - ArgType = S.Context.getRValueReferenceType(ArgType); -} -
[PATCH] D100713: [clang] NFC: refactor multiple implementations of getDecltypeForParenthesizedExpr
aaronpuchert accepted this revision. aaronpuchert added a comment. This revision is now accepted and ready to land. It is a good name! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D100713/new/ https://reviews.llvm.org/D100713 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D100713: [clang] NFC: refactor multiple implementations of getDecltypeForParenthesizedExpr
mizvekov marked 2 inline comments as done. mizvekov added inline comments. Comment at: clang/lib/Sema/SemaExprCXX.cpp:5845 + if (!To->isRValue()) { +QualType T = Self.Context.getDecltypeForParenthesizedExpr(To); InitializedEntity Entity = InitializedEntity::InitializeTemporary(T); rsmith wrote: > mizvekov wrote: > > aaronpuchert wrote: > > > mizvekov wrote: > > > > aaronpuchert wrote: > > > > > The quote doesn't reference parenthesized expressions, isn't this > > > > > just coincidentally the same thing? > > > > It's fundamentally the same thing. The > > > > `getDecltypeForParenthesizedExpr` name is what I tried to keep, I don't > > > > have better ideas there. > > > What this is doing is pointwise equal to > > > `getDecltypeForParenthesizedExpr`, but there is no parenthesized > > > expression, and no `decltype`. There is a quote from the standard that > > > defines this separately (by now this seems to be > > > [[http://eel.is/c++draft/expr.cond#4|expr.cond#4]]), and there are some > > > differences especially in the prvalue case. So I'm not sure this helps. > > Here for XValue and and LValue, the rules are exactly the same as > > https://eel.is/c++draft/dcl.type.decltype#1. > > And the original code here even already special cases it... > > > > I am sure there is some way we can agree that we should not repeat the code > > just because the standard did not bother to give a name to this part of the > > rules... And again I think it is no coincidence that it makes sense to > > perform the same changes in all these cases. > Maybe we can find a more general name for this functionality that doesn't > mention `decltype`. Perhaps something like `getReferenceQualifiedType`? Yes that is a good name, thanks! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D100713/new/ https://reviews.llvm.org/D100713 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D100713: [clang] NFC: refactor multiple implementations of getDecltypeForParenthesizedExpr
mizvekov updated this revision to Diff 362257. mizvekov added a comment. - rename to getReferenceQualifiedType. - Move the null expression special case out of the function, back to the original user. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D100713/new/ https://reviews.llvm.org/D100713 Files: clang/include/clang/AST/ASTContext.h clang/include/clang/Sema/Sema.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ExprObjC.cpp clang/lib/Sema/SemaConcept.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaType.cpp clang/lib/StaticAnalyzer/Core/CallEvent.cpp Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp === --- clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -73,26 +73,7 @@ const Expr *E = getOriginExpr(); if (!E) return Ctx.VoidTy; - assert(E); - - QualType ResultTy = E->getType(); - - // A function that returns a reference to 'int' will have a result type - // of simply 'int'. Check the origin expr's value kind to recover the - // proper type. - switch (E->getValueKind()) { - case VK_LValue: -ResultTy = Ctx.getLValueReferenceType(ResultTy); -break; - case VK_XValue: -ResultTy = Ctx.getRValueReferenceType(ResultTy); -break; - case VK_PRValue: -// No adjustment is necessary. -break; - } - - return ResultTy; + return Ctx.getReferenceQualifiedType(E); } static bool isCallback(QualType T) { Index: clang/lib/Sema/SemaType.cpp === --- clang/lib/Sema/SemaType.cpp +++ clang/lib/Sema/SemaType.cpp @@ -8891,29 +8891,6 @@ return Context.getTypeOfExprType(E); } -/// getDecltypeForParenthesizedExpr - Given an expr, will return the type for -/// that expression, as in [dcl.type.simple]p4 but without taking id-expressions -/// and class member access into account. -QualType Sema::getDecltypeForParenthesizedExpr(Expr *E) { - // C++11 [dcl.type.simple]p4: - // [...] - QualType T = E->getType(); - switch (E->getValueKind()) { - // - otherwise, if e is an xvalue, decltype(e) is T&&, where T is the - // type of e; - case VK_XValue: -return Context.getRValueReferenceType(T); - // - otherwise, if e is an lvalue, decltype(e) is T&, where T is the - // type of e; - case VK_LValue: -return Context.getLValueReferenceType(T); - // - otherwise, decltype(e) is the type of e. - case VK_PRValue: -return T; - } - llvm_unreachable("Unknown value kind"); -} - /// getDecltypeForExpr - Given an expr, will return the decltype for /// that expression, according to the rules in C++11 /// [dcl.type.simple]p4 and C++11 [expr.lambda.prim]p18. @@ -8983,7 +8960,7 @@ } } - return S.getDecltypeForParenthesizedExpr(E); + return S.Context.getReferenceQualifiedType(E); } QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc, Index: clang/lib/Sema/SemaExprCXX.cpp === --- clang/lib/Sema/SemaExprCXX.cpp +++ clang/lib/Sema/SemaExprCXX.cpp @@ -5891,10 +5891,8 @@ // -- If E2 is an xvalue: E1 can be converted to match E2 if E1 can be // implicitly converted to the type "rvalue reference to R2", subject to // the constraint that the reference must bind directly. - if (To->isLValue() || To->isXValue()) { -QualType T = To->isLValue() ? Self.Context.getLValueReferenceType(ToType) -: Self.Context.getRValueReferenceType(ToType); - + if (To->isGLValue()) { +QualType T = Self.Context.getReferenceQualifiedType(To); InitializedEntity Entity = InitializedEntity::InitializeTemporary(T); InitializationSequence InitSeq(Self, Entity, Kind, From); @@ -8743,7 +8741,7 @@ TemplateParameterList *TPL = ReturnTypeRequirement.getTypeConstraintTemplateParameterList(); QualType MatchedType = -getDecltypeForParenthesizedExpr(E).getCanonicalType(); +Context.getReferenceQualifiedType(E).getCanonicalType(); llvm::SmallVector Args; Args.push_back(TemplateArgument(MatchedType)); TemplateArgumentList TAL(TemplateArgumentList::OnStack, Args); Index: clang/lib/Sema/SemaExpr.cpp === --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -19371,14 +19371,7 @@ if (ParamTypes.empty() && Proto->isVariadic()) { // the special case ArgTypes.reserve(E->getNumArgs()); for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { -Expr *Arg = E->getArg(i); -QualType ArgType = Arg->getType(); -if (E->isLValue()) { - ArgType = S.Context.getLValueReferenceType(ArgType); -} else if (E->isXValue()) { - ArgType = S.Context.getRValueReferenceType(ArgType); -} -
[PATCH] D100713: [clang] NFC: refactor multiple implementations of getDecltypeForParenthesizedExpr
rsmith added inline comments. Comment at: clang/lib/AST/ASTContext.cpp:5461 +QualType ASTContext::getDecltypeForParenthesizedExpr(const Expr *e) const { + if (!e) +return VoidTy; This check doesn't seem like it belongs here. Comment at: clang/lib/Sema/SemaExprCXX.cpp:5845 + if (!To->isRValue()) { +QualType T = Self.Context.getDecltypeForParenthesizedExpr(To); InitializedEntity Entity = InitializedEntity::InitializeTemporary(T); mizvekov wrote: > aaronpuchert wrote: > > mizvekov wrote: > > > aaronpuchert wrote: > > > > The quote doesn't reference parenthesized expressions, isn't this just > > > > coincidentally the same thing? > > > It's fundamentally the same thing. The `getDecltypeForParenthesizedExpr` > > > name is what I tried to keep, I don't have better ideas there. > > What this is doing is pointwise equal to `getDecltypeForParenthesizedExpr`, > > but there is no parenthesized expression, and no `decltype`. There is a > > quote from the standard that defines this separately (by now this seems to > > be [[http://eel.is/c++draft/expr.cond#4|expr.cond#4]]), and there are some > > differences especially in the prvalue case. So I'm not sure this helps. > Here for XValue and and LValue, the rules are exactly the same as > https://eel.is/c++draft/dcl.type.decltype#1. > And the original code here even already special cases it... > > I am sure there is some way we can agree that we should not repeat the code > just because the standard did not bother to give a name to this part of the > rules... And again I think it is no coincidence that it makes sense to > perform the same changes in all these cases. Maybe we can find a more general name for this functionality that doesn't mention `decltype`. Perhaps something like `getReferenceQualifiedType`? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D100713/new/ https://reviews.llvm.org/D100713 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits