Support C++-specific selftests
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 6 Jul 2017 15:49:37 +0000 (15:49 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Thu, 6 Jul 2017 15:49:37 +0000 (15:49 +0000)
gcc/ChangeLog:
* Makefile.in (SELFTEST_FLAGS): Drop "-x c", moving it to...
(C_SELFTEST_FLAGS): New.
(CPP_SELFTEST_FLAGS): New.
(SELFTEST_DEPS): New, from deps of s-selftest.
(C_SELFTEST_DEPS): New, from deps of s-selftest.
(CPP_SELFTEST_DEPS): New.
(selftest): Add dependency on s-selftest-c++.
(s-selftest): Rename to...
(s-selftest-c): ...this, moving deps to SELFTEST_DEPS
and C_SELFTEST_DEPS, and using C_SELFTEST_FLAGS rather
than SELFTEST_FLAGS.
(selftest-gdb): Rename to...
(selftest-c-gdb): ...this, using C_SELFTEST_DEPS and
C_SELFTEST_FLAGS.
(selftest-gdb): Reintroduce as an alias for selftest-c-gdb.
(selftest-valgrind): Rename to...
(selftest-c-valgrind): ...this, using C_SELFTEST_DEPS and
C_SELFTEST_FLAGS.
(selftest-valgrind): Reintroduce as an alias for
selftest-c-valgrind.
(s-selftest-c++): New.
(selftest-c++-gdb): New.
(selftest-c++-valgrind): New.

gcc/c-family/ChangeLog:
* c-common.c (selftest::c_family_tests): New.
* c-common.h (selftest::run_c_tests): Move decl to c/c-lang.h.
(selftest::c_family_tests): New decl.

gcc/c/ChangeLog:
* c-lang.c (selftest::run_c_tests): Move body to c_family_tests,
and call that instead.
* c-tree.h (selftest::run_c_tests): New decl.

gcc/cp/ChangeLog:
* cp-lang.c (LANG_HOOKS_RUN_LANG_SELFTESTS): Define as
selftest::run_cp_tests.
(selftest::run_cp_tests): New function.
* cp-tree.h (selftest::run_cp_tests): New decl.

From-SVN: r250030

gcc/ChangeLog
gcc/Makefile.in
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c-family/c-common.h
gcc/c/ChangeLog
gcc/c/c-lang.c
gcc/c/c-tree.h
gcc/cp/ChangeLog
gcc/cp/cp-lang.c
gcc/cp/cp-tree.h

index d016a8e44cd31761bfb0df6e7c8956d6bedf9797..20fcd8213bb88e84718022052e7da4c014ca7a70 100644 (file)
@@ -1,3 +1,29 @@
+2017-07-06  David Malcolm  <dmalcolm@redhat.com>
+
+       * Makefile.in (SELFTEST_FLAGS): Drop "-x c", moving it to...
+       (C_SELFTEST_FLAGS): New.
+       (CPP_SELFTEST_FLAGS): New.
+       (SELFTEST_DEPS): New, from deps of s-selftest.
+       (C_SELFTEST_DEPS): New, from deps of s-selftest.
+       (CPP_SELFTEST_DEPS): New.
+       (selftest): Add dependency on s-selftest-c++.
+       (s-selftest): Rename to...
+       (s-selftest-c): ...this, moving deps to SELFTEST_DEPS
+       and C_SELFTEST_DEPS, and using C_SELFTEST_FLAGS rather
+       than SELFTEST_FLAGS.
+       (selftest-gdb): Rename to...
+       (selftest-c-gdb): ...this, using C_SELFTEST_DEPS and
+       C_SELFTEST_FLAGS.
+       (selftest-gdb): Reintroduce as an alias for selftest-c-gdb.
+       (selftest-valgrind): Rename to...
+       (selftest-c-valgrind): ...this, using C_SELFTEST_DEPS and
+       C_SELFTEST_FLAGS.
+       (selftest-valgrind): Reintroduce as an alias for
+       selftest-c-valgrind.
+       (s-selftest-c++): New.
+       (selftest-c++-gdb): New.
+       (selftest-c++-valgrind): New.
+
 2017-07-06  Olivier Hainque  <hainque@adacore.com>
 
        * gcc.c (process_command): When deciding if undefined variables
index a3beaad614e3c212e0f2368095bd1e3560e9e31a..2189bc00174a19fcac63df62ab5b38d2dffab51b 100644 (file)
@@ -1904,30 +1904,62 @@ rest.cross: specs
 # "nul.s" on Windows. Because on Windows "nul" is a reserved file name.
 # Specify the path to gcc/testsuite/selftests within the srcdir
 # as an argument to -fself-test.
-SELFTEST_FLAGS = -nostdinc -x c /dev/null -S -o /dev/null \
+SELFTEST_FLAGS = -nostdinc /dev/null -S -o /dev/null \
        -fself-test=$(srcdir)/testsuite/selftests
 
-# Run the selftests during the build once we have a driver and a cc1,
+C_SELFTEST_FLAGS = -xc $(SELFTEST_FLAGS)
+CPP_SELFTEST_FLAGS = -xc++ $(SELFTEST_FLAGS)
+
+SELFTEST_DEPS = $(GCC_PASSES) stmp-int-hdrs $(srcdir)/testsuite/selftests
+
+C_SELFTEST_DEPS = cc1$(exeext) $(SELFTEST_DEPS)
+CPP_SELFTEST_DEPS = cc1plus$(exeext) $(SELFTEST_DEPS)
+
+# Run the selftests during the build once we have a driver and the frontend,
 # so that self-test failures are caught as early as possible.
-# Use "s-selftest" to ensure that we only run the selftests if the
-# driver, cc1, or selftest data change.
+# Use "s-selftest-FE" to ensure that we only run the selftests if the
+# driver, frontend, or selftest data change.
 .PHONY: selftest
-selftest: s-selftest
-s-selftest: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs \
-  $(srcdir)/testsuite/selftests
-       $(GCC_FOR_TARGET) $(SELFTEST_FLAGS)
+selftest: s-selftest-c s-selftest-c++
+
+# C selftests
+s-selftest-c: $(C_SELFTEST_DEPS)
+       $(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS)
        $(STAMP) $@
 
-# Convenience method for running selftests under gdb:
-.PHONY: selftest-gdb
-selftest-gdb: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-       $(GCC_FOR_TARGET) $(SELFTEST_FLAGS) \
+# Convenience methods for running C selftests under gdb:
+.PHONY: selftest-c-gdb
+selftest-c-gdb: $(C_SELFTEST_DEPS)
+       $(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS) \
          -wrapper gdb,--args
 
-# Convenience method for running selftests under valgrind:
+.PHONY: selftest-gdb
+selftest-gdb: selftest-c-gdb
+
+# Convenience methods for running C selftests under valgrind:
+.PHONY: selftest-c-valgrind
+selftest-c-valgrind: $(C_SELFTEST_DEPS)
+       $(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS) \
+         -wrapper valgrind,--leak-check=full
+
 .PHONY: selftest-valgrind
-selftest-valgrind: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-       $(GCC_FOR_TARGET) $(SELFTEST_FLAGS) \
+selftest-valgrind: selftest-c-valgrind
+
+# C++ selftests
+s-selftest-c++: $(CPP_SELFTEST_DEPS)
+       $(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS)
+       $(STAMP) $@
+
+# Convenience method for running C++ selftests under gdb:
+.PHONY: selftest-c++-gdb
+selftest-c++-gdb: $(CPP_SELFTEST_DEPS)
+       $(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS) \
+         -wrapper gdb,--args
+
+# Convenience method for running C++ selftests under valgrind:
+.PHONY: selftest-c++-valgrind
+selftest-c++-valgrind: $(CPP_SELFTEST_DEPS)
+       $(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS) \
          -wrapper valgrind,--leak-check=full
 
 # Recompile all the language-independent object files.
index a54beee37f99adb38590ad06f560716c14bf6721..7ddf192e496dcce3ca00c41307d5f06eb502be96 100644 (file)
@@ -1,3 +1,9 @@
+2017-07-06  David Malcolm  <dmalcolm@redhat.com>
+
+       * c-common.c (selftest::c_family_tests): New.
+       * c-common.h (selftest::run_c_tests): Move decl to c/c-lang.h.
+       (selftest::c_family_tests): New decl.
+
 2017-07-04  Marek Polacek  <polacek@redhat.com>
 
        PR c/81231
index 1b6ac8cffa26dfea304035ec938a981fb8810c9d..b4217f3a2cca4e99a8bbbaf30dcfa364eb78cd34 100644 (file)
@@ -8003,4 +8003,20 @@ c_flt_eval_method (bool maybe_c11_only_p)
     return c_ts18661_flt_eval_method ();
 }
 
+#if CHECKING_P
+
+namespace selftest {
+
+/* Run all of the tests within c-family.  */
+
+void
+c_family_tests (void)
+{
+  c_format_c_tests ();
+}
+
+} // namespace selftest
+
+#endif /* #if CHECKING_P */
+
 #include "gt-c-family-c-common.h"
index f3d051a73a4d0b3a033d3afba93408a1663e13f7..7e7efb2916eafd43314fa98b95996348596e24ff 100644 (file)
@@ -1558,8 +1558,12 @@ extern void add_no_sanitize_value (tree node, unsigned int flags);
 
 #if CHECKING_P
 namespace selftest {
+  /* Declarations for specific families of tests within c-family,
+     by source file, in alphabetical order.  */
   extern void c_format_c_tests (void);
-  extern void run_c_tests (void);
+
+  /* The entrypoint for running all of the above tests.  */
+  extern void c_family_tests (void);
 } // namespace selftest
 #endif /* #if CHECKING_P */
 
index fabddc17d2f4e401f88b7ea735f21ca39b02df33..aba08689638ebfe1dc1d7fd5c0a4949f12ee00ce 100644 (file)
@@ -1,3 +1,9 @@
+2017-07-06  David Malcolm  <dmalcolm@redhat.com>
+
+       * c-lang.c (selftest::run_c_tests): Move body to c_family_tests,
+       and call that instead.
+       * c-tree.h (selftest::run_c_tests): New decl.
+
 2017-06-26  Marek Polacek  <polacek@redhat.com>
 
        PR c/80116
index 510b7e7de4786efa73c24c8fdccff3ce8347e7da..e05741dadbabd4c2dc12cacc416895186a219646 100644 (file)
@@ -58,7 +58,10 @@ namespace selftest {
 void
 run_c_tests (void)
 {
-  c_format_c_tests ();
+  /* Run selftests shared within the C family.  */
+  c_family_tests ();
+
+  /* Additional C-specific tests.  */
 }
 
 } // namespace selftest
index ce25fae0b877ab0f369e950096fe072ebc53759f..a8197eb768dafeca115c9d862095942a6b71e4e6 100644 (file)
@@ -764,4 +764,11 @@ extern tree decl_constant_value_for_optimization (tree);
 
 extern vec<tree> incomplete_record_decls;
 
+#if CHECKING_P
+namespace selftest {
+  extern void run_c_tests (void);
+} // namespace selftest
+#endif /* #if CHECKING_P */
+
+
 #endif /* ! GCC_C_TREE_H */
index 4dffee44f17f45e566df30b2e473c6cd84ea9b33..2617fff1dc9b5c7b4640ff6177fea112b84ea61c 100644 (file)
@@ -1,3 +1,10 @@
+2017-07-06  David Malcolm  <dmalcolm@redhat.com>
+
+       * cp-lang.c (LANG_HOOKS_RUN_LANG_SELFTESTS): Define as
+       selftest::run_cp_tests.
+       (selftest::run_cp_tests): New function.
+       * cp-tree.h (selftest::run_cp_tests): New decl.
+
 2017-07-04  Jakub Jelinek  <jakub@redhat.com>
 
        * parser.c (cp_parser_decomposition_declaration): Replace
index defcbdc79a960f4d8ccf4891e2b18f58e3f262d9..805319a4185345a33c1f26d8a3b4bb16ef058d40 100644 (file)
@@ -79,6 +79,11 @@ static tree cxx_enum_underlying_base_type (const_tree);
 #undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
 #define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE cxx_enum_underlying_base_type
 
+#if CHECKING_P
+#undef LANG_HOOKS_RUN_LANG_SELFTESTS
+#define LANG_HOOKS_RUN_LANG_SELFTESTS selftest::run_cp_tests
+#endif /* #if CHECKING_P */
+
 /* Each front end provides its own lang hook initializer.  */
 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
 
@@ -229,6 +234,25 @@ tree cxx_enum_underlying_base_type (const_tree type)
   return underlying_type;
 }
 
+#if CHECKING_P
+
+namespace selftest {
+
+/* Implementation of LANG_HOOKS_RUN_LANG_SELFTESTS for the C++ frontend.  */
+
+void
+run_cp_tests (void)
+{
+  /* Run selftests shared within the C family.  */
+  c_family_tests ();
+
+  /* Additional C++-specific tests.  */
+}
+
+} // namespace selftest
+
+#endif /* #if CHECKING_P */
+
 
 #include "gt-cp-cp-lang.h"
 #include "gtype-cp.h"
index abaef68fda967fd1dc618e3036f2f435ac60be74..50f4235e4b825fb08dfc38c97ad0b9eb6511e7fc 100644 (file)
@@ -7364,6 +7364,12 @@ extern tree cp_ubsan_maybe_instrument_downcast   (location_t, tree, tree, tree);
 extern tree cp_ubsan_maybe_instrument_cast_to_vbase (location_t, tree, tree);
 extern void cp_ubsan_maybe_initialize_vtbl_ptrs (tree);
 
+#if CHECKING_P
+namespace selftest {
+  extern void run_cp_tests (void);
+} // namespace selftest
+#endif /* #if CHECKING_P */
+
 /* Inline bodies.  */
 
 inline tree