https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89658

            Bug ID: 89658
           Summary: __BASE_FILE__ is not preserved when using
                    -fdirectives-only
           Product: gcc
           Version: 8.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jpewhacker at gmail dot com
  Target Milestone: ---

Created attachment 45938
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45938&action=edit
test.c

When using "-E -fdirectives-only" to preprocess a file, then compiling it later
with "-fprocessed -fdirectives-only", __BASE_FILE__ is not correctly preserved.
__FILE__ is preserved due to file and line number directives in the
preprocessed output, but __BASE_FILE__ gets lost.

The attached source program can demonstrate this behaviour as follows:

 $ gcc -o preprocess.c -E test.c -fdirectives-only && gcc -o test -xc
preprocess.c -fpreprocessed -fdirectives-only && ./test
 __BASE_FILE__ = preprocess.c
 __FILE__ = test.c

As can be seen, __FILE__ is correctly set from the original input file, but
__BASE_FILE__ picks up the name of the preprocessed intermediate file (and
doesn't match the initial __FILE__ as expected).


Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin
--enable-initfini-array --with-isl --enable-libmpx
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-gnu-indirect-function --enable-cet --with-tune=generic
--with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.2.1 20181215 (Red Hat 8.2.1-6) (GCC)

Reply via email to