From patchwork Thu Dec 15 17:38:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 131715 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C8A301007D4 for ; Fri, 16 Dec 2011 04:39:11 +1100 (EST) Received: (qmail 8115 invoked by alias); 15 Dec 2011 17:39:09 -0000 Received: (qmail 8106 invoked by uid 22791); 15 Dec 2011 17:39:09 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 15 Dec 2011 17:38:54 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pBFHcsPo010621 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 15 Dec 2011 12:38:54 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pBFHcrEL001029 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 15 Dec 2011 12:38:54 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id pBFHcrJc004992 for ; Thu, 15 Dec 2011 18:38:53 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id pBFHcqUg004991 for gcc-patches@gcc.gnu.org; Thu, 15 Dec 2011 18:38:52 +0100 Date: Thu, 15 Dec 2011 18:38:52 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Fix up -fopenmp -Wunused-but-set-* (PR c/51360) Message-ID: <20111215173852.GT1957@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi! Both the C and C++ FEs weren't marking num_threads/schedule clause expressions as read, so we could end up with false positive -Wunused-but-set-{variable,parameter} warnings. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. Will backport to 4.6 soon. 2011-12-15 Jakub Jelinek PR c/51360 * c-parser.c (c_parser_omp_clause_num_threads, c_parser_omp_clause_schedule): Call mark_exp_read. * semantics.c (finish_omp_clauses): For OMP_CLAUSE_NUM_THREADS_EXPR and OMP_CLAUSE_SCHEDULE_CHUNK_EXPR call mark_rvalue_use. * c-c++-common/gomp/pr51360.c: New test. * g++.dg/gomp/pr51360.C: New test. Jakub --- gcc/c-parser.c.jj 2011-12-01 11:45:06.000000000 +0100 +++ gcc/c-parser.c 2011-12-15 13:59:12.761892100 +0100 @@ -9011,6 +9011,7 @@ c_parser_omp_clause_num_threads (c_parse { location_t expr_loc = c_parser_peek_token (parser)->location; tree c, t = c_parser_expression (parser).value; + mark_exp_read (t); t = c_fully_fold (t, false, NULL); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); @@ -9218,6 +9219,7 @@ c_parser_omp_clause_schedule (c_parser * here = c_parser_peek_token (parser)->location; t = c_parser_expr_no_commas (parser, NULL).value; + mark_exp_read (t); t = c_fully_fold (t, false, NULL); if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME) --- gcc/cp/semantics.c.jj 2011-12-15 08:06:54.000000000 +0100 +++ gcc/cp/semantics.c 2011-12-15 14:20:04.048888247 +0100 @@ -4087,6 +4087,8 @@ finish_omp_clauses (tree clauses) error ("num_threads expression must be integral"); remove = true; } + else + OMP_CLAUSE_NUM_THREADS_EXPR (c) = mark_rvalue_use (t); break; case OMP_CLAUSE_SCHEDULE: @@ -4101,6 +4103,8 @@ finish_omp_clauses (tree clauses) error ("schedule chunk size expression must be integral"); remove = true; } + else + OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = mark_rvalue_use (t); break; case OMP_CLAUSE_NOWAIT: --- gcc/testsuite/c-c++-common/gomp/pr51360.c.jj 2011-12-15 14:20:43.150577783 +0100 +++ gcc/testsuite/c-c++-common/gomp/pr51360.c 2011-12-15 14:14:56.000000000 +0100 @@ -0,0 +1,27 @@ +/* PR c/51360 */ +/* { dg-do compile } */ +/* { dg-options "-Wunused -W -fopenmp" } */ + +void +foo (int a, int b, int c, int d) +{ + int m, n, o, p, i; + m = 6; + n = 1; + o = 5; + p = 1; + a = 6; + b = 1; + c = 5; + d = 1; + #pragma omp parallel for num_threads (m) if (n) schedule (static, o) + for (i = 0; i < 10; i++) + ; + #pragma omp parallel for num_threads (a) if (b) schedule (static, c) + for (i = 0; i < 10; i++) + ; + #pragma omp task final (p) + ; + #pragma omp task final (d) + ; +} --- gcc/testsuite/g++.dg/gomp/pr51360.C.jj 2011-12-15 14:21:02.447810143 +0100 +++ gcc/testsuite/g++.dg/gomp/pr51360.C 2011-12-15 14:17:54.000000000 +0100 @@ -0,0 +1,34 @@ +// PR c/51360 +// { dg-do compile } +// { dg-options "-Wunused -W -fopenmp" } + +template +void +foo (T a, T b, T c, T d) +{ + T m, n, o, p, i; + m = 6; + n = 1; + o = 5; + p = 1; + a = 6; + b = 1; + c = 5; + d = 1; + #pragma omp parallel for num_threads (m) if (n) schedule (static, o) + for (i = 0; i < 10; i++) + ; + #pragma omp parallel for num_threads (a) if (b) schedule (static, c) + for (i = 0; i < 10; i++) + ; + #pragma omp task final (p) + ; + #pragma omp task final (d) + ; +} + +void +bar () +{ + foo (0, 0, 0, 0); +}