public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/51360] New: spurious unused-but-set-variable warning for var used in OpenMP pragma
@ 2011-11-30 17:20 kmccarty at gmail dot com
  2011-12-14 23:51 ` [Bug c/51360] [4.6/4.7 Regression] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: kmccarty at gmail dot com @ 2011-11-30 17:20 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-02-09 17:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-30 17:20 [Bug c/51360] New: spurious unused-but-set-variable warning for var used in OpenMP pragma kmccarty at gmail dot com
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

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).