Allow more kinds of invariant addresses in GIMPLE FE
authorRichard Biener <rguenther@suse.de>
Tue, 5 Oct 2021 12:18:09 +0000 (14:18 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 5 Oct 2021 14:37:39 +0000 (16:37 +0200)
The gimple FE is too restrictive in what it accepts as
literals, the following makes it also accept &a[10] for example.

2021-10-05  Richard Biener  <rguenther@suse.de>

PR c/102605
gcc/c/
* gimple-parser.c (c_parser_gimple_postfix_expression):
Accept more address _Literals.

gcc/testsuite/
* gcc.dg/gimplefe-46.c: New testcase.

gcc/c/gimple-parser.c
gcc/testsuite/gcc.dg/gimplefe-46.c [new file with mode: 0644]

index c8d9db6..c43ee38 100644 (file)
@@ -1622,16 +1622,20 @@ c_parser_gimple_postfix_expression (gimple_parser &parser)
                  tree val = c_parser_gimple_postfix_expression (parser).value;
                  if (! val
                      || val == error_mark_node
-                     || (!CONSTANT_CLASS_P (val)
-                         && !(addr_p
-                              && (TREE_CODE (val) == STRING_CST
-                                  || DECL_P (val)))))
+                     || (!CONSTANT_CLASS_P (val) && !addr_p))
                    {
                      c_parser_error (parser, "invalid _Literal");
                      return expr;
                    }
                  if (addr_p)
-                   val = build1 (ADDR_EXPR, type, val);
+                   {
+                     val = build1 (ADDR_EXPR, type, val);
+                     if (!is_gimple_invariant_address (val))
+                       {
+                         c_parser_error (parser, "invalid _Literal");
+                         return expr;
+                       }
+                   }
                  if (neg_p)
                    {
                      val = const_unop (NEGATE_EXPR, TREE_TYPE (val), val);
diff --git a/gcc/testsuite/gcc.dg/gimplefe-46.c b/gcc/testsuite/gcc.dg/gimplefe-46.c
new file mode 100644 (file)
index 0000000..fb91f7d
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+char global[10];
+
+void bar (void);
+
+void __GIMPLE (ssa)
+foo (char * p)
+{
+  __BB(2):
+  if (p_2(D) == _Literal (char *)&global[2])
+    goto __BB3;
+  else
+    goto __BB4;
+
+  __BB(3):
+  bar ();
+  goto __BB4;
+
+  __BB(4):
+  return;
+}