diff options
author | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-06-21 05:29:09 +0000 |
---|---|---|
committer | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-06-21 05:29:09 +0000 |
commit | aacf5b8e48d4c91854942d48956c8188f7d90a1f (patch) | |
tree | 2ae1e294673a6d1f03b6b44a932a43d5d3aa422b | |
parent | 581084df8a465d80b9a3387f5121f5727044e5e5 (diff) | |
download | gcc-aacf5b8e48d4c91854942d48956c8188f7d90a1f.tar.gz |
* cpperror.c (cpp_error): For traditional CPP, default to
diagnostics on pfile->line.
* cpplib.c (prepare_directive_trad): Set line number for
diagnostics for #define too.
* cpptrad.c (skip_whitespace): Skip comments properly.
(_cpp_expansions_different_trad): Initialize quote2.
testsuite:
* gcc.dg/cpp/trad: New directory with traditional tests copied
from parent directory.
* gcc.dg/cpp/assert_trad1.c, gcc.dg/cpp/assert_trad2.c,
gcc.dg/cpp/assert_trad3.c, gcc.dg/cpp/defined_trad.c,
gcc.dg/cpp/hash2.c, gcc.dg/cpp/tr-define.c, gcc.dg/cpp/tr-direct.c,
gcc.dg/cpp/tr-sign.c, gcc.dg/cpp/tr-str.c, gcc.dg/cpp/uchar-2.c:
Move to trad/ and rename.
* gcc.dg/cpp/trad/__STDC__.c, gcc.dg/cpp/trad/comment.c,
gcc.dg/cpp/trad/escaped-eof.c, gcc.dg/cpp/trad/redef1.c,
gcc.dg/cpp/trad/redef2.c: New tests.
* gcc.dg/cpp/trad/trad.exp: New driver.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@54870 138bc75d-0d04-0410-961f-82ee72b054a4
22 files changed, 407 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c037fcbcac8..670e0f8ad36 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2002-06-21 Neil Booth <neil@daikokuya.co.uk> + + * cpperror.c (cpp_error): For traditional CPP, default to + diagnostics on pfile->line. + * cpplib.c (prepare_directive_trad): Set line number for + diagnostics for #define too. + * cpptrad.c (skip_whitespace): Skip comments properly. + (_cpp_expansions_different_trad): Initialize quote2. + 2002-06-21 Hans-Peter Nilsson <hp@bitrange.com> * config/mmix/mmix.md: Change GNU CC to GCC in file header comment. diff --git a/gcc/cpperror.c b/gcc/cpperror.c index 6603a20710c..0e3b0b631f0 100644 --- a/gcc/cpperror.c +++ b/gcc/cpperror.c @@ -137,8 +137,16 @@ cpp_error VPARAMS ((cpp_reader * pfile, int level, const char *msgid, ...)) if (pfile->buffer) { - line = pfile->cur_token[-1].line; - column = pfile->cur_token[-1].col; + if (CPP_OPTION (pfile, traditional)) + { + line = pfile->line; + column = 0; + } + else + { + line = pfile->cur_token[-1].line; + column = pfile->cur_token[-1].col; + } } else line = column = 0; diff --git a/gcc/cpplib.c b/gcc/cpplib.c index d3c95e75c86..59e2fe6709a 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -303,10 +303,11 @@ prepare_directive_trad (pfile) pfile->state.skipping = was_skipping; _cpp_overlay_buffer (pfile, pfile->out.base, pfile->out.cur - pfile->out.base); - /* Report diagnostics on the line of the directive. */ - pfile->line = pfile->directive_line; } + /* Report diagnostics on the line of the directive. */ + pfile->line = pfile->directive_line; + /* Stop ISO C from expanding anything. */ pfile->state.prevent_expansion++; } diff --git a/gcc/cpptrad.c b/gcc/cpptrad.c index 74976dbe231..b3413d031f0 100644 --- a/gcc/cpptrad.c +++ b/gcc/cpptrad.c @@ -266,7 +266,7 @@ skip_whitespace (pfile, cur, skip_comments) if (!c && cur - 1 != RLIMIT (pfile->context)) continue; - if (*cur == '/' && skip_comments) + if (c == '/' && skip_comments) { const uchar *tmp = skip_escaped_newlines (pfile, cur); if (*tmp == '*') @@ -1118,7 +1118,7 @@ _cpp_expansions_different_trad (macro1, macro2) { uchar *p1 = xmalloc (macro1->count + macro2->count); uchar *p2 = p1 + macro1->count; - uchar quote1 = 0, quote2; + uchar quote1 = 0, quote2 = 0; bool mismatch; size_t len1, len2; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 498e67171a5..75b2189769a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2002-06-21 Neil Booth <neil@daikokuya.co.uk> + + * gcc.dg/cpp/trad: New directory with traditional tests copied + from parent directory. + * gcc.dg/cpp/assert_trad1.c, gcc.dg/cpp/assert_trad2.c, + gcc.dg/cpp/assert_trad3.c, gcc.dg/cpp/defined_trad.c, + gcc.dg/cpp/hash2.c, gcc.dg/cpp/tr-define.c, gcc.dg/cpp/tr-direct.c, + gcc.dg/cpp/tr-sign.c, gcc.dg/cpp/tr-str.c, gcc.dg/cpp/uchar-2.c: + Move to trad/ and rename. + * gcc.dg/cpp/trad/__STDC__.c, gcc.dg/cpp/trad/comment.c, + gcc.dg/cpp/trad/escaped-eof.c, gcc.dg/cpp/trad/redef1.c, + gcc.dg/cpp/trad/redef2.c: New tests. + * gcc.dg/cpp/trad/trad.exp: New driver. + 2002-06-20 Neil Booth <neil@daikokuya.co.uk> * gcc.dg/cpp/assert_trad1.c, gcc.dg/cpp/assert_trad2.c, diff --git a/gcc/testsuite/gcc.dg/cpp/trad/__STDC__.c b/gcc/testsuite/gcc.dg/cpp/trad/__STDC__.c new file mode 100644 index 00000000000..b25bcb9aa76 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/__STDC__.c @@ -0,0 +1,7 @@ +/* Test that __STDC__ is not defined. */ + +/* { dg-do preprocess } */ + +#if defined __STDC__ +# error __STDC__ defined /* { dg-bogus "__STDC__" "__STDC__ defined" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/cpp/trad/assert1.c b/gcc/testsuite/gcc.dg/cpp/trad/assert1.c new file mode 100644 index 00000000000..ff7cc620bec --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/assert1.c @@ -0,0 +1,46 @@ +/* Basic tests of the #assert preprocessor extension. */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +#define def unused expansion +#define fail int fail + +#assert abc (def) +#assert abc (ghi) +#assert abc (jkl) +#assert space ( s p a c e ) + +/* Basic: */ +#if !#abc (def) || !#abc (ghi) || !#abc (jkl) +fail +#endif + +/* any answer for #abc */ +#if !#abc +fail +#endif + +/* internal whitespace is collapsed, + external whitespace is deleted */ +#if !#space (s p a c e) || !#space ( s p a c e ) || #space (space) +fail +#endif + +/* removing assertions */ +#unassert abc (jkl) +#if !#abc || !#abc (def) || !#abc (ghi) || #abc (jkl) +fail +#endif + +#unassert abc +#if #abc || #abc (def) || #abc (ghi) || #abc (jkl) +fail +#endif + +int gobble + +/* make sure it can succeed too. + also check space before open paren isn't significant */ +#if #space(s p a c e) +; +#endif diff --git a/gcc/testsuite/gcc.dg/cpp/trad/assert2.c b/gcc/testsuite/gcc.dg/cpp/trad/assert2.c new file mode 100644 index 00000000000..9838e149cbf --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/assert2.c @@ -0,0 +1,23 @@ +/* Malformed assertion tests. */ +/* { dg-do preprocess } */ + +#assert /* { dg-error "without predicate" "assert w/o predicate" } */ +#assert % /* { dg-error "an identifier" "assert punctuation" } */ +#assert 12 /* { dg-error "an identifier" "assert number" } */ +#assert abc /* { dg-error "missing" "assert w/o answer" } */ + +#if # /* { dg-error "without predicate" "test w/o predicate" } */ +#endif + +#if #% /* { dg-error "an identifier" "test punctuation" } */ +#endif + +#if #12 /* { dg-error "an identifier" "test number" } */ +#endif + +#if #abc +#error /* { dg-bogus "error" "test w/o answer" } */ +#endif + +#if #abc[def] /* { dg-error "not valid in" "bad syntax" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/cpp/trad/assert3.c b/gcc/testsuite/gcc.dg/cpp/trad/assert3.c new file mode 100644 index 00000000000..df9b19fdaf9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/assert3.c @@ -0,0 +1,10 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ +/* { dg-options "-A abc=def -A abc\(ghi\) \"-Aabc = jkl\" -A abc=mno -A -abc=mno" } */ + +/* Test -A command line syntax. Source Neil Booth. 31 Oct 2000. */ + +#if !#abc (def) || !#abc (ghi) || !#abc (jkl) || #abc(mno) +#error Command line -A assertions +#endif diff --git a/gcc/testsuite/gcc.dg/cpp/trad/comment.c b/gcc/testsuite/gcc.dg/cpp/trad/comment.c new file mode 100644 index 00000000000..ce9d7f18e1c --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/comment.c @@ -0,0 +1,5 @@ +/* Test for warning of unterminated comment. */ + +/* { dg-do preprocess } */ + +/* { dg-warning "unterminated comment" } diff --git a/gcc/testsuite/gcc.dg/cpp/trad/define.c b/gcc/testsuite/gcc.dg/cpp/trad/define.c new file mode 100644 index 00000000000..d83288df23e --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/define.c @@ -0,0 +1,2 @@ +/* { dg-do preprocess } */ +/* { dg-options "-traditional-cpp -DDEFINE1DEFINE -DDEFINE2DEFIN=" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/trad/defined.c b/gcc/testsuite/gcc.dg/cpp/trad/defined.c new file mode 100644 index 00000000000..a24ecd519ea --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/defined.c @@ -0,0 +1,78 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ + +/* Tests tradcpp0 with defined. The defined operator in traditional C + works just the same as the defined operator in Standard C. */ + +/* Source: Zack Weinberg, glibc, Neil Booth 11 Dec 2000. */ + +#if defined REGPARMS +#error REGPARMS should not be defined +#endif + +#define REGPARMS 1 +#if !defined REGPARMS +#error REGPARMS should be defined +#endif + +#define defined /* { dg-error "defined" } */ + +/* No diagnostics, though you could argue there should be. */ +#if defined defined +#error defined is defined! +#endif + +#define is_Z_defined defined Z + +#if defined Z +#error Z is not defined +#endif + +/* The behaviour of "defined" when it comes from a macro expansion is + now documented. */ +#if is_Z_defined +#error Macro expanding into defined operator test 1 +#endif + +#define Z + +#if !defined Z +#error Z is defined +#endif + +#if !is_Z_defined +#error Macro expanding into defined operator test 2 +#endif + +#undef is_Z_defined +#undef Z + +/* Do all the tests over again with the () form of defined. */ + +/* No diagnostics, though you could argue there should be. */ +#if defined(defined) +#error defined is defined! +#endif + +#define is_Z_defined defined ( Z ) + +#if defined(Z) +#error Z is not defined +#endif + +/* The behaviour of "defined" when it comes from a macro expansion is + now documented. */ +#if is_Z_defined +#error Macro expanding into defined operator test 1 +#endif + +#define Z + +#if !defined(Z) +#error Z is defined +#endif + +#if !is_Z_defined +#error Macro expanding into defined operator test 2 +#endif diff --git a/gcc/testsuite/gcc.dg/cpp/trad/directive.c b/gcc/testsuite/gcc.dg/cpp/trad/directive.c new file mode 100644 index 00000000000..186cb30bbed --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/directive.c @@ -0,0 +1,10 @@ +/* Test for some basic aspects of -traditional directive processing. */ + +/* { dg-do preprocess } */ + +/* There is a #error directive. */ + +#error bad /* { dg-error "bad" } */ + +/* Directives with their #s indented are not recognized. */ + #if 0 /* { dg-bogus "unterminated" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/trad/escaped-eof.c b/gcc/testsuite/gcc.dg/cpp/trad/escaped-eof.c new file mode 100644 index 00000000000..37ca95c6918 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/escaped-eof.c @@ -0,0 +1,6 @@ +/* Test for warning of escaped EOF. */ + +/* { dg-do preprocess } */ + +/* { dg-warning "backslash-new" "escaped EOF warning" { target *-*-* } 7 } */ +\ diff --git a/gcc/testsuite/gcc.dg/cpp/trad/hash.c b/gcc/testsuite/gcc.dg/cpp/trad/hash.c new file mode 100644 index 00000000000..8108c89fbfc --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/hash.c @@ -0,0 +1,14 @@ +/* Test for erroneously thinking comments are token-pastes. + From XFree86 4.0. */ +/* { dg-do preprocess } */ + +#ifndef foo +#define foo /**/ +#endif + +#ifndef foo +#define foo /* as nothing */ +#endif + +/* { dg-bogus "(start|end) of macro" "paste at end" { target *-*-* } 7 } */ +/* { dg-bogus "(start|end) of macro" "comment at end" { target *-*-* } 11 } */ diff --git a/gcc/testsuite/gcc.dg/cpp/trad/num-sign.c b/gcc/testsuite/gcc.dg/cpp/trad/num-sign.c new file mode 100644 index 00000000000..7522bbf41e2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/num-sign.c @@ -0,0 +1,16 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. */ + +/* { dg-do preprocess { target i?86-*-* } } */ + +/* Tests that traditional numbers are signed, unless otherwise + specified. This test assumes a 32 bit target. + + Neil Booth, 5 Aug 2001. Inspired by PR 3824. */ + +#if 0xffffffffffffffff >= 0 +# error 0xffffffffffffffff /* { dg-bogus "0xffffffffffffffff" "0xffffffffffffffff positive" } */ +#endif + +#if 0xffffffffffffffffU <= 0 +# error 0xffffffffffffffffU /* { dg-bogus "0xffffffffffffffffU" "0xffffffffffffffffU negative" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/cpp/trad/paste.c b/gcc/testsuite/gcc.dg/cpp/trad/paste.c new file mode 100644 index 00000000000..9f1c0db3291 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/paste.c @@ -0,0 +1,16 @@ +/* Test for proper comment elimination semantics from cpplib's -traditional. + This should compile and link with compiled with `gcc -traditional-cpp'. + Test case by Jason R. Thorpe <thorpej@zembu.com>. */ + +/* { dg-do compile } */ + +#define A(name) X/**/name + +#define B(name) \ +void A(Y/**/name)() { A(name)(); } + +void Xhello() { printf("hello world\n"); } + +B(hello) + +int main() { XYhello(); return (0); } diff --git a/gcc/testsuite/gcc.dg/cpp/trad/redef1.c b/gcc/testsuite/gcc.dg/cpp/trad/redef1.c new file mode 100644 index 00000000000..ce5dde0bb37 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/redef1.c @@ -0,0 +1,36 @@ +/* Test for redefining traditional macros with insignificant + (i.e. whitespace) differences. */ + +/* { dg-do preprocess } */ + + +#define foo bar +#define /* x */ foo /* x */ bar /* x */ + +#define quux(thud) a one and a thud and a two +#define /**/ quux( thud ) /**/ a one and a /**/ thud /**/ and /**/ a two +#define quux(thud) a one and a thud and a two /* bah */ + +#define f(x, y)x "x y z" y +#define f(x, y) x "x y z" y + +#define baz() whiz bang +#define baz() whiz bang + +#define g foo +#undef g +#define g + +/* { dg-bogus "redefined" "foo redefined" { target *-*-* } 8 } */ +/* { dg-bogus "redefined" "quux redefined" { target *-*-* } 11 } */ +/* { dg-bogus "redefined" "quux redefined" { target *-*-* } 12 } */ +/* { dg-bogus "redefined" "f redefined" { target *-*-* } 15 } */ +/* { dg-bogus "redefined" "baz redefined" { target *-*-* } 18 } */ +/* { dg-bogus "redefined" "g redefined" { target *-*-* } 22 } */ + +/* { dg-bogus "previous def" "foo prev def" { target *-*-* } 7 } */ +/* { dg-bogus "previous def" "quux prev def" { target *-*-* } 10 } */ +/* { dg-bogus "previous def" "quux prev def" { target *-*-* } 11 } */ +/* { dg-bogus "previous def" "f prev def" { target *-*-* } 14 } */ +/* { dg-bogus "previous def" "baz prev def" { target *-*-* } 17 } */ +/* { dg-bogus "previous def" "g prev def" { target *-*-* } 20 } */ diff --git a/gcc/testsuite/gcc.dg/cpp/trad/redef2.c b/gcc/testsuite/gcc.dg/cpp/trad/redef2.c new file mode 100644 index 00000000000..269a846266f --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/redef2.c @@ -0,0 +1,32 @@ +/* Test for redefining traditional macros with significant differences. */ + +/* { dg-do preprocess } */ + +#define foo bar /* { dg-warning "previous def" "foo prev def" } */ +#define foo barr /* { dg-warning "redefined" "foo redefined" } */ + +#undef foo +#define foo bar /* { dg-warning "previous def" "foo prev def 2" } */ +#define foo() bar /* { dg-warning "redefined" "foo redefined 2" } */ + +#undef foo +#define foo() bar /* { dg-warning "previous def" "foo prev def" } */ +#define foo() barr /* { dg-warning "redefined" "foo redefined" } */ + +#define quux(thud) a thud b /* { dg-warning "previous def" "quux prev def" } */ +#define quux(thu) a thud b /* { dg-warning "redefined" "quux redefined" } */ + +#define bar(x, y) x+y /* { dg-warning "previous def" "bar prev def" } */ +#define bar(x, y) x+x /* { dg-warning "redefined" "bar redefined" } */ + +#define bat(x, y) x+y /* { dg-warning "previous def" "bat prev def" } */ +#define bat(x, y) x+ y /* { dg-warning "redefined" "bat redefined" } */ + +#define baz(x, y) x+y /* { dg-warning "previous def" "baz prev def" } */ +#define baz(x, y) x +y /* { dg-warning "redefined" "baz redefined" } */ + +#define f(x, y) "x y" /* { dg-warning "previous def" "f prev def" } */ +#define f(x, y) "x y" /* { dg-warning "redefined" "f redefined" } */ + +#define g(x, y) 'x' /* { dg-warning "previous def" "g prev def" } */ +#define g(x, y) ' x' /* { dg-warning "redefined" "g redefined" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/trad/strify.c b/gcc/testsuite/gcc.dg/cpp/trad/strify.c new file mode 100644 index 00000000000..500ef1ea32f --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/strify.c @@ -0,0 +1,17 @@ +/* Test whether traditional stringify works. */ +/* { dg-do run } */ + +#define foo(a, b) c="a"; d="b"; + +extern void abort (); + +int main () +{ + char *c, *d; + + foo (p,q); + if (c[0] != 'p' || d[0] != 'q') + abort (); + + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/cpp/trad/trad.exp b/gcc/testsuite/gcc.dg/cpp/trad/trad.exp new file mode 100644 index 00000000000..60d90023007 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/trad.exp @@ -0,0 +1,43 @@ +# Copyright (C) 1997, 2000 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# GCC testsuite that uses the `dg.exp' driver. + +# There's a bunch of headers we need. +if [is_remote host] { + foreach header [glob -nocomplain $srcdir/$subdir/*.{h,def} ] { + remote_download host $header + } +} + +# Load support procs. +load_lib gcc-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_TRADCPPFLAGS +if ![info exists DEFAULT_TRADCPPFLAGS] then { + set DEFAULT_TRADCPPFLAGS " -traditional-cpp" +} + +# Initialize `dg'. +dg-init + +# Main loop. +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \ + "" $DEFAULT_TRADCPPFLAGS + +# All done. +dg-finish diff --git a/gcc/testsuite/gcc.dg/cpp/trad/uchar.c b/gcc/testsuite/gcc.dg/cpp/trad/uchar.c new file mode 100644 index 00000000000..8ea54a1f43c --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/uchar.c @@ -0,0 +1,8 @@ +/* Copyright (C) 2002 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ +/* { dg-options "-funsigned-char -fsigned-char -traditional-cpp" } */ + +#if defined (__CHAR_UNSIGNED__) +# error __CHAR_UNSIGNED__ defined +#endif |