[PR,target/78213] Do not ICE on non-empty -fself-test
diff mbox

Message ID 30f92496-eb64-3a75-9cb8-9d1e4d440920@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez Nov. 16, 2016, 10:45 a.m. UTC
On 11/14/2016 08:18 AM, Bernd Schmidt wrote:
> On 11/11/2016 06:10 PM, Aldy Hernandez wrote:
>> 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.
>
> How about always running init_emit and testing for the correct output?

I would prefer Jakub's suggestion of running in finish_options().

I assume there are other places throughout the self-tests that depend on 
NOT continuing the compilation process, and I'd hate to plug each one.

Would the attached patch be acceptable to both of you?

Aldy
commit 52b906160a109b84a26f5aa15a653f4aee612942
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Fri Nov 11 06:32:08 2016 -0800

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

Comments

Bernd Schmidt Nov. 22, 2016, 4:41 p.m. UTC | #1
On 11/16/2016 11:45 AM, Aldy Hernandez wrote:

> I would prefer Jakub's suggestion of running in finish_options().

I suspect we'll want both. Selftests should really run in an environment 
that's as close as possible to what would normally be going on in the 
compiler.

> I assume there are other places throughout the self-tests that depend on
> NOT continuing the compilation process, and I'd hate to plug each one.
>
> Would the attached patch be acceptable to both of you?

Good enough for now.


Bernd

Patch
diff mbox

diff --git a/gcc/opts.c b/gcc/opts.c
index d2d6100..cb20154 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -744,6 +744,14 @@  finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
       opts->x_flag_toplevel_reorder = 0;
     }
 
+  /* -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 (opts->x_flag_self_test)
+    opts->x_flag_syntax_only = 1;
+
   if (opts->x_flag_tm && opts->x_flag_non_call_exceptions)
     sorry ("transactional memory is not supported with non-call exceptions");
 
diff --git a/gcc/testsuite/gcc.dg/pr78213.c b/gcc/testsuite/gcc.dg/pr78213.c
new file mode 100644
index 0000000..e43c83c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr78213.c
@@ -0,0 +1,11 @@ 
+/* { 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();
+}
+/* { dg-message "fself\-test: " "-fself-test" { target *-*-* } 0 } */