From a702045a246397c2d31e1671fc3140112e669ec6 Mon Sep 17 00:00:00 2001 From: Ollie Wild Date: Thu, 24 May 2007 20:55:36 +0000 Subject: macro.c (_cpp_builtin_macro_text): Handle BT_COUNTER. * macro.c (_cpp_builtin_macro_text): Handle BT_COUNTER. * pch.c (cpp_write_pch_deps): Save __COUNTER__ state. (cpp_write_pch_state): Save __COUNTER__ state. (cpp_valid_state): Check valid __COUNTER__ state. (cpp_read_state): Read new __COUNTER__ state. * include/cpplib.h (enum builtin_type): Add BT_COUNTER enumerator. * init.c (builtin_array): Add __COUNTER__/BT_COUNTER. * internal.h (struct cpp_reader): Add counter member. * gcc.dg/cpp/counter-1.c: New test. * gcc.dg/pch/counter-1.c: New test. * gcc.dg/pch/counter-1.hs: New file. * gcc.dg/pch/counter-2.c: New test. * gcc.dg/pch/counter-2.hs: New file. * gcc.dg/pch/counter-3.c: New test. * gcc.dg/pch/counter-3.hs: New file. * doc/cpp.texi (Common Predefined Macros): Add __COUNTER__ description. From-SVN: r125041 --- gcc/ChangeLog | 5 +++++ gcc/doc/cpp.texi | 7 +++++++ gcc/testsuite/ChangeLog | 10 ++++++++++ gcc/testsuite/gcc.dg/cpp/counter-1.c | 20 ++++++++++++++++++++ gcc/testsuite/gcc.dg/pch/counter-1.c | 9 +++++++++ gcc/testsuite/gcc.dg/pch/counter-1.hs | 5 +++++ gcc/testsuite/gcc.dg/pch/counter-2.c | 15 +++++++++++++++ gcc/testsuite/gcc.dg/pch/counter-2.hs | 4 ++++ gcc/testsuite/gcc.dg/pch/counter-3.c | 13 +++++++++++++ gcc/testsuite/gcc.dg/pch/counter-3.hs | 4 ++++ 10 files changed, 92 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/cpp/counter-1.c create mode 100644 gcc/testsuite/gcc.dg/pch/counter-1.c create mode 100644 gcc/testsuite/gcc.dg/pch/counter-1.hs create mode 100644 gcc/testsuite/gcc.dg/pch/counter-2.c create mode 100644 gcc/testsuite/gcc.dg/pch/counter-2.hs create mode 100644 gcc/testsuite/gcc.dg/pch/counter-3.c create mode 100644 gcc/testsuite/gcc.dg/pch/counter-3.hs (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d2fa44d..28dcaec 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2007-05-24 Ollie Wild + + * doc/cpp.texi (Common Predefined Macros): Add __COUNTER__ + description. + 2007-05-24 Richard Sandiford * postreload-gcse.c (reg_changed_after_insn_p): New function. diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index e6786cf..54941a9 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -1917,6 +1917,13 @@ underscores. @table @code +@item __COUNTER__ +This macro expands to sequential integral values starting from 0. In +conjuction with the @code{##} operator, this provides a convenient means to +generate unique identifiers. Care must be taken to ensure that +@code{__COUNTER__} is not expanded prior to inclusion of precompiled headers +which use it. Otherwise, the precompiled headers will not be used. + @item __GNUC__ @itemx __GNUC_MINOR__ @itemx __GNUC_PATCHLEVEL__ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e230bc3..7a33bde 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2007-05-24 Ollie Wild + + * gcc.dg/cpp/counter-1.c: New test. + * gcc.dg/pch/counter-1.c: New test. + * gcc.dg/pch/counter-1.hs: New file. + * gcc.dg/pch/counter-2.c: New test. + * gcc.dg/pch/counter-2.hs: New file. + * gcc.dg/pch/counter-3.c: New test. + * gcc.dg/pch/counter-3.hs: New file. + 2007-05-24 Zdenek Dvorak * gcc.dg/tree-ssa/predcom-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/cpp/counter-1.c b/gcc/testsuite/gcc.dg/cpp/counter-1.c new file mode 100644 index 0000000..80d8b78 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/counter-1.c @@ -0,0 +1,20 @@ +/* Copyright (C) 2007 Free Software Foundation + Contributed by Ollie Wild */ + +/* { dg-do preprocess } */ + +/* Tests __COUNTER__ macro is correctly expanded. */ + +#define counter __COUNTER__ + +#if __COUNTER__ != 0 +#error __COUNTER__ != 0 +#endif + +#if counter != 1 +#error counter != 1 +#endif + +#if __COUNTER__ != 2 +#error __COUNTER__ != 2 +#endif diff --git a/gcc/testsuite/gcc.dg/pch/counter-1.c b/gcc/testsuite/gcc.dg/pch/counter-1.c new file mode 100644 index 0000000..79cea88 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/counter-1.c @@ -0,0 +1,9 @@ +/* Copyright (C) 2007 Free Software Foundation + Contributed by Ollie Wild */ + +#include "counter-1.h" + +int main(void) +{ + return __COUNTER__; +} diff --git a/gcc/testsuite/gcc.dg/pch/counter-1.hs b/gcc/testsuite/gcc.dg/pch/counter-1.hs new file mode 100644 index 0000000..c3d2ce7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/counter-1.hs @@ -0,0 +1,5 @@ +/* Copyright (C) 2007 Free Software Foundation + Contributed by Ollie Wild */ + +static unsigned offset[] = {__COUNTER__, __COUNTER__, __COUNTER__}; +#define counter __COUNTER__ diff --git a/gcc/testsuite/gcc.dg/pch/counter-2.c b/gcc/testsuite/gcc.dg/pch/counter-2.c new file mode 100644 index 0000000..7bbde23 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/counter-2.c @@ -0,0 +1,15 @@ +/* Copyright (C) 2007 Free Software Foundation + Contributed by Ollie Wild */ + +/* { dg-options "-I. -Winvalid-pch" } */ + +#if __COUNTER__ != 0 +#error __COUNTER__ != 0 +#endif + +#include "counter-2.h"/* { dg-error "`__COUNTER__' is invalid|No such file|they were invalid" } */ + +int main(void) +{ + return __COUNTER__; +} diff --git a/gcc/testsuite/gcc.dg/pch/counter-2.hs b/gcc/testsuite/gcc.dg/pch/counter-2.hs new file mode 100644 index 0000000..63b8a2b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/counter-2.hs @@ -0,0 +1,4 @@ +/* Copyright (C) 2007 Free Software Foundation + Contributed by Ollie Wild */ + +static int i = __COUNTER__; diff --git a/gcc/testsuite/gcc.dg/pch/counter-3.c b/gcc/testsuite/gcc.dg/pch/counter-3.c new file mode 100644 index 0000000..8279205 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/counter-3.c @@ -0,0 +1,13 @@ +/* Copyright (C) 2007 Free Software Foundation + Contributed by Ollie Wild */ + +#if __COUNTER__ != 0 +#error __COUNTER__ != 0 +#endif + +#include "counter-3.h" + +int main(void) +{ + return __COUNTER__; +} diff --git a/gcc/testsuite/gcc.dg/pch/counter-3.hs b/gcc/testsuite/gcc.dg/pch/counter-3.hs new file mode 100644 index 0000000..19039c8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/counter-3.hs @@ -0,0 +1,4 @@ +/* Copyright (C) 2007 Free Software Foundation + Contributed by Ollie Wild */ + +#define counter __COUNTER__ -- cgit v1.1