]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c/101512 - fix missing address-taking in c_common_mark_addressable_vec
authorRichard Biener <rguenther@suse.de>
Wed, 21 Jul 2021 07:14:24 +0000 (09:14 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 29 Jul 2021 06:13:29 +0000 (08:13 +0200)
c_common_mark_addressable_vec fails to look through C_MAYBE_CONST_EXPR
in the case it isn't at the toplevel.

2021-07-21  Richard Biener  <rguenther@suse.de>

PR c/101512
gcc/c-family/
* c-common.c (c_common_mark_addressable_vec): Look through
C_MAYBE_CONST_EXPR even if not at the toplevel.

gcc/testsuite/
* gcc.dg/torture/pr101512.c: New testcase.

gcc/c-family/c-common.c
gcc/testsuite/gcc.dg/torture/pr101512.c [new file with mode: 0644]

index aacdfb46a0296e7fbd784678ca7e73315218c2c9..21da679cd3cf2073f3f7d9f7d18bf03d4a5e1fcf 100644 (file)
@@ -6894,10 +6894,13 @@ complete_flexible_array_elts (tree init)
 void 
 c_common_mark_addressable_vec (tree t)
 {   
-  if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
-    t = C_MAYBE_CONST_EXPR_EXPR (t);
-  while (handled_component_p (t))
-    t = TREE_OPERAND (t, 0);
+  while (handled_component_p (t) || TREE_CODE (t) == C_MAYBE_CONST_EXPR)
+    {
+      if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
+       t = C_MAYBE_CONST_EXPR_EXPR (t);
+      else
+       t = TREE_OPERAND (t, 0);
+    }
   if (!VAR_P (t)
       && TREE_CODE (t) != PARM_DECL
       && TREE_CODE (t) != COMPOUND_LITERAL_EXPR)
diff --git a/gcc/testsuite/gcc.dg/torture/pr101512.c b/gcc/testsuite/gcc.dg/torture/pr101512.c
new file mode 100644 (file)
index 0000000..a25da2a
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-w -Wno-psabi" } */
+
+int n();
+typedef unsigned long V __attribute__ ((vector_size (64)));
+V
+foo (int i, V v)
+{
+  i = ((V)(V){n()})[n()];
+  return v + i;
+}