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 <ja...@redhat.com> 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. --- 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 <typename T> +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); +} Jakub