re PR c++/84590 (-fsanitize=undefined internal compiler error: tree check: expected...
authorMarek Polacek <polacek@redhat.com>
Fri, 2 Mar 2018 09:48:41 +0000 (09:48 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 2 Mar 2018 09:48:41 +0000 (09:48 +0000)
PR c++/84590
* cp-gimplify.c (cp_fully_fold): Unwrap TARGET_EXPR or a CONSTRUCTOR
wrapped in VIEW_CONVERT_EXPR.

* c-c++-common/ubsan/shift-11.c: New test.

From-SVN: r258132

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/shift-11.c [new file with mode: 0644]

index 2d5363c4ddc69f2148c88d7b0b9f300eada9730e..c74d3bc3e7a8ac798bad99317e424762bf55d34c 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/84590
+       * cp-gimplify.c (cp_fully_fold): Unwrap TARGET_EXPR or a CONSTRUCTOR
+       wrapped in VIEW_CONVERT_EXPR.
+
 2018-03-01  Martin Sebor  <msebor@redhat.com>
 
        PR c++/84294
index 55a9d278dbe316972ca0b9651cfb40bc72e5e395..0ddd435454c92d26c45f98a58c40290d3d53fe3b 100644 (file)
@@ -2037,7 +2037,17 @@ cp_fully_fold (tree x)
   /* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't
      have to call both.  */
   if (cxx_dialect >= cxx11)
-    x = maybe_constant_value (x);
+    {
+      x = maybe_constant_value (x);
+      /* Sometimes we are given a CONSTRUCTOR but the call above wraps it into
+        a TARGET_EXPR; undo that here.  */
+      if (TREE_CODE (x) == TARGET_EXPR)
+       x = TARGET_EXPR_INITIAL (x);
+      else if (TREE_CODE (x) == VIEW_CONVERT_EXPR
+              && TREE_CODE (TREE_OPERAND (x, 0)) == CONSTRUCTOR
+              && TREE_TYPE (TREE_OPERAND (x, 0)) == TREE_TYPE (x))
+       x = TREE_OPERAND (x, 0);
+    }
   return cp_fold_rvalue (x);
 }
 
index e15927ca90e23cd44d784c9b0bdf9b71f6b695b0..17369ce0ebd2349567096624c0b38b4ed71841f2 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/84590
+       * c-c++-common/ubsan/shift-11.c: New test.
+
 2018-03-02  Richard Sandiford  <richard.sandiford@linaro.org>
 
        * gcc.dg/vect/vect-alias-check-13.c: New test.
diff --git a/gcc/testsuite/c-c++-common/ubsan/shift-11.c b/gcc/testsuite/c-c++-common/ubsan/shift-11.c
new file mode 100644 (file)
index 0000000..03a72e2
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR c++/84590 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=shift" } */
+
+struct S {
+  int b;
+};
+
+void
+fn (void)
+{
+  struct S c1 = { 1 << -1 }; /* { dg-warning "left shift" } */
+}