public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2596] d: Remove generated D header files on error (PR101657)
@ 2021-07-29 15:12 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2021-07-29 15:12 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:75f2e3f6cbbb79421b12e399498e9c14241359e7

commit r12-2596-g75f2e3f6cbbb79421b12e399498e9c14241359e7
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Jul 26 17:24:38 2021 +0200

    d: Remove generated D header files on error (PR101657)
    
    If an error occurs later during compilation, remember that we generated
    the headers, so that they can be removed before exit.
    
            PR d/101657
    
    gcc/d/ChangeLog:
    
            * d-lang.cc (d_parse_file): Remove generated D header files on error.
    
    gcc/testsuite/ChangeLog:
    
            * gdc.dg/pr101657.d: New test.

Diff:
---
 gcc/d/d-lang.cc                 | 19 +++++++++++++++++++
 gcc/testsuite/gdc.dg/pr101657.d | 14 ++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 6ad3823d910..ac0945b1f34 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1000,6 +1000,10 @@ d_parse_file (void)
 	}
     }
 
+  /* If an error occurs later during compilation, remember that we generated
+     the headers, so that they can be removed before exit.  */
+  bool dump_headers = false;
+
   if (global.errors)
     goto had_errors;
 
@@ -1019,6 +1023,8 @@ d_parse_file (void)
 
 	  genhdrfile (m);
 	}
+
+      dump_headers = true;
     }
 
   if (global.errors)
@@ -1243,6 +1249,19 @@ d_parse_file (void)
      exit with an error status.  */
   errorcount += (global.errors + global.warnings);
 
+  /* Remove generated .di files on error.  */
+  if (errorcount && dump_headers)
+    {
+      for (size_t i = 0; i < modules.length; i++)
+	{
+	  Module *m = modules[i];
+	  if (d_option.fonly && m != Module::rootModule)
+	    continue;
+
+	  remove (m->hdrfile->toChars ());
+	}
+    }
+
   /* Write out globals.  */
   d_finish_compilation (vec_safe_address (global_declarations),
 			vec_safe_length (global_declarations));
diff --git a/gcc/testsuite/gdc.dg/pr101657.d b/gcc/testsuite/gdc.dg/pr101657.d
new file mode 100644
index 00000000000..0d77c36f030
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr101657.d
@@ -0,0 +1,14 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101657
+// { dg-do compile }
+// { dg-additional-options "-H" }
+
+void fun101657()
+{
+    fail; // { dg-error "undefined identifier 'fail'" }
+}
+
+// { dg-final { if ![file exists pr101657.di] \{                } }
+// { dg-final {     pass "gdc.dg/pr101657.d   (file exists pr101657.di)" } }
+// { dg-final { \} else \{                                      } }
+// { dg-final {     fail "gdc.dg/pr101657.d   (file exists pr101657.di)" } }
+// { dg-final { \}                                              } }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-29 15:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 15:12 [gcc r12-2596] d: Remove generated D header files on error (PR101657) Iain Buclaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).