Hello,

Currently, GCC outputs ".s" assembly files when running on C/C++ header files with -fdump-ada-spec. This is unexpected, since -fdump-ada-spec is used only to output an Ada binding.

This patch fixes the spec-strings for C/C++ header files in order to pass a "-o %g.s" flag to cc1/cc1plus, so that output assembly files are cleaned at exit. It also fixes the processing of the -fsyntax-only flag for C header file so that the "-o ..." argument is passed only once, as the spec-string for C++ header files does.

I could bootstrap the patch and it triggered no regression on x86_64-linux. I've written a simple test that checks that no assembly file/object file is produced when compiling C/C++ header files with -fdump-ada-spec. In order to do this, I had to create a new *.exp file so that the testsuite processes my C header files (the regular dg.exp file skips *.h files).

I also noticed that using -S and -o options at the same time currently doesn't work on header files (even without -fdump-ada-spec): cc1 is spawned with two "-o" arguments. That's why in the dump-ada-spec-2.h file I've specified "dg-do assemble" instead of "dg-do compile".

Many thanks in advance for your comments!


2014-06-02  Eric Botcazou  <botca...@adacore.com>
            Pierre-Marie de Rodat  <dero...@adacore.com>

gcc/
        * gcc.dg/dump-ada-spec/dump-ada-spec.exp: New.
        * gcc.dg/dump-ada-spec-1.c: Move to dump-ada-spec.
        * gcc.dg/dump-ada-spec/dump-ada-spec-2.h: New.
        * g++.dg/dump-ada-spec: New.

gcc/testsuite/
        * lib/gcc-dg.exp (file-exists, file-exists-not): New.
        * gcc.c (default_compilers): Prevent creation of .s files with
        -fdump-ada-spec and -fdump-xref.
        * cp/lang-specs.h: Likewise.

--
Pierre-Marie de Rodat
diff --git gcc/ChangeLog gcc/ChangeLog
index bc9b036..e74d282 100644
--- gcc/ChangeLog
+++ gcc/ChangeLog
@@ -1,3 +1,10 @@
+2014-06-02  Eric Botcazou  <botca...@adacore.com>
+            Pierre-Marie de Rodat  <dero...@adacore.com>
+
+       * gcc.c (default_compilers): Prevent creation of .s files with
+       -fdump-ada-spec and -fdump-xref.
+       * cp/lang-specs.h: Likewise.
+
 2014-06-02  Uros Bizjak  <ubiz...@gmail.com>
 
        PR target/61239
diff --git gcc/cp/lang-specs.h gcc/cp/lang-specs.h
index 79c9222..35c3954 100644
--- gcc/cp/lang-specs.h
+++ gcc/cp/lang-specs.h
@@ -47,7 +47,7 @@ along with GCC; see the file COPYING3.  If not see
       cc1plus %{save-temps*|no-integrated-cpp:-fpreprocessed 
%{save-temps*:%b.ii} %{!save-temps*:%g.ii}}\
              %{!save-temps*:%{!no-integrated-cpp:%(cpp_unique_options)}}\
        %(cc1_options) %2\
-       %{!fsyntax-only:%{!fdump-ada-spec*:-o %g.s %{!o*:--output-pch=%i.gch}\
+       %{!fsyntax-only:-o %g.s %{!fdump-ada-spec*:%{!o*:--output-pch=%i.gch}\
         %W{o*:--output-pch=%*}}%V}}}}",
      CPLUSPLUS_CPP_SPEC, 0, 0},
   {"@c++",
diff --git gcc/gcc.c gcc/gcc.c
index 9ac18e6..699753a 100644
--- gcc/gcc.c
+++ gcc/gcc.c
@@ -1057,12 +1057,12 @@ static const struct compiler default_compilers[] =
                %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
                    cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} 
\
                        %(cc1_options)\
-                        %{!fdump-ada-spec*:-o %g.s %{!o*:--output-pch=%i.gch}\
-                        %W{o*:--output-pch=%*}}%V}\
+                        %{!fsyntax-only:-o %g.s 
%{!fdump-ada-spec*:%{!o*:--output-pch=%i.gch}\
+                        %W{o*:--output-pch=%*}}%V}}\
          %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
                cc1 %(cpp_unique_options) %(cc1_options)\
-                    %{!fdump-ada-spec*:-o %g.s %{!o*:--output-pch=%i.gch}\
-                    %W{o*:--output-pch=%*}}%V}}}}}}", 0, 0, 0},
+                    %{!fsyntax-only:-o %g.s 
%{!fdump-ada-spec*:%{!o*:--output-pch=%i.gch}\
+                    %W{o*:--output-pch=%*}}%V}}}}}}}", 0, 0, 0},
   {".i", "@cpp-output", 0, 0, 0},
   {"@cpp-output",
    "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) 
%{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0},
diff --git gcc/testsuite/ChangeLog gcc/testsuite/ChangeLog
index a52af2b..ce1ca39 100644
--- gcc/testsuite/ChangeLog
+++ gcc/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2014-06-02  Eric Botcazou  <botca...@adacore.com>
+            Pierre-Marie de Rodat  <dero...@adacore.com>
+
+       * lib/gcc-dg.exp (file-exists, file-exists-not): New.
+       * gcc.dg/dump-ada-spec/dump-ada-spec.exp: New.
+       * gcc.dg/dump-ada-spec-1.c: Move to dump-ada-spec.
+       * gcc.dg/dump-ada-spec/dump-ada-spec-2.h: New.
+       * g++.dg/dump-ada-spec: New.
+
 2014-06-02  Uros Bizjak  <ubiz...@gmail.com>
 
        * gcc.target/i386/xop-rotate1-vector.c (dg-options): Add -mno-avx2.
diff --git gcc/testsuite/g++.dg/dump-ada-spec/dump-ada-spec-1.c 
gcc/testsuite/g++.dg/dump-ada-spec/dump-ada-spec-1.c
new file mode 100644
index 0000000..eb249e7
--- /dev/null
+++ gcc/testsuite/g++.dg/dump-ada-spec/dump-ada-spec-1.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-ada-spec" } */
+
+struct S
+{
+  int i;
+};
+
+/* { dg-final { scan-ada-spec "type S is record" } } */
+/* { dg-final { cleanup-ada-spec } } */
diff --git gcc/testsuite/g++.dg/dump-ada-spec/dump-ada-spec-2.h 
gcc/testsuite/g++.dg/dump-ada-spec/dump-ada-spec-2.h
new file mode 100644
index 0000000..663fa96
--- /dev/null
+++ gcc/testsuite/g++.dg/dump-ada-spec/dump-ada-spec-2.h
@@ -0,0 +1,8 @@
+/* { dg-do assemble } */
+/* { dg-options "-fdump-ada-spec" } */
+
+extern void foo (void);
+
+/* { dg-final { file-exists-not "dump-ada-spec-2.s" } } */
+/* { dg-final { file-exists-not "dump-ada-spec-2.o" } } */
+/* { dg-final { file-exists-not "dump-ada-spec-2.gch" } } */
diff --git gcc/testsuite/g++.dg/dump-ada-spec/dump-ada-spec.exp 
gcc/testsuite/g++.dg/dump-ada-spec/dump-ada-spec.exp
new file mode 100644
index 0000000..01b3e86
--- /dev/null
+++ gcc/testsuite/g++.dg/dump-ada-spec/dump-ada-spec.exp
@@ -0,0 +1,36 @@
+#   Copyright (C) 1997-2014 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 Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Load support procs.
+load_lib g++-dg.exp
+
+# If a testcase doesn't have special options, use these.
+global DEFAULT_CFLAGS
+if ![info exists DEFAULT_CFLAGS] then {
+    set DEFAULT_CFLAGS " -ansi -pedantic-errors"
+}
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[ch\]]] \
+       "" $DEFAULT_CFLAGS
+
+# All done.
+dg-finish
diff --git gcc/testsuite/g++.dg/dump-ada-spec/dump_ada_spec_2_h.ads 
gcc/testsuite/g++.dg/dump-ada-spec/dump_ada_spec_2_h.ads
new file mode 100644
index 0000000..d96d818
--- /dev/null
+++ gcc/testsuite/g++.dg/dump-ada-spec/dump_ada_spec_2_h.ads
@@ -0,0 +1,11 @@
+pragma Ada_2005;
+pragma Style_Checks (Off);
+
+with Interfaces.C; use Interfaces.C;
+
+package dump_ada_spec_2_h is
+
+   procedure foo;  -- dump-ada-spec-2.h:4
+   pragma Import (C, foo, "foo");
+
+end dump_ada_spec_2_h;
diff --git gcc/testsuite/gcc.dg/dump-ada-spec-1.c 
gcc/testsuite/gcc.dg/dump-ada-spec-1.c
deleted file mode 100644
index eb249e7..0000000
--- gcc/testsuite/gcc.dg/dump-ada-spec-1.c
+++ /dev/null
@@ -1,10 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-fdump-ada-spec" } */
-
-struct S
-{
-  int i;
-};
-
-/* { dg-final { scan-ada-spec "type S is record" } } */
-/* { dg-final { cleanup-ada-spec } } */
diff --git gcc/testsuite/gcc.dg/dump-ada-spec/dump-ada-spec-1.c 
gcc/testsuite/gcc.dg/dump-ada-spec/dump-ada-spec-1.c
new file mode 100644
index 0000000..eb249e7
--- /dev/null
+++ gcc/testsuite/gcc.dg/dump-ada-spec/dump-ada-spec-1.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-ada-spec" } */
+
+struct S
+{
+  int i;
+};
+
+/* { dg-final { scan-ada-spec "type S is record" } } */
+/* { dg-final { cleanup-ada-spec } } */
diff --git gcc/testsuite/gcc.dg/dump-ada-spec/dump-ada-spec-2.h 
gcc/testsuite/gcc.dg/dump-ada-spec/dump-ada-spec-2.h
new file mode 100644
index 0000000..663fa96
--- /dev/null
+++ gcc/testsuite/gcc.dg/dump-ada-spec/dump-ada-spec-2.h
@@ -0,0 +1,8 @@
+/* { dg-do assemble } */
+/* { dg-options "-fdump-ada-spec" } */
+
+extern void foo (void);
+
+/* { dg-final { file-exists-not "dump-ada-spec-2.s" } } */
+/* { dg-final { file-exists-not "dump-ada-spec-2.o" } } */
+/* { dg-final { file-exists-not "dump-ada-spec-2.gch" } } */
diff --git gcc/testsuite/gcc.dg/dump-ada-spec/dump-ada-spec.exp 
gcc/testsuite/gcc.dg/dump-ada-spec/dump-ada-spec.exp
new file mode 100644
index 0000000..efd9acb
--- /dev/null
+++ gcc/testsuite/gcc.dg/dump-ada-spec/dump-ada-spec.exp
@@ -0,0 +1,36 @@
+#   Copyright (C) 1997-2014 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 Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Load support procs.
+load_lib gcc-dg.exp
+
+# If a testcase doesn't have special options, use these.
+global DEFAULT_CFLAGS
+if ![info exists DEFAULT_CFLAGS] then {
+    set DEFAULT_CFLAGS " -ansi -pedantic-errors"
+}
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[ch\]]] \
+       "" $DEFAULT_CFLAGS
+
+# All done.
+dg-finish
diff --git gcc/testsuite/lib/gcc-dg.exp gcc/testsuite/lib/gcc-dg.exp
index a758d47..dbb1080 100644
--- gcc/testsuite/lib/gcc-dg.exp
+++ gcc/testsuite/lib/gcc-dg.exp
@@ -669,6 +669,28 @@ proc scan-module-absence { args } {
     }
 }
 
+# Verify that some file exists, invoked via dg-final.
+proc file-exists { filename } {
+    set testcase [testname-for-summary]
+
+    if [file exists $filename] {
+       pass "$testcase file-exists $filename"
+    } else {
+       fail "$testcase file-exists $filename"
+    }
+}
+
+# Verify that some file does not exist, invoked via dg-final.
+proc file-exists-not { filename } {
+    set testcase [testname-for-summary]
+
+    if [file exists $filename] {
+       fail "$testcase file-exists $filename"
+    } else {
+       pass "$testcase file-exists $filename"
+    }
+}
+
 # Verify that the compiler output file exists, invoked via dg-final.
 proc output-exists { args } {
     # Process an optional target or xfail list.

Reply via email to