re PR c/82167 (Segmentation fault when dereferencing the address of an array argument)
authorMarek Polacek <polacek@redhat.com>
Wed, 13 Sep 2017 16:46:17 +0000 (16:46 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 13 Sep 2017 16:46:17 +0000 (16:46 +0000)
PR c/82167
* c-typeck.c (c_expr_sizeof_expr): Use the type of expr.value rather
than expr.original_type.

* gcc.dg/pr82167.c: New test.

From-SVN: r252372

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr82167.c [new file with mode: 0644]

index d55b5ac42e48085fd7fdc58975e9ea4f29f3f4fb..957daeb4fe9979e7587c69fbf8daa2813e6a2636 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-13  Marek Polacek  <polacek@redhat.com>
+
+       PR c/82167
+       * c-typeck.c (c_expr_sizeof_expr): Use the type of expr.value rather
+       than expr.original_type.
+
 2017-09-12  Nathan Sidwell  <nathan@acm.org>
 
        * c-decl.c (field_decl_cmp, resort_data, resort_field_decl_cmp,
index 91996c95ed070c0b68f024a0df9aa054d2a84a93..f45fd3cfbbf0942aa6f048f0cef0f8dbd9197ff7 100644 (file)
@@ -2909,7 +2909,7 @@ c_expr_sizeof_expr (location_t loc, struct c_expr expr)
          if (warning_at (loc, OPT_Wsizeof_array_argument,
                          "%<sizeof%> on array function parameter %qE will "
                          "return size of %qT", expr.value,
-                         expr.original_type))
+                         TREE_TYPE (expr.value)))
            inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
        }
       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
index 2091f98c11a10d54549f953bc89eb206f99c614c..1280e90308b69bbd6d0a9cb796caa6ec68790b8e 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-13  Marek Polacek  <polacek@redhat.com>
+
+       PR c/82167
+       * gcc.dg/pr82167.c: New test.
+
 2017-09-13  Will Schmidt  <will_schmidt@vnet.ibm.com>
 
        * gcc.target/powerpc/fold-vec-ld-char.c: New.
diff --git a/gcc/testsuite/gcc.dg/pr82167.c b/gcc/testsuite/gcc.dg/pr82167.c
new file mode 100644 (file)
index 0000000..af3b3a5
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR c/82167 */
+/* { dg-do compile } */
+
+void
+fn1 (int a[])
+{
+  __builtin_printf ("%zu\n", sizeof (*&a)); /* { dg-warning ".sizeof. on array function parameter .a. will return size of .int \\*." } */
+}
+
+void
+fn2 (int *a[])
+{
+  __builtin_printf ("%zu\n", sizeof (*&a)); /* { dg-warning ".sizeof. on array function parameter .a. will return size of .int \\*\\*." } */
+}