public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "kmccarty at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-51360-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51360 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 code. 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 ‘main’: omp.c:12:12: warning: variable ‘num’ set but not used [-Wunused-but-set-variable] % cat omp.c #include <omp.h> #include <stdlib.h> #include <stdio.h> // Compile with: gcc -Wall -fopenmp omp.c // Run with: ./a.out <num_threads> e.g. "./a.out 4" int main(int argc, char ** argv) { if (argc != 2) return EXIT_FAILURE; int vec[20] = { 0, }; int i, num = atoi(argv[1]); #pragma omp parallel for num_threads(num) for (i = 0; i < 20; ++i) { #pragma omp critical { printf("thread %d\n", (int)omp_get_thread_num()); fflush(stdout); } vec[i] *= 5; } return 0; } Running the generated binary (RHEL 4 update 6 on x86_64) with a specified value 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
next reply other threads:[~2011-11-30 17:00 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-11-30 17:20 kmccarty at gmail dot com [this message] 2011-12-14 23:51 ` [Bug c/51360] [4.6/4.7 Regression] " pinskia at gcc dot gnu.org 2011-12-15 13:38 ` jakub at gcc dot gnu.org 2011-12-15 17:51 ` jakub at gcc dot gnu.org 2011-12-15 20:51 ` [Bug c/51360] [4.6 " jakub at gcc dot gnu.org 2012-02-09 17:16 ` jakub at gcc dot gnu.org 2012-02-09 17:41 ` jakub at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-51360-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).