The patch kit affects the locations of the errors reported by g++.dg/gomp/loop-1.C.
I reviewed the new locations, and they seemed sane. This patch updates the locations of omp_for_cond to use the location of the cond if available, falling back to the existing behavior of using input_location otherwise. This improves the reported locations. The patch also updates the testcase to reflect the various changes to the locations. For reference, here's the updated output from the testcase (with caret-printing enabled): g++.dg/gomp/loop-1.C: In function ‘void f1(int)’: g++.dg/gomp/loop-1.C:21:3: error: initializer expression refers to iteration variable ‘i’ for (i = i; i < 16; i++) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:24:14: error: initializer expression refers to iteration variable ‘i’ for (i = 2 * (i & x); i < 16; i++) /* { dg-error "initializer expression refers to iteration variable" } */ ~~^~~~~~~~~ g++.dg/gomp/loop-1.C:27:3: error: initializer expression refers to iteration variable ‘i’ for (i = bar (i); i < 16; i++) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:30:3: error: initializer expression refers to iteration variable ‘i’ for (i = baz (&i); i < 16; i++) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:33:17: error: condition expression refers to iteration variable ‘i’ for (i = 5; i < 2 * i + 17; i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~~~~~~ g++.dg/gomp/loop-1.C:36:26: error: condition expression refers to iteration variable ‘i’ for (i = 5; 2 * i + 17 > i; i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~~~~~~~~~~^~~ g++.dg/gomp/loop-1.C:39:23: error: condition expression refers to iteration variable ‘i’ for (i = 5; bar (i) > i; i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~~~~~~~^~~ g++.dg/gomp/loop-1.C:42:17: error: condition expression refers to iteration variable ‘i’ for (i = 5; i <= baz (&i); i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~~~~~ g++.dg/gomp/loop-1.C:45:17: error: condition expression refers to iteration variable ‘i’ for (i = 5; i <= i; i++) /* { dg-error "invalid controlling predicate|condition expression refers to iteration variable" } */ ~~^~~~ g++.dg/gomp/loop-1.C:48:3: error: increment expression refers to iteration variable ‘i’ for (i = 5; i < 16; i += i) /* { dg-error "increment expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:51:33: error: increment expression refers to iteration variable ‘i’ for (i = 5; i < 16; i = i + 2 * i) /* { dg-error "invalid increment expression|increment expression refers to iteration variable" } */ ~~^~~ g++.dg/gomp/loop-1.C:54:3: error: increment expression refers to iteration variable ‘i’ for (i = 5; i < 16; i = i + i) /* { dg-error "increment expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:57:35: error: increment expression refers to iteration variable ‘i’ for (i = 5; i < 16; i = i + bar (i)) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~ g++.dg/gomp/loop-1.C:60:31: error: increment expression refers to iteration variable ‘i’ for (i = 5; i < 16; i = baz (&i) + i) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~~ g++.dg/gomp/loop-1.C:63:32: error: increment expression refers to iteration variable ‘i’ for (i = 5; i < 16; i += bar (i)) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~ g++.dg/gomp/loop-1.C:66:32: error: increment expression refers to iteration variable ‘i’ for (i = 5; i < 16; i += baz (&i)) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~~ g++.dg/gomp/loop-1.C:73:3: error: initializer expression refers to iteration variable ‘j’ for (i = j; i < 16; i = i + 2) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:77:3: error: initializer expression refers to iteration variable ‘i’ for (i = 0; i < 16; i = i + 2) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:82:16: error: initializer expression refers to iteration variable ‘i’ for (j = i + 3; j < 16; j += 2) /* { dg-error "initializer expression refers to iteration variable" } */ ~~^~~ g++.dg/gomp/loop-1.C:85:3: error: initializer expression refers to iteration variable ‘i’ for (i = 0; i < 16; i++) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:90:20: error: condition expression refers to iteration variable ‘i’ for (j = 16; j > (i & x); j--) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~~~ g++.dg/gomp/loop-1.C:94:19: error: condition expression refers to iteration variable ‘i’ for (j = 0; j < i; j++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~ g++.dg/gomp/loop-1.C:98:19: error: condition expression refers to iteration variable ‘i’ for (j = 0; j < i + 4; j++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~ g++.dg/gomp/loop-1.C:101:17: error: condition expression refers to iteration variable ‘j’ for (i = 0; i < j + 4; i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~ g++.dg/gomp/loop-1.C:105:17: error: condition expression refers to iteration variable ‘j’ for (i = 0; i < j; i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~ g++.dg/gomp/loop-1.C:109:17: error: condition expression refers to iteration variable ‘j’ for (i = 0; i < bar (j); i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~~~ g++.dg/gomp/loop-1.C:114:19: error: condition expression refers to iteration variable ‘i’ for (j = 0; j < baz (&i); j++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~~~~ g++.dg/gomp/loop-1.C:117:3: error: increment expression refers to iteration variable ‘j’ for (i = 0; i < 16; i += j) /* { dg-error "increment expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:121:3: error: increment expression refers to iteration variable ‘i’ for (i = 0; i < 16; i++) /* { dg-error "increment expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:125:3: error: increment expression refers to iteration variable ‘j’ for (i = 0; i < 16; i = j + i) /* { dg-error "increment expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:129:3: error: increment expression refers to iteration variable ‘i’ for (i = 0; i < 16; i++) /* { dg-error "increment expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:133:31: error: increment expression refers to iteration variable ‘j’ for (i = 0; i < 16; i = bar (j) + i) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~ g++.dg/gomp/loop-1.C:138:37: error: increment expression refers to iteration variable ‘i’ for (j = 0; j < 16; j = j + baz (&i)) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~~ g++.dg/gomp/loop-1.C: In function ‘void f2(int)’: g++.dg/gomp/loop-1.C:158:3: error: initializer expression refers to iteration variable ‘i’ for (int i = i; i < 16; i++) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:161:18: error: initializer expression refers to iteration variable ‘i’ for (int i = 2 * (i & x); i < 16; i++) /* { dg-error "initializer expression refers to iteration variable" } */ ~~^~~~~~~~~ g++.dg/gomp/loop-1.C:164:3: error: initializer expression refers to iteration variable ‘i’ for (int i = bar (i); i < 16; i++) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:167:3: error: initializer expression refers to iteration variable ‘i’ for (int i = baz (&i); i < 16; i++) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:170:21: error: condition expression refers to iteration variable ‘i’ for (int i = 5; i < 2 * i + 17; i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~~~~~~ g++.dg/gomp/loop-1.C:173:30: error: condition expression refers to iteration variable ‘i’ for (int i = 5; 2 * i + 17 > i; i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~~~~~~~~~~^~~ g++.dg/gomp/loop-1.C:176:27: error: condition expression refers to iteration variable ‘i’ for (int i = 5; bar (i) > i; i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~~~~~~~^~~ g++.dg/gomp/loop-1.C:179:21: error: condition expression refers to iteration variable ‘i’ for (int i = 5; i <= baz (&i); i++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~~~~~ g++.dg/gomp/loop-1.C:182:21: error: condition expression refers to iteration variable ‘i’ for (int i = 5; i <= i; i++) /* { dg-error "invalid controlling predicate|condition expression refers to iteration variable" } */ ~~^~~~ g++.dg/gomp/loop-1.C:185:3: error: increment expression refers to iteration variable ‘i’ for (int i = 5; i < 16; i += i) /* { dg-error "increment expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:188:37: error: increment expression refers to iteration variable ‘i’ for (int i = 5; i < 16; i = i + 2 * i) /* { dg-error "invalid increment expression|increment expression refers to iteration variable" } */ ~~^~~ g++.dg/gomp/loop-1.C:191:3: error: increment expression refers to iteration variable ‘i’ for (int i = 5; i < 16; i = i + i) /* { dg-error "increment expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:194:39: error: increment expression refers to iteration variable ‘i’ for (int i = 5; i < 16; i = i + bar (i)) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~ g++.dg/gomp/loop-1.C:197:35: error: increment expression refers to iteration variable ‘i’ for (int i = 5; i < 16; i = baz (&i) + i) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~~ g++.dg/gomp/loop-1.C:200:36: error: increment expression refers to iteration variable ‘i’ for (int i = 5; i < 16; i += bar (i)) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~ g++.dg/gomp/loop-1.C:203:36: error: increment expression refers to iteration variable ‘i’ for (int i = 5; i < 16; i += baz (&i)) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~~ g++.dg/gomp/loop-1.C:210:3: error: initializer expression refers to iteration variable ‘i’ for (int i = 0; i < 16; i = i + 2) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:215:20: error: initializer expression refers to iteration variable ‘i’ for (int j = i + 3; j < 16; j += 2) /* { dg-error "initializer expression refers to iteration variable" } */ ~~^~~ g++.dg/gomp/loop-1.C:218:3: error: initializer expression refers to iteration variable ‘i’ for (int i = 0; i < 16; i++) /* { dg-error "initializer expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:223:24: error: condition expression refers to iteration variable ‘i’ for (int j = 16; j > (i & x); j--) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~~~ g++.dg/gomp/loop-1.C:227:23: error: condition expression refers to iteration variable ‘i’ for (int j = 0; j < i; j++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~ g++.dg/gomp/loop-1.C:231:23: error: condition expression refers to iteration variable ‘i’ for (int j = 0; j < i + 4; j++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~ g++.dg/gomp/loop-1.C:235:23: error: condition expression refers to iteration variable ‘i’ for (int j = 0; j < baz (&i); j++) /* { dg-error "condition expression refers to iteration variable" } */ ~~^~~~~~~~~~ g++.dg/gomp/loop-1.C:238:3: error: increment expression refers to iteration variable ‘i’ for (int i = 0; i < 16; i++) /* { dg-error "increment expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:242:3: error: increment expression refers to iteration variable ‘i’ for (int i = 0; i < 16; i++) /* { dg-error "increment expression refers to iteration variable" } */ ^~~ g++.dg/gomp/loop-1.C:247:41: error: increment expression refers to iteration variable ‘i’ for (int j = 0; j < 16; j = j + baz (&i)) /* { dg-error "increment expression refers to iteration variable" } */ ~~~~^~~~ gcc/cp/ChangeLog: * parser.c (cp_parser_omp_for_cond): Attempt to use the location of "cond" for the binary op. gcc/testsuite/ChangeLog: * g++.dg/gomp/loop-1.C: Update dg-error locations. --- gcc/cp/parser.c | 3 ++- gcc/testsuite/g++.dg/gomp/loop-1.C | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index f3d406e..284dadd0 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -32843,7 +32843,8 @@ cp_parser_omp_for_cond (cp_parser *parser, tree decl, enum tree_code code) || CLASS_TYPE_P (TREE_TYPE (decl)))) return cond; - return build_x_binary_op (input_location, TREE_CODE (cond), + return build_x_binary_op (EXPR_LOC_OR_LOC (cond, input_location), + TREE_CODE (cond), TREE_OPERAND (cond, 0), ERROR_MARK, TREE_OPERAND (cond, 1), ERROR_MARK, /*overload=*/NULL, tf_warning_or_error); diff --git a/gcc/testsuite/g++.dg/gomp/loop-1.C b/gcc/testsuite/g++.dg/gomp/loop-1.C index 46e707f..de08eb3 100644 --- a/gcc/testsuite/g++.dg/gomp/loop-1.C +++ b/gcc/testsuite/g++.dg/gomp/loop-1.C @@ -86,16 +86,16 @@ f1 (int x) for (j = baz (&i); j < 16; j += 2) ; #pragma omp for collapse(2) - for (i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (j = 16; j > (i & x); j--) + for (i = 0; i < 16; i++) + for (j = 16; j > (i & x); j--) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (j = 0; j < i; j++) + for (i = 0; i < 16; i++) + for (j = 0; j < i; j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (j = 0; j < i + 4; j++) + for (i = 0; i < 16; i++) + for (j = 0; j < i + 4; j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) for (i = 0; i < j + 4; i++) /* { dg-error "condition expression refers to iteration variable" } */ @@ -110,8 +110,8 @@ f1 (int x) for (j = 0; j < 16; j++) ; #pragma omp for collapse(2) - for (i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (j = 0; j < baz (&i); j++) + for (i = 0; i < 16; i++) + for (j = 0; j < baz (&i); j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) for (i = 0; i < 16; i += j) /* { dg-error "increment expression refers to iteration variable" } */ @@ -219,20 +219,20 @@ f2 (int x) for (int j = baz (&i); j < 16; j += 2) ; #pragma omp for collapse(2) - for (int i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (int j = 16; j > (i & x); j--) + for (int i = 0; i < 16; i++) + for (int j = 16; j > (i & x); j--) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (int i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (int j = 0; j < i; j++) + for (int i = 0; i < 16; i++) + for (int j = 0; j < i; j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (int i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (int j = 0; j < i + 4; j++) + for (int i = 0; i < 16; i++) + for (int j = 0; j < i + 4; j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (int i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (int j = 0; j < baz (&i); j++) + for (int i = 0; i < 16; i++) + for (int j = 0; j < baz (&i); j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) for (int i = 0; i < 16; i++) /* { dg-error "increment expression refers to iteration variable" } */ -- 1.8.5.3