Re: [PATCH driver/36312] should refuse to overwrite input file with output file

2014-11-10 Thread Joseph Myers
On Sat, 8 Nov 2014, Manuel López-Ibáñez wrote:

 This patch is a minor variant of the one approved here:
 
 https://gcc.gnu.org/ml/gcc-patches/2014-11/msg00246.html
 
 fixing the problem with linker parameters (which are stored in infiles).
 
 https://gcc.gnu.org/ml/gcc-patches/2014-11/msg00391.html
 
 The only part that has changed, and thus requires approval, is in
 gcc/gcc.c, in particular the condition:
 
 +if ((!infiles[i].language || infiles[i].language[0] != '*')
 + canonical_filename_eq (infiles[i].name, output_file))
 
 is new.

That part is OK.


-- 
Joseph S. Myers
jos...@codesourcery.com

[PATCH driver/36312] should refuse to overwrite input file with output file

2014-11-08 Thread Manuel López-Ibáñez
This patch is a minor variant of the one approved here:

https://gcc.gnu.org/ml/gcc-patches/2014-11/msg00246.html

fixing the problem with linker parameters (which are stored in infiles).

https://gcc.gnu.org/ml/gcc-patches/2014-11/msg00391.html

The only part that has changed, and thus requires approval, is in
gcc/gcc.c, in particular the condition:

+if ((!infiles[i].language || infiles[i].language[0] != '*')
+ canonical_filename_eq (infiles[i].name, output_file))

is new.

Boottested on x86_64-linux-gnu with
--enable-languages=c,c++,objc,fortran,ada,obj-c++

OK?

gcc/testsuite/ChangeLog:

2014-11-08  Anthony Brandon  anthony.bran...@gmail.com
Manuel López-Ibáñez  m...@gcc.gnu.org

PR driver/36312
* gcc.misc-tests/output.exp: New test case for identical input and
output files.

include/ChangeLog:

2014-11-08  Anthony Brandon  anthony.bran...@gmail.com
Manuel López-Ibáñez  m...@gcc.gnu.org

PR driver/36312
* filenames.h: Add prototype for canonical_filename_eq.

gcc/ChangeLog:

2014-11-08  Anthony Brandon  anthony.bran...@gmail.com
Manuel López-Ibáñez  m...@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-08  Anthony Brandon  anthony.bran...@gmail.com
Manuel López-Ibáñez  m...@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.
Index: include/filenames.h
===
--- include/filenames.h (revision 217234)
+++ include/filenames.h (working copy)
@@ -88,10 +88,12 @@ extern int filename_ncmp (const char *s1
 
 extern hashval_t filename_hash (const void *s);
 
 extern int filename_eq (const void *s1, const void *s2);
 
+extern int canonical_filename_eq (const char *a, const char *b);
+
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* FILENAMES_H */
Index: libiberty/functions.texi
===
--- libiberty/functions.texi(revision 217234)
+++ libiberty/functions.texi(working copy)
@@ -123,10 +123,20 @@ is deprecated in favor of @code{memset}.
 Uses @code{malloc} to allocate storage for @var{nelem} objects of
 @var{elsize} bytes each, then zeros the memory.
 
 @end deftypefn
 
+@c filename_cmp.c:201
+@deftypefn Extension int canonical_filename_eq (const char *@var{a}, const 
char *@var{b})
+
+Return non-zero if file names @var{a} and @var{b} are equivalent.
+This function compares the canonical versions of the filenames as returned by
+@code{lrealpath()}, so that so that different file names pointing to the same
+underlying file are treated as being identical.
+
+@end deftypefn
+
 @c choose-temp.c:45
 @deftypefn Extension char* choose_temp_base (void)
 
 Return a prefix for temporary file names or @code{NULL} if unable to
 find one.  The current directory is chosen if all else fails so the
@@ -284,11 +294,11 @@ Find the first (least significant) bit s
 numbered from right to left, starting with bit 1 (corresponding to the
 value 1).  If @var{valu} is zero, zero is returned.
 
 @end deftypefn
 
-@c filename_cmp.c:32
+@c filename_cmp.c:37
 @deftypefn Extension int filename_cmp (const char *@var{s1}, const char 
*@var{s2})
 
 Return zero if the two file names @var{s1} and @var{s2} are equivalent.
 If not equivalent, the returned value is similar to what @code{strcmp}
 would return.  In other words, it returns a negative value if @var{s1}
@@ -301,28 +311,28 @@ the case when the two filenames point to
 However, it does handle the fact that on DOS-like file systems, forward
 and backward slashes are equal.
 
 @end deftypefn
 
-@c filename_cmp.c:178
+@c filename_cmp.c:183
 @deftypefn Extension int filename_eq (const void *@var{s1}, const void 
*@var{s2})
 
 Return non-zero if file names @var{s1} and @var{s2} are equivalent.
 This function is for use with hashtab.c hash tables.
 
 @end deftypefn
 
-@c filename_cmp.c:147
+@c filename_cmp.c:152
 @deftypefn Extension hashval_t filename_hash (const void *@var{s})
 
 Return the hash value for file name @var{s} that will be compared
 using filename_cmp.
 This function is for use with hashtab.c hash tables.
 
 @end deftypefn
 
-@c filename_cmp.c:89
+@c filename_cmp.c:94
 @deftypefn Extension int filename_ncmp (const char *@var{s1}, const char 
*@var{s2}, size_t @var{n})
 
 Return zero if the two file names @var{s1} and @var{s2} are equivalent
 in range @var{n}.
 If not equivalent, the returned value is similar to what @code{strncmp}
Index: libiberty/filename_cmp.c