diff options
author | Gary Funck <gary@intrepid.com> | 2012-01-09 08:48:43 +0000 |
---|---|---|
committer | Gary Funck <gfunck@gcc.gnu.org> | 2012-01-09 08:48:43 +0000 |
commit | b492b6862ef38c3a8c7a67f4c410dcf69434507d (patch) | |
tree | 2b2f237168b3048e8f7a77942d33aaf369c7cae0 | |
parent | fdff9f3d33732e60f9c1a22e4a3c40a3aeea7447 (diff) | |
download | gcc-b492b6862ef38c3a8c7a67f4c410dcf69434507d.zip gcc-b492b6862ef38c3a8c7a67f4c410dcf69434507d.tar.gz gcc-b492b6862ef38c3a8c7a67f4c410dcf69434507d.tar.bz2 |
re PR preprocessor/33919 (__BASE_FILE__ does not expand correctly when included from the command line)
libcpp/
PR preprocessor/33919
* files.c (_cpp_get_file_name): New. Implement file name
access function.
* internal.h (_cpp_get_file_name): New prototype.
* macro.c (_cpp_builtin_macro_text): Call _cpp_get_file_name()
to use pfile->main_file in lieu of traversing INCLUDED_FROM chain.
gcc/testsuite/
PR preprocessor/33919
* gcc.dg/pr33919.c: New test.
* gcc.dg/pr33919-0.h: New test header file.
* gcc.dg/pr33919-1.h: Ditto.
* gcc.dg/pr33919-2.h: Ditto.
From-SVN: r183003
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr33919-0.h | 1 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr33919-1.h | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr33919-2.h | 1 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr33919.c | 26 | ||||
-rw-r--r-- | libcpp/ChangeLog | 9 | ||||
-rw-r--r-- | libcpp/files.c | 11 | ||||
-rw-r--r-- | libcpp/internal.h | 3 | ||||
-rw-r--r-- | libcpp/macro.c | 9 |
9 files changed, 62 insertions, 8 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b8b9b94..06ad7c6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2012-01-09 Gary Funck <gary@intrepid.com> + + PR preprocessor/33919 + * gcc.dg/pr33919.c: New test. + * gcc.dg/pr33919-0.h: New test header file. + * gcc.dg/pr33919-1.h: Ditto. + * gcc.dg/pr33919-2.h: Ditto. + 2012-01-07 Jan Hubicka <jh@suse.cz> PR tree-optimize/51694 diff --git a/gcc/testsuite/gcc.dg/pr33919-0.h b/gcc/testsuite/gcc.dg/pr33919-0.h new file mode 100644 index 0000000..21966c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr33919-0.h @@ -0,0 +1 @@ +char *pre_inc_base_file = __BASE_FILE__; diff --git a/gcc/testsuite/gcc.dg/pr33919-1.h b/gcc/testsuite/gcc.dg/pr33919-1.h new file mode 100644 index 0000000..c7345aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr33919-1.h @@ -0,0 +1,2 @@ +#include "pr33919-2.h" +char *inc_base_file = __BASE_FILE__; diff --git a/gcc/testsuite/gcc.dg/pr33919-2.h b/gcc/testsuite/gcc.dg/pr33919-2.h new file mode 100644 index 0000000..3c22257 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr33919-2.h @@ -0,0 +1 @@ +char *nested_inc_base_file = __BASE_FILE__; diff --git a/gcc/testsuite/gcc.dg/pr33919.c b/gcc/testsuite/gcc.dg/pr33919.c new file mode 100644 index 0000000..14ea374 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr33919.c @@ -0,0 +1,26 @@ +/* PR preprocessor/pr33919 */ +/* { dg-do run } */ +/* { dg-options "-I . -include ${srcdir}/gcc.dg/pr33919-0.h" } */ + +#include "pr33919-1.h" + +const char *base_file = __BASE_FILE__; + +extern int strcmp (const char *, const char *); +extern void abort (void); + +int +main () +{ + if (!strcmp (pre_inc_base_file, "<command line>")) + abort (); + if (strcmp (pre_inc_base_file, __FILE__)) + abort (); + if (strcmp (base_file, __FILE__)) + abort (); + if (strcmp (inc_base_file, __FILE__)) + abort (); + if (strcmp (nested_inc_base_file, __FILE__)) + abort (); + return 0; +} diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index dfe18d0..8a1eb05 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,12 @@ +2012-01-09 Gary Funck <gary@intrepid.com> + + PR preprocessor/33919 + * files.c (_cpp_get_file_name): New. Implement file name + access function. + * internal.h (_cpp_get_file_name): New prototype. + * macro.c (_cpp_builtin_macro_text): Call _cpp_get_file_name() + to use pfile->main_file in lieu of traversing INCLUDED_FROM chain. + 2012-01-03 Olivier Hainque <hainque@adacore.com> * system.h: Prior to #define, #undef fopen and freopen unconditionally. diff --git a/libcpp/files.c b/libcpp/files.c index fad8b75..29ccf3b 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -1,7 +1,7 @@ /* Part of CPP library. File handling. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 - Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003, 2004, 2005, + 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. Written by Per Bothner, 1994. Based on CCCP program by Paul Rubin, June 1986 Adapted to ANSI C, Richard Stallman, Jan 1987 @@ -1370,6 +1370,13 @@ _cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file) } } +/* Return the file name associated with FILE. */ +const char * +_cpp_get_file_name (_cpp_file *file) +{ + return file->name; +} + /* Inteface to file statistics record in _cpp_file structure. */ struct stat * _cpp_get_file_stat (_cpp_file *file) diff --git a/libcpp/internal.h b/libcpp/internal.h index 7e2932a..5b3731b 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -1,6 +1,6 @@ /* Part of CPP library. Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, - 2008, 2009, 2010, 2011 Free Software Foundation, Inc. + 2008, 2009, 2010, 2011, 2012 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 @@ -635,6 +635,7 @@ extern void _cpp_cleanup_files (cpp_reader *); extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *); extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f); extern bool _cpp_read_file_entries (cpp_reader *, FILE *); +extern const char *_cpp_get_file_name (_cpp_file *); extern struct stat *_cpp_get_file_stat (_cpp_file *); /* In expr.c */ diff --git a/libcpp/macro.c b/libcpp/macro.c index d96b2631a..32f99ca 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -1,7 +1,7 @@ /* Part of CPP library. (Macro and #define handling.) Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. + 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. Written by Per Bothner, 1994. Based on CCCP program by Paul Rubin, June 1986 Adapted to ANSI C, Richard Stallman, Jan 1987 @@ -278,10 +278,9 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) pfile->line_table->highest_line); else { - map = linemap_lookup (pfile->line_table, pfile->line_table->highest_line); - while (! MAIN_FILE_P (map)) - map = INCLUDED_FROM (pfile->line_table, map); - name = ORDINARY_MAP_FILE_NAME (map); + name = _cpp_get_file_name (pfile->main_file); + if (!name) + abort (); } len = strlen (name); buf = _cpp_unaligned_alloc (pfile, len * 2 + 3); |