This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C PATCH for c/65345 (file-scope _Atomic expansion with floats)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Joseph Myers <joseph at codesourcery dot com>, clm at codesourcery dot com, matthew dot fortune at imgtec dot com, dje dot gcc at gmail dot com, Eric Botcazou <ebotcazou at adacore dot com>, Richard Henderson <rth at redhat dot com>, Uros Bizjak <ubizjak at gmail dot com>, davem at redhat dot com, uweigand at de dot ibm dot com, Andreas dot Krebbel at de dot ibm dot com, richard dot earnshaw at arm dot com, ramana dot radhakrishnan at arm dot com, nickc at redhat dot com, olegendo at gcc dot gnu dot org, kkojima at gcc dot gnu dot org, marcus dot shawcroft at arm dot com
- Date: Thu, 1 Oct 2015 16:49:41 +0200
- Subject: C PATCH for c/65345 (file-scope _Atomic expansion with floats)
- Authentication-results: sourceware.org; auth=none
Joseph reminded me that I had forgotten about this patch. As mentioned
here <https://gcc.gnu.org/ml/gcc-patches/2015-04/msg01792.html>, I'm
removing the XFAILs in the tests so people are likely to see new FAILs.
I think the following targets will need similar fix as the one below:
* MIPS
* rs6000
* alpha
* sparc
* s390
* arm
* sh
* aarch64
I'm CCing the respective maintainers. You might want to XFAIL those tests.
Applying to trunk.
2015-10-01 Marek Polacek <polacek@redhat.com>
PR c/65345
* config/i386/i386.c (ix86_atomic_assign_expand_fenv): Adjust to use
create_tmp_var_raw rather than create_tmp_var.
* gcc.dg/atomic/pr65345-4.c: New test.
* gcc.dg/pr65345-3.c: New test.
diff --git gcc/config/i386/i386.c gcc/config/i386/i386.c
index fe9c756..cfeba76 100644
--- gcc/config/i386/i386.c
+++ gcc/config/i386/i386.c
@@ -53128,13 +53128,13 @@ ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
{
if (!TARGET_80387 && !TARGET_SSE_MATH)
return;
- tree exceptions_var = create_tmp_var (integer_type_node);
+ tree exceptions_var = create_tmp_var_raw (integer_type_node);
if (TARGET_80387)
{
tree fenv_index_type = build_index_type (size_int (6));
tree fenv_type = build_array_type (unsigned_type_node, fenv_index_type);
- tree fenv_var = create_tmp_var (fenv_type);
- mark_addressable (fenv_var);
+ tree fenv_var = create_tmp_var_raw (fenv_type);
+ TREE_ADDRESSABLE (fenv_var) = 1;
tree fenv_ptr = build_pointer_type (fenv_type);
tree fenv_addr = build1 (ADDR_EXPR, fenv_ptr, fenv_var);
fenv_addr = fold_convert (ptr_type_node, fenv_addr);
@@ -53144,10 +53144,12 @@ ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
tree fnclex = ix86_builtins[IX86_BUILTIN_FNCLEX];
tree hold_fnstenv = build_call_expr (fnstenv, 1, fenv_addr);
tree hold_fnclex = build_call_expr (fnclex, 0);
- *hold = build2 (COMPOUND_EXPR, void_type_node, hold_fnstenv,
+ fenv_var = build4 (TARGET_EXPR, fenv_type, fenv_var, hold_fnstenv,
+ NULL_TREE, NULL_TREE);
+ *hold = build2 (COMPOUND_EXPR, void_type_node, fenv_var,
hold_fnclex);
*clear = build_call_expr (fnclex, 0);
- tree sw_var = create_tmp_var (short_unsigned_type_node);
+ tree sw_var = create_tmp_var_raw (short_unsigned_type_node);
tree fnstsw_call = build_call_expr (fnstsw, 0);
tree sw_mod = build2 (MODIFY_EXPR, short_unsigned_type_node,
sw_var, fnstsw_call);
@@ -53161,8 +53163,8 @@ ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
}
if (TARGET_SSE_MATH)
{
- tree mxcsr_orig_var = create_tmp_var (unsigned_type_node);
- tree mxcsr_mod_var = create_tmp_var (unsigned_type_node);
+ tree mxcsr_orig_var = create_tmp_var_raw (unsigned_type_node);
+ tree mxcsr_mod_var = create_tmp_var_raw (unsigned_type_node);
tree stmxcsr = ix86_builtins[IX86_BUILTIN_STMXCSR];
tree ldmxcsr = ix86_builtins[IX86_BUILTIN_LDMXCSR];
tree stmxcsr_hold_call = build_call_expr (stmxcsr, 0);
diff --git gcc/testsuite/gcc.dg/atomic/pr65345-4.c gcc/testsuite/gcc.dg/atomic/pr65345-4.c
index e69de29..6d44def 100644
--- gcc/testsuite/gcc.dg/atomic/pr65345-4.c
+++ gcc/testsuite/gcc.dg/atomic/pr65345-4.c
@@ -0,0 +1,58 @@
+/* PR c/65345 */
+/* { dg-options "" } */
+
+#define CHECK(X) if (!(X)) __builtin_abort ()
+
+_Atomic float i = 5;
+_Atomic float j = 2;
+
+void
+fn1 (float a[(int) (i = 0)])
+{
+}
+
+void
+fn2 (float a[(int) (i += 2)])
+{
+}
+
+void
+fn3 (float a[(int) ++i])
+{
+}
+
+void
+fn4 (float a[(int) ++i])
+{
+}
+
+void
+fn5 (float a[(int) ++i][(int) (j = 10)])
+{
+}
+
+void
+fn6 (float a[(int) (i = 7)][(int) j--])
+{
+}
+
+int
+main ()
+{
+ float a[10];
+ float aa[10][10];
+ fn1 (a);
+ CHECK (i == 0);
+ fn2 (a);
+ CHECK (i == 2);
+ fn3 (a);
+ CHECK (i == 3);
+ fn4 (a);
+ CHECK (i == 4);
+ fn5 (aa);
+ CHECK (i == 5);
+ CHECK (j == 10);
+ fn6 (aa);
+ CHECK (i == 7);
+ CHECK (j == 9);
+}
diff --git gcc/testsuite/gcc.dg/pr65345-3.c gcc/testsuite/gcc.dg/pr65345-3.c
index e69de29..cda9364 100644
--- gcc/testsuite/gcc.dg/pr65345-3.c
+++ gcc/testsuite/gcc.dg/pr65345-3.c
@@ -0,0 +1,35 @@
+/* PR c/65345 */
+/* { dg-options "" } */
+
+_Atomic float i = 3.0f;
+
+float a1 = sizeof (i + 1.2);
+float a2 = sizeof (i = 0);
+float a3 = sizeof (i++);
+float a4 = sizeof (i--);
+float a5 = sizeof (-i);
+
+float b1 = _Alignof (i + 1);
+float b2 = _Alignof (i = 0);
+float b3 = _Alignof (i++);
+float b4 = _Alignof (i--);
+float b5 = _Alignof (-i);
+
+float c1 = i; /* { dg-error "initializer element is not constant" } */
+float c2 = (i ? 1 : 2); /* { dg-error "initializer element is not constant" } */
+float c3[(int) i]; /* { dg-error "variably modified" } */
+float c4 = 0 || i; /* { dg-error "initializer element is not constant" } */
+float c5 = (i += 10); /* { dg-error "initializer element is not constant" } */
+
+_Static_assert (_Generic (i, float: 1, default: 0) == 1, "1");
+_Static_assert (_Generic (i + 1, float: 1, default: 0) == 1, "2");
+_Static_assert (_Generic (i = 0, float: 1, default: 0) == 1, "3");
+_Static_assert (_Generic (i++, float: 1, default: 0) == 1, "4");
+_Static_assert (_Generic (i--, float: 1, default: 0) == 1, "5");
+
+_Atomic int sz = 2;
+void fn1 (float a[sz + 1]);
+void fn2 (float a[sz = 0]);
+void fn3 (float a[sz++]);
+void fn4 (float a[sz--]);
+void fn5 (float a[-sz]);
Marek