Abpostelnicu updated this revision to Diff 72790. Abpostelnicu marked 2 inline comments as done. Abpostelnicu added a comment.
i will add the unit tests in the next patch. https://reviews.llvm.org/D22910 Files: include/clang/AST/ExprCXX.h lib/AST/Expr.cpp Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -2863,8 +2863,23 @@ // These never have a side-effect. return false; + case CXXOperatorCallExprClass: { + // When looking for potential side-effects, we assume that these + // operators: assignment, increement and decrement are intended + // to have a side-effect and other overloaded operators are not. + // Otherwise fall through the logic of call expression. + OverloadedOperatorKind Op = cast<CXXOperatorCallExpr>(this)->getOperator(); + if (CXXOperatorCallExpr::isAssignmentOp(Op) + || CXXOperatorCallExpr::isIncrementOp(Op) + || CXXOperatorCallExpr::isDecrementOp(Op)) { + const Decl *FD = cast<CallExpr>(this)->getCalleeDecl(); + bool IsPure = FD && (FD->hasAttr<ConstAttr>() || FD->hasAttr<PureAttr>()); + if (!IsPure) + return true; + } + LLVM_FALLTHROUGH; + } case CallExprClass: - case CXXOperatorCallExprClass: case CXXMemberCallExprClass: case CUDAKernelCallExprClass: case UserDefinedLiteralClass: { Index: include/clang/AST/ExprCXX.h =================================================================== --- include/clang/AST/ExprCXX.h +++ include/clang/AST/ExprCXX.h @@ -106,6 +106,26 @@ // operations on floating point types. bool isFPContractable() const { return FPContractable; } + // Check to see if a given overloaded operator is of assignment kind + static bool isAssignmentOp(OverloadedOperatorKind Opc) { + return Opc == OO_Equal || Opc == OO_StarEqual || + Opc == OO_SlashEqual || Opc == OO_PercentEqual || + Opc == OO_PlusEqual || Opc == OO_MinusEqual || + Opc == OO_LessLessEqual || Opc == OO_GreaterGreaterEqual || + Opc == OO_AmpEqual || Opc == OO_CaretEqual || + Opc == OO_PipeEqual; + } + + // Check to see if a given overloaded operator is of increment kind + static bool isIncrementOp(OverloadedOperatorKind Opc) { + return Opc == OO_PlusPlus; + } + + // Check to see if a given overloaded operator is of decrement kind + static bool isDecrementOp(OverloadedOperatorKind Opc) { + return Opc == OO_MinusMinus; + } + friend class ASTStmtReader; friend class ASTStmtWriter; };
Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -2863,8 +2863,23 @@ // These never have a side-effect. return false; + case CXXOperatorCallExprClass: { + // When looking for potential side-effects, we assume that these + // operators: assignment, increement and decrement are intended + // to have a side-effect and other overloaded operators are not. + // Otherwise fall through the logic of call expression. + OverloadedOperatorKind Op = cast<CXXOperatorCallExpr>(this)->getOperator(); + if (CXXOperatorCallExpr::isAssignmentOp(Op) + || CXXOperatorCallExpr::isIncrementOp(Op) + || CXXOperatorCallExpr::isDecrementOp(Op)) { + const Decl *FD = cast<CallExpr>(this)->getCalleeDecl(); + bool IsPure = FD && (FD->hasAttr<ConstAttr>() || FD->hasAttr<PureAttr>()); + if (!IsPure) + return true; + } + LLVM_FALLTHROUGH; + } case CallExprClass: - case CXXOperatorCallExprClass: case CXXMemberCallExprClass: case CUDAKernelCallExprClass: case UserDefinedLiteralClass: { Index: include/clang/AST/ExprCXX.h =================================================================== --- include/clang/AST/ExprCXX.h +++ include/clang/AST/ExprCXX.h @@ -106,6 +106,26 @@ // operations on floating point types. bool isFPContractable() const { return FPContractable; } + // Check to see if a given overloaded operator is of assignment kind + static bool isAssignmentOp(OverloadedOperatorKind Opc) { + return Opc == OO_Equal || Opc == OO_StarEqual || + Opc == OO_SlashEqual || Opc == OO_PercentEqual || + Opc == OO_PlusEqual || Opc == OO_MinusEqual || + Opc == OO_LessLessEqual || Opc == OO_GreaterGreaterEqual || + Opc == OO_AmpEqual || Opc == OO_CaretEqual || + Opc == OO_PipeEqual; + } + + // Check to see if a given overloaded operator is of increment kind + static bool isIncrementOp(OverloadedOperatorKind Opc) { + return Opc == OO_PlusPlus; + } + + // Check to see if a given overloaded operator is of decrement kind + static bool isDecrementOp(OverloadedOperatorKind Opc) { + return Opc == OO_MinusMinus; + } + friend class ASTStmtReader; friend class ASTStmtWriter; };
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits