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

Message ID 9158b0e8-f6b7-8a71-4d78-6f1b174a8405@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez Nov. 11, 2016, 5:10 p.m. UTC
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 <aldyh@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.

Comments

Jakub Jelinek Nov. 11, 2016, 5:24 p.m. UTC | #1
On Fri, Nov 11, 2016 at 09:10:48AM -0800, 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.
> 
> It looks that by design -fself-test is meant to be run before any
> initialization like the aforementioned runs.

Won't -fself-test -fno-syntax-only still crash?  I.e. wouldn't it be better
to deal with this e.g. in finish_options?  Or perhaps error out if
-fself-tests is not used with -fsyntax-only and change the Makefile to
invoke it with both options?

	Jakub
Bernd Schmidt Nov. 14, 2016, 1:18 p.m. UTC | #2
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?


Bernd
Jakub Jelinek Nov. 14, 2016, 1:20 p.m. UTC | #3
On Mon, Nov 14, 2016 at 02:18:02PM +0100, 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?

You mean only if -fself-test, right?

	Jakub
Bernd Schmidt Nov. 14, 2016, 1:25 p.m. UTC | #4
On 11/14/2016 02:20 PM, Jakub Jelinek wrote:
> On Mon, Nov 14, 2016 at 02:18:02PM +0100, 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?
>
> You mean only if -fself-test, right?

I guess.


Bernd

Patch
diff mbox

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();
+}