Hi! While hacking on gomp-4.1 branch, I've noticed that -fopenmp-simd is broken for C++ for #pragma omp declare simd, and there is also an error recovery issue in c_omp_declare_simd_clauses_to_numbers. Additionally, tree-vect.h had some issues when included from C++ testcases, fixed those too so that I can include the new C++ testcase.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2015-07-08 Jakub Jelinek <ja...@redhat.com> * c-omp.c (c_omp_declare_simd_clauses_to_numbers): If all clauses are to be removed, return NULL rather than original clauses list. * decl.c (grokfndecl): Handle flag_openmp_simd like flag_openmp. * pt.c (apply_late_template_attributes): Likewise. * g++.dg/vect/vect.exp: Run also simd* tests. * gcc.dg/vect/tree-vect.h (abort, exit): For C++ use extern "C". (check_vect): Fix up get_cpuid call for C++. * g++.dg/vect/simd-clone-1.cc: New test. --- gcc/c-family/c-omp.c.jj 2015-06-30 14:24:33.000000000 +0200 +++ gcc/c-family/c-omp.c 2015-07-08 19:45:22.681603168 +0200 @@ -1092,6 +1092,8 @@ c_omp_declare_simd_clauses_to_numbers (t for (i = 0; i < len; i++) OMP_CLAUSE_CHAIN (clvec[i]) = (i < len - 1) ? clvec[i + 1] : NULL_TREE; } + else + clauses = NULL_TREE; clvec.release (); return clauses; } --- gcc/cp/decl.c.jj 2015-06-30 14:25:15.000000000 +0200 +++ gcc/cp/decl.c 2015-07-08 18:31:02.591975136 +0200 @@ -7905,7 +7905,7 @@ grokfndecl (tree ctype, if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl)) TREE_NOTHROW (decl) = 1; - if (flag_openmp || flag_cilkplus) + if (flag_openmp || flag_openmp_simd || flag_cilkplus) { /* Adjust "omp declare simd" attributes. */ tree ods = lookup_attribute ("omp declare simd", *attrlist); --- gcc/cp/pt.c.jj 2015-07-06 13:23:11.000000000 +0200 +++ gcc/cp/pt.c 2015-07-08 18:31:22.988688810 +0200 @@ -9065,7 +9065,7 @@ apply_late_template_attributes (tree *de { *p = TREE_CHAIN (t); TREE_CHAIN (t) = NULL_TREE; - if ((flag_openmp || flag_cilkplus) + if ((flag_openmp || flag_openmp_simd || flag_cilkplus) && is_attribute_p ("omp declare simd", get_attribute_name (t)) && TREE_VALUE (t)) --- gcc/testsuite/g++.dg/vect/vect.exp.jj 2015-04-24 12:31:59.000000000 +0200 +++ gcc/testsuite/g++.dg/vect/vect.exp 2015-07-08 18:24:16.799688191 +0200 @@ -58,7 +58,7 @@ lappend VECT_SLP_CFLAGS "-fdump-tree-slp dg-init # Main loop. -g++-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/pr*.{c,cc,S} ]] \ +g++-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/{pr,simd}*.{c,cc,S} ]] \ "" $DEFAULT_VECTCFLAGS g++-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/slp-pr*.{c,cc,S} ]] \ "" $VECT_SLP_CFLAGS --- gcc/testsuite/gcc.dg/vect/tree-vect.h.jj 2015-04-24 12:31:56.000000000 +0200 +++ gcc/testsuite/gcc.dg/vect/tree-vect.h 2015-07-08 18:33:40.066764526 +0200 @@ -5,8 +5,14 @@ # include "cpuid.h" #endif +#ifdef __cplusplus +extern "C" { +#endif extern void abort (void); extern void exit (int); +#ifdef __cplusplus +} +#endif static void sig_ill_handler (int sig) @@ -26,7 +32,7 @@ check_vect (void) asm volatile (".long 0x10000484"); #elif defined(__i386__) || defined(__x86_64__) { - int a, b, c, d, want_level, want_c, want_d; + unsigned int a, b, c, d, want_level, want_c, want_d; /* Determine what instruction set we've been compiled for, and detect that we're running with it. This allows us to at least do a compile --- gcc/testsuite/g++.dg/vect/simd-clone-1.cc.jj 2015-07-08 18:37:39.905397704 +0200 +++ gcc/testsuite/g++.dg/vect/simd-clone-1.cc 2015-07-08 18:41:13.577398206 +0200 @@ -0,0 +1,55 @@ +// { dg-require-effective-target vect_simd_clones } +// { dg-additional-options "-fopenmp-simd -fno-inline" } +// { dg-additional-options "-mavx" { target avx_runtime } } + +#include "../../gcc.dg/vect/tree-vect.h" + +struct S +{ + int s; + #pragma omp declare simd notinbranch linear(x) + int f (int x); +}; + +#pragma omp declare simd notinbranch linear(x) +int +S::f (int x) +{ + return x; +} + +template <int N> +struct T +{ + int t; + #pragma omp declare simd notinbranch linear(x) + int f (int x); +}; + +#pragma omp declare simd notinbranch linear(x) +template <int N> +int +T<N>::f (int x) +{ + return x; +} + +void +do_main () +{ + int i, r = 0; + S s; + T<0> t; + #pragma omp simd reduction(+:r) + for (i = 0; i < 64; i++) + r += s.f (i) + t.f (i); + if (r != 64 * 63) + abort (); +} + +int +main () +{ + check_vect (); + do_main (); +} Jakub