Commit 00b94a44 by Neil Booth Committed by Neil Booth

cpperror.c (cpp_error): For traditional CPP, default to diagnostics on pfile->line.

	* 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.

From-SVN: r54870
parent c583c5c3
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.
......
......@@ -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;
......
......@@ -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++;
}
......
......@@ -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;
......
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,
......
/* Test that __STDC__ is not defined. */
/* { dg-do preprocess } */
#if defined __STDC__
# error __STDC__ defined /* { dg-bogus "__STDC__" "__STDC__ defined" } */
#endif
/* 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
/* 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
/* 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
/* Test for warning of unterminated comment. */
/* { dg-do preprocess } */
/* { dg-warning "unterminated comment" }
/* { dg-do preprocess } */
/* { dg-options "-traditional-cpp -DDEFINE1DEFINE -DDEFINE2DEFIN=" } */
/* 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
/* 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" } */
/* Test for warning of escaped EOF. */
/* { dg-do preprocess } */
/* { dg-warning "backslash-new" "escaped EOF warning" { target *-*-* } 7 } */
\
/* 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 } */
/* 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
/* 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); }
/* 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 } */
/* 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" } */
/* 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);
}
# 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
/* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment