]> gcc.gnu.org Git - gcc.git/commitdiff
cpplex.c: Fix trigraph replacement within strings.
authorNeil Booth <neilb@earthling.net>
Tue, 4 Jul 2000 22:26:16 +0000 (22:26 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Tue, 4 Jul 2000 22:26:16 +0000 (22:26 +0000)
* cpplex.c: Fix trigraph replacement within strings.
* gcc.dg/cpp/lexident.c, gcc.dg/cpp/lexnum.c,
  gcc.dg/cpp/lexstrng.c: New tests.

From-SVN: r34868

gcc/ChangeLog
gcc/cpplex.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/lexident.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/lexnum.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/lexstrng.c [new file with mode: 0644]

index 074c22649fc34164dd205a6c21054eb816eb73a8..df412c1efa827916f23e35ae12ecaf939bdd4a9f 100644 (file)
@@ -1,3 +1,7 @@
+2000-07-05  Neil Booth  <NeilB@earthling.net>
+
+       * cpplex.c: Fix trigraph replacement within strings.
+
 2000-07-04  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * rs6000/aix.h (ASM_GENERATE_INTERNAL_LABEL): Fix format specifier.
index a45336d1158db26806ef2a0ee1b60bdf598b8764..b0fba653a613fbaa99a478418b2852e1e649576f 100644 (file)
@@ -853,7 +853,7 @@ trigraph_replace (pfile, src, limit)
   /* Starting with src[1], find two consecutive '?'.  The case of no
      trigraphs is streamlined.  */
   
-  for (; src + 1 < limit; src += 2)
+  for (src++; src + 1 < limit; src += 2)
     {
       if (src[0] != '?')
        continue;
index 2824980484e6747526dfaf03a2da5d316c0688cf..6b233fc675e8e04ac868cdb529f4a21f1a0285ae 100644 (file)
@@ -1,3 +1,8 @@
+2000-07-05  Neil Booth  <NeilB@earthling.net>
+
+       * gcc.dg/cpp/lexident.c, gcc.dg/cpp/lexnum.c,
+         gcc.dg/cpp/lexstrng.c: New tests.
+
 2000-07-04  Neil Booth  <NeilB@earthling.net>
 
        * gcc.dg/cpp/macro1.c: Add more macro expansion tests.
diff --git a/gcc/testsuite/gcc.dg/cpp/lexident.c b/gcc/testsuite/gcc.dg/cpp/lexident.c
new file mode 100644 (file)
index 0000000..c914023
--- /dev/null
@@ -0,0 +1,25 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+
+/* { dg-do preprocess } */
+/* { dg-options "-trigraphs" } */
+
+/* Test lexing of identifiers.  */
+
+/* Escaped newlines, _ and $ in identifiers.  */
+#def\
+\
+ine foo_
+
+#d\
+ef??/
+in\
+e b\
+a$r
+
+#ifndef foo_
+#error foo_
+#endif
+
+#ifndef ba$r
+#error ba$r
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/lexnum.c b/gcc/testsuite/gcc.dg/cpp/lexnum.c
new file mode 100644 (file)
index 0000000..7df1554
--- /dev/null
@@ -0,0 +1,50 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+
+/* { dg-do run } */
+/* { dg-options "-trigraphs" } */
+
+/* Test lexing of numbers.  */
+
+extern int puts (const char *);
+extern void abort (void);
+#define err(str) do { puts(str); abort(); } while (0)
+
+/* Escaped newlines.  */
+#define foo 12\
+3\
+\
+4??/
+5
+
+#if foo != 12345
+#error foo
+#endif
+
+int main (int argc, char *argv[])
+{
+  double a = 5.;
+  double x = .5;
+
+/* Decimal points, including initially and immediately before and
+   after an escaped newline.  */
+  if (a != 5)
+    err ("a");
+  if (x != .\
+5)
+    err ("x != .5");
+  x = 25\
+.\
+6;
+  if (x != 25.6)
+    err ("x != 25.6");
+
+  /* Test exponentials and their signs.  A buggy lexer is more likely
+     to fail the compile, but never mind.  */
+  if (250 != 25e+1 || 250 != 25e1 || 250 != 2500e-1)
+    err ("exponentials");
+
+  /* Todo: p exponentials, and how to test preprocessing number
+     tokenisation?  */
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/lexstrng.c b/gcc/testsuite/gcc.dg/cpp/lexstrng.c
new file mode 100644 (file)
index 0000000..4fbb3b5
--- /dev/null
@@ -0,0 +1,69 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+
+/* { dg-do run } */
+/* { dg-options "-trigraphs" } */
+
+/* Test lexing of strings and character constants.  */
+
+#include <string.h>
+
+#ifndef __WCHAR_TYPE__
+#define __WCHAR_TYPE__ int
+#endif
+typedef __WCHAR_TYPE__ wchar_t;
+
+extern int strcmp (const char *, const char *);
+extern int puts (const char *);
+extern void abort (void);
+#define err(str) do { puts(str); abort(); } while (0)
+
+/* Escaped newlines.  */
+const char *str1 = "s\
+t\
+\
+r??/
+  1";
+
+const char x = '\
+??/
+b';
+
+/* Test escaped terminators.  */
+const char *term = "\"\\\"\\";
+const char termc = '\'';
+const char *terms = "'";
+
+/* Test wide strings and chars are lexed.  */
+const wchar_t wchar = L'w';
+const wchar_t* wstring = L"wide string";
+
+/* Test all 9 trigraphs embedded in a string.  Test trigraphs do not
+   survive an embedded backslash newline.  Test trigraphs preceded by
+   a '?' are still noticed.  */
+const char *t = "??/\??<??>??=??)??\
+(??(??!??'??-???=???/
+?-";
+
+int main (int argc, char *argv[])
+{
+  if (strcmp (str1, "str  1"))
+    err ("str1");
+
+  if (x != 'b')
+    err ("b");
+
+  /* We have to split the string up to avoid trigraph replacement
+     here.  Split the 2 trigraphs after both 1 and 2 ?s; just doing
+     this exposed a bug in the initial release of the tokenized lexer.  */
+  if (strcmp (t, "\\{}#]?" "?([|^~?#??" "-"))
+    err ("Embedded trigraphs");
+
+  if (term[0] != '"' || term[1] != '\\' || term[2] != '"'
+      || term[3] != '\\' || term[4] != '\0')
+    err ("Escaped string terminators");
+
+  if (termc != terms[0])
+    err ("Escaped character constant terminator");
+
+  return 0;
+}
This page took 0.09339 seconds and 5 git commands to generate.