From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45547 invoked by alias); 6 Apr 2016 12:46:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 44362 invoked by uid 89); 6 Apr 2016 12:46:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:protect X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 06 Apr 2016 12:46:13 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C44C412B48 for ; Wed, 6 Apr 2016 12:46:11 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-22.phx2.redhat.com [10.3.113.22]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u36CkA1V023961 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 6 Apr 2016 08:46:11 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u36Ck7Or000703 for ; Wed, 6 Apr 2016 14:46:08 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u36Ck6o7000702 for gcc-patches@gcc.gnu.org; Wed, 6 Apr 2016 14:46:06 +0200 Date: Wed, 06 Apr 2016 12:46:00 -0000 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Avoid -Wuninitialized warnings in certain OpenMP cases (PR middle-end/70550) Message-ID: <20160406124606.GW19207@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-04/txt/msg00295.txt.bz2 Hi! I've committed my counter-part of the recently posted OpenACC -Wuninitialized patch. omp-low already makes sure -Wuninitialized doesn't warn when used in shared clause (explicit or implicit). This patch adds to that avoidance of warning for mapping of vars in target construct (if they aren't addressable, we could warn), and for implicit firstprivate clauses on task/taskloop and target constructs. IMHO if somebody uses explicit firstprivate clause, then warning is desirable, if the var is uninitialized, one should better use private instead of firstprivate clause. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 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. * c-c++-common/gomp/pr70550-1.c: New test. * c-c++-common/gomp/pr70550-2.c: New test. --- gcc/tree.h.jj 2016-04-05 18:56:59.908992839 +0200 +++ gcc/tree.h 2016-04-06 10:04:46.616725165 +0200 @@ -1430,6 +1430,10 @@ extern void protected_set_expr_location #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) \ --- gcc/gimplify.c.jj 2016-04-05 18:57:00.038991093 +0200 +++ gcc/gimplify.c 2016-04-06 10:04:46.619725124 +0200 @@ -7742,6 +7742,8 @@ gimplify_adjust_omp_clauses_1 (splay_tre && (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); --- gcc/omp-low.c.jj 2016-04-05 18:57:00.092990368 +0200 +++ gcc/omp-low.c 2016-04-06 10:23:57.344978709 +0200 @@ -6107,8 +6107,15 @@ lower_send_clauses (tree clauses, gimple 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 * || 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 * 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 * { 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); --- gcc/testsuite/c-c++-common/gomp/pr70550-1.c.jj 2016-04-06 10:04:46.625725042 +0200 +++ gcc/testsuite/c-c++-common/gomp/pr70550-1.c 2016-04-06 10:04:46.625725042 +0200 @@ -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); + } + } +} --- gcc/testsuite/c-c++-common/gomp/pr70550-2.c.jj 2016-04-06 10:28:00.704648456 +0200 +++ gcc/testsuite/c-c++-common/gomp/pr70550-2.c 2016-04-06 10:29:48.939167321 +0200 @@ -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); + } +} Jakub