re PR target/60062 (wrong code (for code with the optimize attribute) at -O1 and...
authorJakub Jelinek <jakub@redhat.com>
Thu, 6 Feb 2014 10:54:20 +0000 (11:54 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 6 Feb 2014 10:54:20 +0000 (11:54 +0100)
PR target/60062
* tree.h (opts_for_fn): New inline function.
(opt_for_fn): Define.
* config/i386/i386.c (ix86_function_regparm): Use
opt_for_fn (decl, optimize) instead of optimize.

* gcc.c-torture/execute/pr60062.c: New test.
* gcc.c-torture/execute/pr60072.c: New test.

From-SVN: r207549

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr60062.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/pr60072.c [new file with mode: 0644]
gcc/tree.h

index 078192de17aacd3218c6f5b94937a21fcce2598b..7028dd60e6d2b8cbbf63bd08c4fbb42e647d2bf1 100644 (file)
@@ -1,3 +1,11 @@
+2014-02-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/60062
+       * tree.h (opts_for_fn): New inline function.
+       (opt_for_fn): Define.
+       * config/i386/i386.c (ix86_function_regparm): Use
+       opt_for_fn (decl, optimize) instead of optimize.
+
 2014-02-06  Marcus Shawcroft  <marcus.shawcroft@arm.com>
 
        * config/aarch64/aarch64.c (aarch64_classify_symbol): Fix logic
index 58f36e0445a06f17d99a33b089882a2df8881146..abe05aab36eb1648fd377a9be20fb30115b47dc4 100644 (file)
@@ -5608,7 +5608,12 @@ ix86_function_regparm (const_tree type, const_tree decl)
   /* Use register calling convention for local functions when possible.  */
   if (decl
       && TREE_CODE (decl) == FUNCTION_DECL
-      && optimize
+      /* Caller and callee must agree on the calling convention, so
+        checking here just optimize means that with
+        __attribute__((optimize (...))) caller could use regparm convention
+        and callee not, or vice versa.  Instead look at whether the callee
+        is optimized or not.  */
+      && opt_for_fn (decl, optimize)
       && !(profile_flag && !flag_fentry))
     {
       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
index a91c110d7e684f76a0d00c8d655751123f80fb68..552b591e240b0a71dcde602d5724611582482908 100644 (file)
@@ -1,3 +1,9 @@
+2014-02-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/60062
+       * gcc.c-torture/execute/pr60062.c: New test.
+       * gcc.c-torture/execute/pr60072.c: New test.
+
 2014-02-06  Ian Bolton  <ian.bolton@arm.com>
 
        * gcc.dg/tree-ssa/pr59597.c: Make called function static
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr60062.c b/gcc/testsuite/gcc.c-torture/execute/pr60062.c
new file mode 100644 (file)
index 0000000..62973d4
--- /dev/null
@@ -0,0 +1,25 @@
+/* PR target/60062 */
+
+int a;
+
+static void
+foo (const char *p1, int p2)
+{
+  if (__builtin_strcmp (p1, "hello") != 0)
+    __builtin_abort ();
+}
+
+static void
+bar (const char *p1)
+{
+  if (__builtin_strcmp (p1, "hello") != 0)
+    __builtin_abort ();
+}
+
+__attribute__((optimize (0))) int
+main ()
+{
+  foo ("hello", a);
+  bar ("hello");
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr60072.c b/gcc/testsuite/gcc.c-torture/execute/pr60072.c
new file mode 100644 (file)
index 0000000..566874d
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR target/60072 */
+
+int c = 1;
+
+__attribute__ ((optimize (1)))
+static int *foo (int *p)
+{
+  return p;
+}
+
+int
+main ()
+{
+  *foo (&c) = 2;
+  return c - 2;
+}
index e918ec54d24bd8771e3252c65ae436ab70f23cf0..0dc8d0dcd4f572f4b5c204740607ca80e83b487e 100644 (file)
@@ -4470,6 +4470,20 @@ may_be_aliased (const_tree var)
              || TREE_ADDRESSABLE (var)));
 }
 
+/* Return pointer to optimization flags of FNDECL.  */
+static inline struct cl_optimization *
+opts_for_fn (const_tree fndecl)
+{
+  tree fn_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
+  if (fn_opts == NULL_TREE)
+    fn_opts = optimization_default_node;
+  return TREE_OPTIMIZATION (fn_opts);
+}
+
+/* opt flag for function FNDECL, e.g. opts_for_fn (fndecl, optimize) is
+   the optimization level of function fndecl.  */
+#define opt_for_fn(fndecl, opt) (opts_for_fn (fndecl)->x_##opt)
+
 /* For anonymous aggregate types, we need some sort of name to
    hold on to.  In practice, this should not appear, but it should
    not be harmful if it does.  */