diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2019-04-12 06:25:04 +0000 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gcc.gnu.org> | 2019-04-12 06:25:04 +0000 |
commit | c50eadba265a0e9b3b84267477f953d0d5872522 (patch) | |
tree | adebd7495b2b5b33202ade4920313cb8e4c79318 /gcc/d/decl.cc | |
parent | 77f4fb57664b93b49257699ddb48182f6dc6a60a (diff) | |
download | gcc-c50eadba265a0e9b3b84267477f953d0d5872522.zip gcc-c50eadba265a0e9b3b84267477f953d0d5872522.tar.gz gcc-c50eadba265a0e9b3b84267477f953d0d5872522.tar.bz2 |
d: Add -fbuilding-libphobos-tests option
Currently, the druntime and phobos unittests are compiled as a separate
check program, then ran by the libphobos.unittest/unittest.exp script.
As PR d/89255 notes, this process lacks proper multilib handling.
As a first step, a new internal option that instructs the compiler to
put the reference to all unittest functions in another symbol has been
added. This will allow each module to be compiled separately as a
standalone program using dg-runtest without running into collisions in
the D runtime module registry.
gcc/d/ChangeLog:
2019-04-12 Iain Buclaw <ibuclaw@gdcproject.org>
* d-tree.h (DECL_IN_UNITTEST_CONDITION_P): Define.
* decl.cc (DeclVisitor): Add in_version_unittest_ field.
(DeclVisitor::visit(ConditionalDeclaration)): New override.
(DeclVisitor::visit(FuncDeclaration)): Set
DECL_IN_UNITTEST_CONDITION_P.
* lang.opt (-fbuilding-libphobos-tests): Add option.
* modules.cc (current_testing_module): New static variable.
(build_module_tree): Generate second moduleinfo symbol to hold
reference to unittests if flag_building_libphobos_tests.
(register_module_decl): Check DECL_IN_UNITTEST_CONDITION_P to decide
which moduleinfo the decl should be registered against.
From-SVN: r270301
Diffstat (limited to 'gcc/d/decl.cc')
-rw-r--r-- | gcc/d/decl.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index fffed97..f6c8639 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "dmd/aggregate.h" #include "dmd/attrib.h" +#include "dmd/cond.h" #include "dmd/ctfe.h" #include "dmd/declaration.h" #include "dmd/enum.h" @@ -121,9 +122,13 @@ class DeclVisitor : public Visitor { using Visitor::visit; + /* If we're lowering the body of a version(unittest) condition. */ + bool in_version_unittest_; + public: DeclVisitor (void) { + this->in_version_unittest_ = false; } /* This should be overridden by each declaration class. */ @@ -241,6 +246,25 @@ public: visit ((AttribDeclaration *) d); } + /* Conditional compilation is the process of selecting which code to compile + and which code to not compile. Look for version conditions that may */ + + void visit (ConditionalDeclaration *d) + { + bool old_condition = this->in_version_unittest_; + + if (global.params.useUnitTests) + { + VersionCondition *vc = d->condition->isVersionCondition (); + if (vc && vc->ident == Identifier::idPool ("unittest")) + this->in_version_unittest_ = true; + } + + visit ((AttribDeclaration *) d); + + this->in_version_unittest_ = old_condition; + } + /* Walk over all members in the namespace scope. */ void visit (Nspace *d) @@ -868,6 +892,7 @@ public: } DECL_ARGUMENTS (fndecl) = param_list; + DECL_IN_UNITTEST_CONDITION_P (fndecl) = this->in_version_unittest_; rest_of_decl_compilation (fndecl, 1, 0); /* If this is a member function that nested (possibly indirectly) in another |