gcc/libgomp/testsuite/libgomp.oacc-c-c++-common/vred2d-128.c
Lewis Hyatt 0587cef3d7 c: Fix location for _Pragma tokens [PR97498]
The handling of #pragma GCC diagnostic uses input_location, which is not always
as precise as needed; in particular the relative location of some tokens and a
_Pragma directive will crucially determine whether a given diagnostic is enabled
or suppressed in the desired way. PR97498 shows how the C frontend ends up with
input_location pointing to the beginning of the line containing a _Pragma()
directive, resulting in the wrong behavior if the diagnostic to be modified
pertains to some tokens found earlier on the same line. This patch fixes that by
addressing two issues:

    a) libcpp was not assigning a valid location to the CPP_PRAGMA token
    generated by the _Pragma directive.
    b) C frontend was not setting input_location to something reasonable.

With this change, the C frontend is able to change input_location to point to
the _Pragma token as needed.

This is just a two-line fix (one for each of a) and b)), the testsuite changes
were needed only because the location on the tested warnings has been somewhat
improved, so the tests need to look for the new locations.

gcc/c/ChangeLog:

	PR preprocessor/97498
	* c-parser.cc (c_parser_pragma): Set input_location to the
	location of the pragma, rather than the start of the line.

libcpp/ChangeLog:

	PR preprocessor/97498
	* directives.cc (destringize_and_run): Override the location of
	the CPP_PRAGMA token from a _Pragma directive to the location of
	the expansion point, as is done for the tokens lexed from it.

gcc/testsuite/ChangeLog:

	PR preprocessor/97498
	* c-c++-common/pr97498.c: New test.
	* c-c++-common/gomp/pragma-3.c: Adapt for improved warning locations.
	* c-c++-common/gomp/pragma-5.c: Likewise.
	* gcc.dg/pragma-message.c: Likewise.

libgomp/ChangeLog:

	* testsuite/libgomp.oacc-c-c++-common/reduction-5.c: Adapt for
	improved warning locations.
	* testsuite/libgomp.oacc-c-c++-common/vred2d-128.c: Likewise.
2022-07-10 16:50:03 -04:00

95 lines
3.8 KiB
C

/* Test large vector lengths. */
/* { dg-additional-options "-DEXPENSIVE" { target run_expensive_tests } } */
/* { dg-additional-options -Wuninitialized } */
#include <assert.h>
#ifdef EXPENSIVE
#define n 10000
#else
#define n 2500
#endif
int a1[n], a2[n];
#define gentest(name, outer, inner) \
void name () \
{ \
long i, j, t1, t2, t3; /* { dg-line vars } */ \
_Pragma(outer) /* { dg-line outer } */ \
for (i = 0; i < n; i++) \
{ \
t1 = 0; \
t2 = 0; \
_Pragma(inner) \
for (j = i; j < n; j++) \
{ \
t1++; \
t2--; \
} \
a1[i] = t1; \
a2[i] = t2; \
} \
for (i = 0; i < n; i++) \
{ \
assert (a1[i] == n-i); \
assert (a2[i] == -(n-i)); \
} \
} \
gentest (test1, "acc parallel loop gang vector_length (128) firstprivate (t1, t2)",
"acc loop vector reduction(+:t1) reduction(-:t2)")
/* { dg-warning {'t1' is used uninitialized} {} { target *-*-* } outer }
{ dg-note {'t1' was declared here} {} { target *-*-* } vars }
{ dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-4 }
TODO See PR101551 for 'offloading_enabled' differences. */
/* { dg-warning {'t2' is used uninitialized} {} { target *-*-* } outer }
{ dg-note {'t2' was declared here} {} { target *-*-* } vars }
{ DUP_dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-8 }
TODO See PR101551 for 'offloading_enabled' differences. */
gentest (test2, "acc parallel loop gang vector_length (128) firstprivate (t1, t2)",
"acc loop worker vector reduction(+:t1) reduction(-:t2)")
/* { DUPdg-warning {'t1' is used uninitialized} {} { target *-*-* } outer }
{ DUP_dg-note {'t1' was declared here} {} { target *-*-* } vars }
{ dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-4 }
TODO See PR101551 for 'offloading_enabled' differences. */
/* { DUPdg-warning {'t2' is used uninitialized} {} { target *-*-* } outer }
{ DUP_dg-note {'t2' was declared here} {} { target *-*-* } vars }
{ DUP_dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-8 }
TODO See PR101551 for 'offloading_enabled' differences. */
gentest (test3, "acc parallel loop gang worker vector_length (128) firstprivate (t1, t2)",
"acc loop vector reduction(+:t1) reduction(-:t2)")
/* { DUPdg-warning {'t1' is used uninitialized} {} { target *-*-* } outer }
{ DUP_dg-note {'t1' was declared here} {} { target *-*-* } vars }
{ dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-4 }
TODO See PR101551 for 'offloading_enabled' differences. */
/* { DUPdg-warning {'t2' is used uninitialized} {} { target *-*-* } outer }
{ DUP_dg-note {'t2' was declared here} {} { target *-*-* } vars }
{ DUP_dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-8 }
TODO See PR101551 for 'offloading_enabled' differences. */
gentest (test4, "acc parallel loop firstprivate (t1, t2)",
"acc loop reduction(+:t1) reduction(-:t2)")
/* { DUPdg-warning {'t1' is used uninitialized} {} { target *-*-* } outer }
{ DUP_dg-note {'t1' was declared here} {} { target *-*-* } vars }
{ dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-4 }
TODO See PR101551 for 'offloading_enabled' differences. */
/* { DUPdg-warning {'t2' is used uninitialized} {} { target *-*-* } outer }
{ DUP_dg-note {'t2' was declared here} {} { target *-*-* } vars }
{ DUP_dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-8 }
TODO See PR101551 for 'offloading_enabled' differences. */
int
main ()
{
test1 ();
test2 ();
test3 ();
test4 ();
return 0;
}