From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2543 invoked by alias); 30 Nov 2011 17:00:28 -0000 Received: (qmail 2532 invoked by uid 22791); 30 Nov 2011 17:00:26 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 30 Nov 2011 17:00:11 +0000 From: "kmccarty at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/51360] New: spurious unused-but-set-variable warning for var used in OpenMP pragma Date: Wed, 30 Nov 2011 17:20:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: kmccarty at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-11/txt/msg02868.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D51360 Bug #: 51360 Summary: spurious unused-but-set-variable warning for var used in OpenMP pragma Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: kmccarty@gmail.com Hi, gcc 4.6.2 produces a spurious unused variable warning for the following cod= e.=20 The variable 'num' is used in setting the number of threads within an OpenMP parallel region but the compiler does not realize this. The warning is: % /usr/local/gcc46/bin/gcc -Wall -fopenmp omp.c omp.c: In function =E2=80=98main=E2=80=99: omp.c:12:12: warning: variable =E2=80=98num=E2=80=99 set but not used [-Wunused-but-set-variable] % cat omp.c #include #include #include // Compile with: gcc -Wall -fopenmp omp.c // Run with: ./a.out e.g. "./a.out 4" int main(int argc, char ** argv) { if (argc !=3D 2) return EXIT_FAILURE; int vec[20] =3D { 0, }; int i, num =3D atoi(argv[1]); #pragma omp parallel for num_threads(num) for (i =3D 0; i < 20; ++i) { #pragma omp critical { printf("thread %d\n", (int)omp_get_thread_num()); fflush(stdout); } vec[i] *=3D 5; } return 0; } Running the generated binary (RHEL 4 update 6 on x86_64) with a specified v= alue for argv[1] indicates that the value of 'num' is being used as expected. gcc 4.2.4 and 4.4.3 do not warn with the same compiler flags. Thanks, - Kevin B. McCarty