]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR target/50970 (Function pointer dereferenced twice in if statement on Arm cpu)
authorZhenqiang Chen <zhenqiang.chen@linaro.org>
Tue, 25 Sep 2012 06:37:29 +0000 (06:37 +0000)
committerBin Cheng <amker@gcc.gnu.org>
Tue, 25 Sep 2012 06:37:29 +0000 (06:37 +0000)
PR c++/50970
* typeck.c (cp_build_binary_op): Check side effects before generating
pfn and delta related expressions.

From-SVN: r191692

gcc/cp/ChangeLog
gcc/cp/typeck.c

index c03f66a7ad6b7e4c2050e239f94af4c9cd27f973..ba1f775c055fe7723196b4930d3cf84ea1ff08f1 100644 (file)
@@ -1,3 +1,9 @@
+2012-09-25  Zhenqiang Chen <zhenqiang.chen@linaro.org>
+
+       PR c++/50970
+       * typeck.c (cp_build_binary_op): Check side effects before generating
+       pfn and delta related expressions.
+
 2012-09-24  Lawrence Crowl  <crowl@google.com>
 
        * init.c (build_new_1): Change to new double_int API.
index ad4b0903d6725f3e5480afb94f1ce6081159d6c9..884f7d0573b69d60430c857eae7a289ff299cf1f 100644 (file)
@@ -4159,18 +4159,23 @@ cp_build_binary_op (location_t location,
          if (TARGET_PTRMEMFUNC_VBIT_LOCATION
              == ptrmemfunc_vbit_in_delta)
            {
-             tree pfn0 = pfn_from_ptrmemfunc (op0);
-             tree delta0 = delta_from_ptrmemfunc (op0);
-             tree e1 = cp_build_binary_op (location,
-                                           EQ_EXPR,
-                                           pfn0,       
-                                           build_zero_cst (TREE_TYPE (pfn0)),
-                                           complain);
-             tree e2 = cp_build_binary_op (location,
-                                           BIT_AND_EXPR, 
-                                           delta0,
-                                           integer_one_node,
-                                           complain);
+             tree pfn0, delta0, e1, e2;
+
+             if (TREE_SIDE_EFFECTS (op0))
+               op0 = save_expr (op0);
+
+             pfn0 = pfn_from_ptrmemfunc (op0);
+             delta0 = delta_from_ptrmemfunc (op0);
+             e1 = cp_build_binary_op (location,
+                                      EQ_EXPR,
+                                      pfn0,
+                                      build_zero_cst (TREE_TYPE (pfn0)),
+                                      complain);
+             e2 = cp_build_binary_op (location,
+                                      BIT_AND_EXPR,
+                                      delta0,
+                                      integer_one_node,
+                                      complain);
              
              if ((complain & tf_warning)
                  && c_inhibit_evaluation_warnings == 0