From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id F05093833029; Tue, 22 Dec 2020 13:40:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F05093833029 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Iain Buclaw To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/ibuclaw/heads/darwin)] d: Don't emit normal functions and declarations when compiling with -fbuilding-libphobos-tests X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/users/ibuclaw/heads/darwin X-Git-Oldrev: 5629fd368f53a181177d0a82a22ec4c0789f367e X-Git-Newrev: c77c67bf0b30e8becc9dd4bd6e6d7597e1d49ec7 Message-Id: <20201222134052.F05093833029@sourceware.org> Date: Tue, 22 Dec 2020 13:40:52 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2020 13:40:53 -0000 https://gcc.gnu.org/g:c77c67bf0b30e8becc9dd4bd6e6d7597e1d49ec7 commit c77c67bf0b30e8becc9dd4bd6e6d7597e1d49ec7 Author: Iain Buclaw 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 6df92599cb7..d3b68d5ca59 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -115,6 +115,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 @@ -666,6 +687,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 @@ -778,6 +809,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 ()) {