re PR target/70296 (Incorrect handling of vector X; if X is function-like macro)
authorJakub Jelinek <jakub@redhat.com>
Mon, 21 Mar 2016 15:41:13 +0000 (16:41 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 21 Mar 2016 15:41:13 +0000 (16:41 +0100)
PR target/70296
* include/cpplib.h (cpp_fun_like_macro_p): New prototype.
* macro.c (cpp_fun_like_macro_p): New function.

* config/rs6000/rs6000-c.c (rs6000_macro_to_expand): If IDENT is
function-like macro, peek following token(s) if it is followed
by CPP_OPEN_PAREN token with optional padding in between, and
if not, don't treat it like a macro.

* gcc.target/powerpc/altivec-36.c: New test.

From-SVN: r234371

gcc/ChangeLog
gcc/config/rs6000/rs6000-c.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/powerpc/altivec-36.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/include/cpplib.h
libcpp/macro.c

index b45acc50aa55888f8db5d16e381985be103a8a02..0bc45fd34e140e27bc2bf331b5431ee718b19836 100644 (file)
@@ -1,3 +1,11 @@
+2016-03-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/70296
+       * config/rs6000/rs6000-c.c (rs6000_macro_to_expand): If IDENT is
+       function-like macro, peek following token(s) if it is followed
+       by CPP_OPEN_PAREN token with optional padding in between, and
+       if not, don't treat it like a macro.
+
 2016-03-21  Thomas Schwinge  <thomas@codesourcery.com>
            Alexander Monakov  <amonakov@ispras.ru>
 
index b6e42f6ecada2a04214d993e258a6cccf8ab8f63..ceb80b216bae6ac6c7a6edd0851f007df1990078 100644 (file)
@@ -216,7 +216,21 @@ rs6000_macro_to_expand (cpp_reader *pfile, const cpp_token *tok)
       else if (ident && (ident != C_CPP_HASHNODE (__vector_keyword)))
        {
          enum rid rid_code = (enum rid)(ident->rid_code);
-         if (ident->type == NT_MACRO)
+         enum node_type itype = ident->type;
+         /* If there is a function-like macro, check if it is going to be
+            invoked with or without arguments.  Without following ( treat
+            it like non-macro, otherwise the following cpp_get_token eats
+            what should be preserved.  */
+         if (itype == NT_MACRO && cpp_fun_like_macro_p (ident))
+           {
+             int idx2 = idx;
+             do
+               tok = cpp_peek_token (pfile, idx2++);
+             while (tok->type == CPP_PADDING);
+             if (tok->type != CPP_OPEN_PAREN)
+               itype = NT_VOID;
+           }
+         if (itype == NT_MACRO)
            {
              do
                (void) cpp_get_token (pfile);
index 78802920f69a7fad26b3a1fe1e5fe7464b0a663d..77fbafc0bcb7b1ec4d4c0819f9f577d496553e97 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/70296
+       * gcc.target/powerpc/altivec-36.c: New test.
+
 2016-03-21  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/70310
diff --git a/gcc/testsuite/gcc.target/powerpc/altivec-36.c b/gcc/testsuite/gcc.target/powerpc/altivec-36.c
new file mode 100644 (file)
index 0000000..ce9e6a3
--- /dev/null
@@ -0,0 +1,46 @@
+/* PR target/70296 */
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-maltivec -std=gnu11" } */
+
+#define c(x) x
+#define f(x)
+#define i int
+#define k
+typedef int vector;
+typedef vector int V;
+vector int a;
+vector b;
+vector c(int) d;
+vector c(e);
+vector c;
+vector f(int) int g;
+vector f(int) h;
+vector i j;
+vector k int l;
+vector k m;
+#define int(x) x
+vector int n;
+vector int(int) o;
+vector int(r);
+#undef int
+
+void
+foo ()
+{
+  V *p;
+  p = &a;
+  p = &d;
+  p = &g;
+  p = &j;
+  p = &l;
+  p = &n;
+  p = &o;
+  int *q;
+  q = &b;
+  q = &e;
+  q = &c;
+  q = &h;
+  q = &m;
+  q = &r;
+}
index 89b582d75402a789f640f36f64e6aa99f6af6b50..2352b7d640b2663dd35b7f0d081ac53f32caacf0 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/70296
+       * include/cpplib.h (cpp_fun_like_macro_p): New prototype.
+       * macro.c (cpp_fun_like_macro_p): New function.
+
 2016-03-15  Richard Henderson  <rth@redhat.com>
 
        * line-map.c (new_linemap): Make alloc_size a size_t.
index 882f80cff468c005c9688f67cb8068aaa9942ddb..35b0375c09c6c7f6eebfcef045c3979febe53f7d 100644 (file)
@@ -813,6 +813,7 @@ extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
 extern const cpp_token *cpp_get_token (cpp_reader *);
 extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
                                                     source_location *);
+extern bool cpp_fun_like_macro_p (cpp_hashnode *);
 extern const unsigned char *cpp_macro_definition (cpp_reader *,
                                                  cpp_hashnode *);
 extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
index cfb09ceaddddbb28c1b0d4dc69c1fb26adb58eb7..759fbe7f028c4299a2270d579d8d6da2b3200cd5 100644 (file)
@@ -3301,6 +3301,15 @@ check_trad_stringification (cpp_reader *pfile, const cpp_macro *macro,
     }
 }
 
+/* Returns true of NODE is a function-like macro.  */
+bool
+cpp_fun_like_macro_p (cpp_hashnode *node)
+{
+  return (node->type == NT_MACRO
+         && (node->flags & (NODE_BUILTIN | NODE_MACRO_ARG)) == 0
+         && node->value.macro->fun_like);
+}
+
 /* Returns the name, arguments and expansion of a macro, in a format
    suitable to be read back in again, and therefore also for DWARF 2
    debugging info.  e.g. "PASTE(X, Y) X ## Y", or "MACNAME EXPANSION".