public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Iain D Sandoe <iains@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/iains/heads/d-for-darwin)] d: Don't emit normal functions and declarations when compiling with -fbuilding-libphobos-tests
Date: Mon, 11 Oct 2021 20:34:54 +0000 (GMT)	[thread overview]
Message-ID: <20211011203454.AE4C63857C75@sourceware.org> (raw)

https://gcc.gnu.org/g:f7074e857b103a6d6b5c8951d3fd4870ff33affc

commit f7074e857b103a6d6b5c8951d3fd4870ff33affc
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Thu Dec 3 23:56:16 2020 +0100

    d: Don't emit normal functions and declarations when compiling with -fbuilding-libphobos-tests

Diff:
---
 gcc/d/decl.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 0d46ee180e7..8ee674c426c 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -116,6 +116,27 @@ gcc_attribute_p (Dsymbol *decl)
   return false;
 }
 
+/* Returns true if DECL is either lexically nested inside a unittest function,
+   or a `version(unittest)' condition.  */
+
+static bool
+in_unittest_p (Declaration *decl)
+{
+  for (Dsymbol *p = decl->parent; p != NULL; p = p->parent)
+    {
+      if (p->isUnitTestDeclaration ())
+	return true;
+      if (FuncDeclaration *fd = p->isFuncDeclaration ())
+	{
+	  tree t = get_symbol_decl (fd);
+	  if (DECL_IN_UNITTEST_CONDITION_P (t))
+	    return true;
+	}
+    }
+
+  return false;
+}
+
 /* Implements the visitor interface to lower all Declaration AST classes
    emitted from the D Front-end to GCC trees.
    All visit methods accept one parameter D, which holds the frontend AST
@@ -655,6 +676,16 @@ public:
       }
     else if (d->isDataseg () && !(d->storage_class & STCextern))
       {
+	/* For libphobos-internal use only.  When compiling unittests, only
+	   generate code for unittest or instantiated variables.  */
+	if (flag_building_libphobos_tests)
+	  {
+	    if (!this->in_version_unittest_
+		&& !in_unittest_p (d)
+		&& !d->isInstantiated ())
+	      return;
+	  }
+
 	tree decl = get_symbol_decl (d);
 
 	/* Duplicated VarDeclarations map to the same symbol.  Check if this
@@ -767,6 +798,20 @@ public:
     if (!global.params.useUnitTests && d->isUnitTestDeclaration ())
       return;
 
+    /* For libphobos-internal use only.  When compiling unittests, only
+       generate code for unittest or instantiated functions.  */
+    if (flag_building_libphobos_tests)
+      {
+	if (!d->isUnitTestDeclaration ()
+	    && !this->in_version_unittest_
+	    && !in_unittest_p (d)
+	    && !d->isArrayOp
+	    && !d->isInstantiated ()
+	    && !d->isMain ()
+	    && !d->isCMain ())
+	  return;
+      }
+
     /* Check if any errors occurred when running semantic.  */
     if (TypeFunction *tf = d->type->isTypeFunction ())
       {


             reply	other threads:[~2021-10-11 20:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11 20:34 Iain D Sandoe [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-10-18 15:53 Iain D Sandoe
2021-10-15 19:33 Iain D Sandoe
2021-10-13  8:30 Iain D Sandoe
2020-12-21 20:36 Iain D Sandoe
2020-12-13 17:43 Iain D Sandoe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211011203454.AE4C63857C75@sourceware.org \
    --to=iains@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).