The problem in this PR is that -fself-test is being run on a non empty source file. This causes init_emit() to run, which sets:

        REG_POINTER (virtual_incoming_args_rtx) = 1;

Setting REG_POINTER on the virtual incoming args, causes /f to be printed on some RTL dumps, causing the -fself-test machinery to fail at matching the expected value.

It looks that by design -fself-test is meant to be run before any initialization like the aforementioned runs.

We could error/fail when running -fself-test on a non-empty file, but I think we can just enable -fsyntax-only and get the same result. After all, this is an undocumented internal option.

BTW, this is being triggered on aarch64, but will likely show up in different ports in different ways.

OK for trunk?
commit f5d7bfbdae2f74d3b98a81e1f3ee7b9b24c8f3be
Author: Aldy Hernandez <al...@redhat.com>
Date:   Fri Nov 11 06:32:08 2016 -0800

        PR target/78213
        * opts.c (common_handle_option): Set -fsyntax-only if running self
        tests.

diff --git a/gcc/opts.c b/gcc/opts.c
index d2d6100..35357bd 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1770,6 +1770,16 @@ common_handle_option (struct gcc_options *opts,
       opts->x_exit_after_options = true;
       break;
 
+    case OPT_fself_test:
+      /* -fself-test depends on the state of the compiler prior to
+         compiling anything.  Ideally it should be run on an empty
+         source file.  However, in case we get run with actual source,
+         assume -fsyntax-only which will inhibit any compiler
+         initialization which may confuse the self tests.  */
+      if (lang_mask != CL_DRIVER)
+       flag_syntax_only = 1;
+      break;
+
     case OPT_fsanitize_:
       opts->x_flag_sanitize
        = parse_sanitizer_options (arg, loc, code,
diff --git a/gcc/testsuite/gcc.dg/pr78213.c b/gcc/testsuite/gcc.dg/pr78213.c
new file mode 100644
index 0000000..b262fa1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr78213.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fself-test" } */
+
+/* Verify that -fself-test does not fail on a non empty source.  */
+
+int i;                                                                         
 void bar();                                                                    
 void foo()
+{
+  while (i--)
+    bar();
+}

Reply via email to