[PATCH] D22910: Add support for CXXOperatorCallExpr in Expr::HasSideEffects

Andi via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 6 04:55:33 PDT 2016


Abpostelnicu updated this revision to Diff 73766.
Abpostelnicu marked 3 inline comments as done.

https://reviews.llvm.org/D22910

Files:
  lib/AST/Expr.cpp


Index: lib/AST/Expr.cpp
===================================================================
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -2863,8 +2863,22 @@
     // These never have a side-effect.
     return false;
 
+  case CXXOperatorCallExprClass: {
+    // When looking for potential side-effects, we assume that these
+    // operators: assignment, increment 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)
+        || Op == OO_PlusPlus || Op == OO_Minus) {
+      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: {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22910.73766.patch
Type: text/x-patch
Size: 1083 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161006/00676db9/attachment.bin>


More information about the cfe-commits mailing list