OSDN Git Service

PR preprocessor/48532
authordodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 Jun 2011 11:33:42 +0000 (11:33 +0000)
committerdodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 Jun 2011 11:33:42 +0000 (11:33 +0000)
libcpp/

* directives.c (do_pragma): Don't forget the invocation location
when parsing the pragma name of a namespaced pragma directive.

gcc/testsuite/

* gcc.dg/cpp/pragma-3.c: New test case.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@174694 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/gcc.dg/cpp/pragma-3.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/directives.c

diff --git a/gcc/testsuite/gcc.dg/cpp/pragma-3.c b/gcc/testsuite/gcc.dg/cpp/pragma-3.c
new file mode 100644 (file)
index 0000000..9afc391
--- /dev/null
@@ -0,0 +1,39 @@
+/* 
+   { dg-options "-fopenmp" }
+   { dg-do preprocess }
+ */
+
+void foo (void)
+{
+  int i1, j1, k1;
+#define p parallel
+#define P(x) private (x##1)
+#define S(x) shared (x##1)
+#define F(x) firstprivate (x##1)
+#pragma omp \
+  p \
+  P(i) \
+  S(j) \
+  F(k)
+  ;
+}
+
+/* 
+   The bug here was that we had a line like:
+       # 33554432 "../../gcc/testsuite/gcc.dg/cpp/pragma-3.c"
+   
+   Before line:
+
+       #pragma omp parallel private (i1) shared (j1) firstprivate (k1)
+
+   Note the very big integer there.  Normally we should just have
+   this:
+   
+       # 13 "../../gcc/testsuite/gcc.dg/cpp/pragma-3.c"
+       #pragma omp parallel private (i1) shared (j1) firstprivate (k1)
+
+   So let's check that we have no line with a number of 3 or more
+   digit after #:
+
+   { dg-final { scan-file-not pragma-3.i "# \[0-9\]{3} \[^\n\r\]*pragma-3.c" } }
+*/
index 485d66e..e1c01c1 100644 (file)
@@ -1,3 +1,9 @@
+2011-06-06  Dodji Seketeli  <dodji@redhat.com>
+
+       PR preprocessor/48532
+       * directives.c (do_pragma): Don't forget the invocation location
+       when parsing the pragma name of a namespaced pragma directive.
+
 2011-05-29  John Tytgat  <John.Tytgat@aaug.net>
 
        * files.c (read_file_guts): Add test on non-zero value of S_ISREG.
 2011-05-29  John Tytgat  <John.Tytgat@aaug.net>
 
        * files.c (read_file_guts): Add test on non-zero value of S_ISREG.
index f244ae5..85e941e 100644 (file)
@@ -1360,7 +1360,36 @@ do_pragma (cpp_reader *pfile)
        {
          bool allow_name_expansion = p->allow_expansion;
          if (allow_name_expansion)
        {
          bool allow_name_expansion = p->allow_expansion;
          if (allow_name_expansion)
-           pfile->state.prevent_expansion--;
+           {
+             pfile->state.prevent_expansion--;
+             /*
+               Kludge ahead.
+
+               Consider this code snippet:
+
+               #define P parallel
+               #pragma omp P for
+               ... a for loop ...
+
+               Once we parsed the 'omp' namespace of the #pragma
+               directive, we then parse the 'P' token that represents the
+               pragma name.  P being a macro, it is expanded into the
+               resulting 'parallel' token.
+
+               At this point the 'p' variable contains the 'parallel'
+               pragma name.  And pfile->context->macro is non-null
+               because we are still right at the end of the macro
+               context of 'P'.  The problem is, if we are being
+               (indirectly) called by cpp_get_token_with_location,
+               that function might test pfile->context->macro to see
+               if we are in the context of a macro expansion, (and we
+               are) and then use pfile->invocation_location as the
+               location of the macro invocation.  So we must instruct
+               cpp_get_token below to set
+               pfile->invocation_location.  */
+             pfile->set_invocation_location = true;
+           }
+
          token = cpp_get_token (pfile);
          if (token->type == CPP_NAME)
            p = lookup_pragma_entry (p->u.space, token->val.node.node);
          token = cpp_get_token (pfile);
          if (token->type == CPP_NAME)
            p = lookup_pragma_entry (p->u.space, token->val.node.node);