From ec35ea455c30c14700dbb7a2cbbd3379e0212e96 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 6 Apr 2016 14:42:24 +0200 Subject: [PATCH] re PR middle-end/70550 (-Wuninitialized false positives in OpenMP code) PR middle-end/70550 * tree.h (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT): Define. * gimplify.c (gimplify_adjust_omp_clauses_1): Set it for implicit firstprivate clauses. * omp-low.c (lower_send_clauses): Set TREE_NO_WARNING for OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT !by_ref vars in task contexts. (lower_omp_target): Set TREE_NO_WARNING for non-addressable possibly uninitialized vars which are copied into addressable temporaries or copied for GOMP_MAP_FIRSTPRIVATE_INT. * c-c++-common/gomp/pr70550-1.c: New test. * c-c++-common/gomp/pr70550-2.c: New test. From-SVN: r234779 --- gcc/ChangeLog | 12 +++ gcc/gimplify.c | 2 + gcc/omp-low.c | 24 +++++- gcc/testsuite/ChangeLog | 6 ++ gcc/testsuite/c-c++-common/gomp/pr70550-1.c | 81 +++++++++++++++++++++ gcc/testsuite/c-c++-common/gomp/pr70550-2.c | 55 ++++++++++++++ gcc/tree.h | 4 + 7 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/pr70550-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/pr70550-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d0ae429b49d..e31d7cfff05 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2016-04-06 Jakub Jelinek + + PR middle-end/70550 + * tree.h (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT): Define. + * gimplify.c (gimplify_adjust_omp_clauses_1): Set it for implicit + firstprivate clauses. + * omp-low.c (lower_send_clauses): Set TREE_NO_WARNING for + OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT !by_ref vars in task contexts. + (lower_omp_target): Set TREE_NO_WARNING for + non-addressable possibly uninitialized vars which are copied into + addressable temporaries or copied for GOMP_MAP_FIRSTPRIVATE_INT. + 2016-04-05 John David Anglin * config/pa/predicates.md (integer_store_memory_operand): Accept diff --git a/gcc/gimplify.c b/gcc/gimplify.c index b9757db4c89..f29d608f5eb 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -7742,6 +7742,8 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data) && (flags & GOVD_WRITTEN) == 0 && omp_shared_to_firstprivate_optimizable_decl_p (decl)) OMP_CLAUSE_SHARED_READONLY (clause) = 1; + else if (code == OMP_CLAUSE_FIRSTPRIVATE && (flags & GOVD_EXPLICIT) == 0) + OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (clause) = 1; else if (code == OMP_CLAUSE_MAP && (flags & GOVD_MAP_0LEN_ARRAY) != 0) { tree nc = build_omp_clause (input_location, OMP_CLAUSE_MAP); diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 3fd6eb304b6..52a80059ef3 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -6107,8 +6107,15 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist, switch (OMP_CLAUSE_CODE (c)) { - case OMP_CLAUSE_PRIVATE: case OMP_CLAUSE_FIRSTPRIVATE: + if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) + && !by_ref + && is_task_ctx (ctx)) + TREE_NO_WARNING (var) = 1; + do_in = true; + break; + + case OMP_CLAUSE_PRIVATE: case OMP_CLAUSE_COPYIN: case OMP_CLAUSE__LOOPTEMP_: do_in = true; @@ -16083,7 +16090,16 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) || map_kind == GOMP_MAP_POINTER || map_kind == GOMP_MAP_TO_PSET || map_kind == GOMP_MAP_FORCE_DEVICEPTR) - gimplify_assign (avar, var, &ilist); + { + /* If we need to initialize a temporary + with VAR because it is not addressable, and + the variable hasn't been initialized yet, then + we'll get a warning for the store to avar. + Don't warn in that case, the mapping might + be implicit. */ + TREE_NO_WARNING (var) = 1; + gimplify_assign (avar, var, &ilist); + } avar = build_fold_addr_expr (avar); gimplify_assign (x, avar, &ilist); if ((GOMP_MAP_COPY_FROM_P (map_kind) @@ -16252,6 +16268,8 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) tree t = var; if (is_reference (var)) t = build_simple_mem_ref (var); + else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)) + TREE_NO_WARNING (var) = 1; if (TREE_CODE (type) != POINTER_TYPE) t = fold_convert (pointer_sized_int_node, t); t = fold_convert (TREE_TYPE (x), t); @@ -16263,6 +16281,8 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) { tree avar = create_tmp_var (TREE_TYPE (var)); mark_addressable (avar); + if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)) + TREE_NO_WARNING (var) = 1; gimplify_assign (avar, var, &ilist); avar = build_fold_addr_expr (avar); gimplify_assign (x, avar, &ilist); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2e5954ca8ac..5c4b95f9381 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-04-06 Jakub Jelinek + + PR middle-end/70550 + * c-c++-common/gomp/pr70550-1.c: New test. + * c-c++-common/gomp/pr70550-2.c: New test. + 2016-04-05 Nathan Sidwell PR c++/70512 diff --git a/gcc/testsuite/c-c++-common/gomp/pr70550-1.c b/gcc/testsuite/c-c++-common/gomp/pr70550-1.c new file mode 100644 index 00000000000..493d4175993 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pr70550-1.c @@ -0,0 +1,81 @@ +/* PR middle-end/70550 */ +/* { dg-do compile } */ +/* { dg-additional-options "-Wuninitialized" } */ + +#ifdef __SIZEOF_INT128__ +typedef __int128 T; +#else +typedef long long T; +#endif + +void bar (T); +#pragma omp declare target (bar) + +void +foo (void) +{ + { + int i; + #pragma omp target defaultmap(tofrom:scalar) /* { dg-bogus "is used uninitialized in this function" } */ + { + i = 26; + bar (i); + } + } + { + T j; + #pragma omp target defaultmap(tofrom:scalar) /* { dg-bogus "is used uninitialized in this function" } */ + { + j = 37; + bar (j); + } + } + { + int i; + #pragma omp target /* { dg-bogus "is used uninitialized in this function" } */ + { + i = 26; + bar (i); + } + } + { + T j; + #pragma omp target /* { dg-bogus "is used uninitialized in this function" } */ + { + j = 37; + bar (j); + } + } + { + int i; + #pragma omp target firstprivate (i) /* { dg-warning "is used uninitialized in this function" } */ + { + i = 26; + bar (i); + } + } + { + T j; + #pragma omp target firstprivate (j) /* { dg-warning "is used uninitialized in this function" } */ + { + j = 37; + bar (j); + } + } + { + int i; + #pragma omp target private (i) /* { dg-bogus "is used uninitialized in this function" } */ + { + i = 26; + bar (i); + } + } + { + T j; + #pragma omp target private (j) /* { dg-bogus "is used uninitialized in this function" } */ + { + j = 37; + bar (j); + } + } +} diff --git a/gcc/testsuite/c-c++-common/gomp/pr70550-2.c b/gcc/testsuite/c-c++-common/gomp/pr70550-2.c new file mode 100644 index 00000000000..31c34da4711 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pr70550-2.c @@ -0,0 +1,55 @@ +/* PR middle-end/70550 */ +/* { dg-do compile } */ +/* { dg-additional-options "-Wuninitialized" } */ + +void bar (int); + +void +foo (void) +{ + int i, j, k, l, m, n, o, p, q; + #pragma omp task /* { dg-bogus "is used uninitialized in this function" } */ + { + i = 2; + bar (i); + } + #pragma omp taskloop /* { dg-bogus "is used uninitialized in this function" } */ + for (j = 0; j < 10; j++) + { + k = 7; + bar (k); + } + #pragma omp task firstprivate (l) /* { dg-warning "is used uninitialized in this function" } */ + { + l = 2; + bar (l); + } + #pragma omp taskloop firstprivate (m) /* { dg-warning "is used uninitialized in this function" } */ + for (j = 0; j < 10; j++) + { + m = 7; + bar (m); + } + #pragma omp task shared (n) /* { dg-bogus "is used uninitialized in this function" } */ + { + n = 2; + bar (n); + } + #pragma omp taskloop shared (o) /* { dg-bogus "is used uninitialized in this function" } */ + for (j = 0; j < 10; j++) + { + o = 7; + bar (o); + } + #pragma omp task private (p) /* { dg-bogus "is used uninitialized in this function" } */ + { + p = 2; + bar (p); + } + #pragma omp taskloop shared (q) /* { dg-bogus "is used uninitialized in this function" } */ + for (j = 0; j < 10; j++) + { + q = 7; + bar (q); + } +} diff --git a/gcc/tree.h b/gcc/tree.h index 544a6a163df..fa705967e13 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1430,6 +1430,10 @@ extern void protected_set_expr_location (tree, location_t); #define OMP_CLAUSE_PRIVATE_TASKLOOP_IV(NODE) \ TREE_PROTECTED (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_PRIVATE)) +/* True on a FIRSTPRIVATE clause if it has been added implicitly. */ +#define OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT(NODE) \ + (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_FIRSTPRIVATE)->base.public_flag) + /* True on a LASTPRIVATE clause if a FIRSTPRIVATE clause for the same decl is present in the chain. */ #define OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE(NODE) \