From: Andrew Pinski <apin...@marvell.com>

Hi,
  The problem here is the token->val.node is not saved over
a precompiled header for C++ operator.  This can cause an
internal compiler error as we tried to print out the spelling
of the token as we assumed it was valid.
The fix is to have cpp_token_val_index return CPP_TOKEN_FLD_NODE
for operator tokens that have NAMED_OP set.

OK?  Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

libcpp/ChangeLog:
* lex.c (cpp_token_val_index <case SPELL_OPERATOR>): If tok->flags
has NAMED_OP set, then return CPP_TOKEN_FLD_NODE.

gcc/testsuite/ChangeLog:
* g++.dg/pch/operator-1.C: New testcase.
* g++.dg/pch/operator-1.Hs: New file.
---
 gcc/testsuite/g++.dg/pch/operator-1.C  | 2 ++
 gcc/testsuite/g++.dg/pch/operator-1.Hs | 9 +++++++++
 libcpp/lex.c                           | 6 +++++-
 3 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/pch/operator-1.C
 create mode 100644 gcc/testsuite/g++.dg/pch/operator-1.Hs

diff --git a/gcc/testsuite/g++.dg/pch/operator-1.C 
b/gcc/testsuite/g++.dg/pch/operator-1.C
new file mode 100644
index 0000000..290b5f7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pch/operator-1.C
@@ -0,0 +1,2 @@
+#include "operator-1.H"
+int main(void){ major(0);} /* { dg-warning "Did not Work" } */
diff --git a/gcc/testsuite/g++.dg/pch/operator-1.Hs 
b/gcc/testsuite/g++.dg/pch/operator-1.Hs
new file mode 100644
index 0000000..657dae1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pch/operator-1.Hs
@@ -0,0 +1,9 @@
+# define __glibc_macro_warning1(message) _Pragma (#message)
+# define __glibc_macro_warning(message) \
+  __glibc_macro_warning1 (GCC warning message)
+#define __SYSMACROS_DM1(...) __glibc_macro_warning (#__VA_ARGS__)
+
+#define __SYSMACROS_DM(symbol) __SYSMACROS_DM1 \
+ (Did not Work)
+
+# define major(dev) __SYSMACROS_DM (major) (dev+0)
diff --git a/libcpp/lex.c b/libcpp/lex.c
index eedfcbb..16ded6e 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -3756,7 +3756,11 @@ cpp_token_val_index (const cpp_token *tok)
     case SPELL_LITERAL:
       return CPP_TOKEN_FLD_STR;
     case SPELL_OPERATOR:
-      if (tok->type == CPP_PASTE)
+      /* Operands which were originally spelled as ident keep around
+         the node for the exact spelling.  */
+      if (tok->flags & NAMED_OP)
+       return CPP_TOKEN_FLD_NODE;
+      else if (tok->type == CPP_PASTE)
        return CPP_TOKEN_FLD_TOKEN_NO;
       else
        return CPP_TOKEN_FLD_NONE;
-- 
1.8.3.1

Reply via email to