[PATCH] D50766: Fix false positive unsequenced access and modification warning in array subscript expression.

Mateusz Janek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 15 12:18:41 PDT 2018


stryku updated this revision to Diff 160885.
stryku added a comment.

Thanks for pointing that out. You're probably right, these two calls are self-explanatory.


https://reviews.llvm.org/D50766

Files:
  lib/Sema/SemaChecking.cpp


Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11658,30 +11658,38 @@
       notePostUse(O, E);
   }
 
-  void VisitBinComma(BinaryOperator *BO) {
-    // C++11 [expr.comma]p1:
-    //   Every value computation and side effect associated with the left
-    //   expression is sequenced before every value computation and side
-    //   effect associated with the right expression.
-    SequenceTree::Seq LHS = Tree.allocate(Region);
-    SequenceTree::Seq RHS = Tree.allocate(Region);
+  void VisitSequencedLhsRhsExpressions(Expr *LHS, Expr *RHS) {
+    SequenceTree::Seq LHSRegion = Tree.allocate(Region);
+    SequenceTree::Seq RHSRegion = Tree.allocate(Region);
     SequenceTree::Seq OldRegion = Region;
 
     {
       SequencedSubexpression SeqLHS(*this);
-      Region = LHS;
-      Visit(BO->getLHS());
+      Region = LHSRegion;
+      Visit(LHS);
     }
 
-    Region = RHS;
-    Visit(BO->getRHS());
+    Region = RHSRegion;
+    Visit(RHS);
 
     Region = OldRegion;
 
-    // Forget that LHS and RHS are sequenced. They are both unsequenced
-    // with respect to other stuff.
-    Tree.merge(LHS);
-    Tree.merge(RHS);
+    Tree.merge(LHSRegion);
+    Tree.merge(RHSRegion);
+  }
+
+  void VisitArraySubscriptExpr(ArraySubscriptExpr *ASE) {
+    // The expression E1[E2] is identical (by definition) to *((E1)+(E2)). The
+    // expression E1 is sequenced before the expression E2.
+    VisitSequencedLhsRhsExpressions(ASE->getLHS(), ASE->getLHS());
+  }
+
+  void VisitBinComma(BinaryOperator *BO) {
+    // C++11 [expr.comma]p1:
+    //   Every value computation and side effect associated with the left
+    //   expression is sequenced before every value computation and side
+    //   effect associated with the right expression.
+    VisitSequencedLhsRhsExpressions(BO->getLHS(), BO->getLHS());
   }
 
   void VisitBinAssign(BinaryOperator *BO) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50766.160885.patch
Type: text/x-patch
Size: 1987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180815/101122e4/attachment.bin>


More information about the cfe-commits mailing list