aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorAnthony Brandon <anthony.brandon@gmail.com>2014-11-11 23:33:25 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2014-11-11 23:33:25 +0000
commit3d00119cfbbcadccb56e5a0b8fe447ad7554d681 (patch)
treed4db9e599db1d46abb0414b25660560c2823a504 /gcc/gcc.c
parent3aa34c1d8f94fc56d66de3b8d09dbd8c2c9e8525 (diff)
downloadgcc-3d00119cfbbcadccb56e5a0b8fe447ad7554d681.zip
gcc-3d00119cfbbcadccb56e5a0b8fe447ad7554d681.tar.gz
gcc-3d00119cfbbcadccb56e5a0b8fe447ad7554d681.tar.bz2
re PR driver/36312 (should refuse to overwrite input file with output file)
gcc/testsuite/ChangeLog: 2014-11-11 Anthony Brandon <anthony.brandon@gmail.com> Manuel López-Ibáñez <manu@gcc.gnu.org> PR driver/36312 * gcc.misc-tests/output.exp: New test case for identical input and output files. include/ChangeLog: 2014-11-11 Anthony Brandon <anthony.brandon@gmail.com> Manuel López-Ibáñez <manu@gcc.gnu.org> PR driver/36312 * filenames.h: Add prototype for canonical_filename_eq. gcc/ChangeLog: 2014-11-11 Anthony Brandon <anthony.brandon@gmail.com> Manuel López-Ibáñez <manu@gcc.gnu.org> PR driver/36312 * diagnostic-core.h: Add prototype for fatal_error. * diagnostic.c (fatal_error): New function fatal_error. * gcc.c (store_arg): Remove have_o_argbuf_index. (process_command): Check if input and output files are the same. * toplev.c (init_asm_output): Check if input and output files are the same. libiberty/ChangeLog: 2014-11-11 Anthony Brandon <anthony.brandon@gmail.com> Manuel López-Ibáñez <manu@gcc.gnu.org> PR driver/36312 * filename_cmp.c (canonical_filename_eq): New function to check if file names are the same. * functions.texi: Updated with documentation for new function. Co-Authored-By: Manuel López-Ibáñez <manu@gcc.gnu.org> From-SVN: r217391
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index e013d52..7e6af22 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1702,17 +1702,15 @@ typedef const char *const_char_p; /* For DEF_VEC_P. */
static vec<const_char_p> argbuf;
-/* Position in the argbuf vector containing the name of the output file
- (the value associated with the "-o" flag). */
-
-static int have_o_argbuf_index = 0;
-
/* Were the options -c, -S or -E passed. */
static int have_c = 0;
/* Was the option -o passed. */
static int have_o = 0;
+/* Pointer to output file name passed in with -o. */
+static const char *output_file = 0;
+
/* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
it here. */
@@ -1762,8 +1760,6 @@ store_arg (const char *arg, int delete_always, int delete_failure)
{
argbuf.safe_push (arg);
- if (strcmp (arg, "-o") == 0)
- have_o_argbuf_index = argbuf.length ();
if (delete_always || delete_failure)
{
const char *p;
@@ -3713,6 +3709,7 @@ driver_handle_option (struct gcc_options *opts,
#if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
arg = convert_filename (arg, ! have_c, 0);
#endif
+ output_file = arg;
/* Save the output name in case -save-temps=obj was used. */
save_temps_prefix = xstrdup (arg);
/* On some systems, ld cannot handle "-o" without a space. So
@@ -4052,6 +4049,16 @@ process_command (unsigned int decoded_options_count,
CL_DRIVER, &handlers, global_dc);
}
+ if (output_file && strcmp (output_file, "-"))
+ {
+ int i;
+ for (i = 0; i < n_infiles; i++)
+ if ((!infiles[i].language || infiles[i].language[0] != '*')
+ && canonical_filename_eq (infiles[i].name, output_file))
+ fatal_error ("input file %qs is the same as output file",
+ output_file);
+ }
+
/* If -save-temps=obj and -o name, create the prefix to use for %b.
Otherwise just make -save-temps=obj the same as -save-temps=cwd. */
if (save_temps_flag == SAVE_TEMPS_OBJ && save_temps_prefix != NULL)