aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Booth <NeilB@earthling.net>2000-07-04 22:26:16 +0000
committerNeil Booth <NeilB@earthling.net>2000-07-04 22:26:16 +0000
commit49fdf5a36241b7c1e8a603f4a857b0e50d91ba4e (patch)
tree817777257373fdb5986b614252de7d6ef1b8ad5b
parente157517dc1ad14b9afe253ee1897adb6c2acee3b (diff)
* cpplex.c: Fix trigraph replacement within strings.
* gcc.dg/cpp/lexident.c, gcc.dg/cpp/lexnum.c, gcc.dg/cpp/lexstrng.c: New tests. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@34868 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog4
-rw-r--r--gcc/cpplex.c2
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/cpp/lexident.c25
-rw-r--r--gcc/testsuite/gcc.dg/cpp/lexnum.c50
-rw-r--r--gcc/testsuite/gcc.dg/cpp/lexstrng.c69
6 files changed, 154 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 074c22649fc..df412c1efa8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index a45336d1158..b0fba653a61 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -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;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2824980484e..6b233fc675e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 00000000000..c914023b0fd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/lexident.c
@@ -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
index 00000000000..7df15540833
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/lexnum.c
@@ -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
index 00000000000..4fbb3b555eb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/lexstrng.c
@@ -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;
+}