Bug 18819 - [4.2/4.3 regression] ACATS cdd2a02 fail at runtime
Summary: [4.2/4.3 regression] ACATS cdd2a02 fail at runtime
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 4.0.0
: P5 normal
Target Milestone: 4.2.0
Assignee: Eric Botcazou
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2004-12-03 22:21 UTC by Laurent GUERBY
Modified: 2007-02-21 23:04 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-02-15 10:09:18


Attachments
Patch for miscompilation on s390x. (1.06 KB, patch)
2006-01-22 11:44 UTC, Eric Botcazou
Details | Diff
Other patch for miscompilation on s390x. (471 bytes, patch)
2006-01-22 16:31 UTC, Eric Botcazou
Details | Diff
Reduced testcase. (287 bytes, text/plain)
2006-03-07 18:33 UTC, Eric Botcazou
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Laurent GUERBY 2004-12-03 22:21:42 UTC
Happens both on x86 and x86_64, no analysis yet.

,.,. CDD2A02 ACATS 2.5 04-12-03 22:31:47
---- CDD2A02 Check that the Read, Write, Input, and Output attributes
                are inherited for untagged derived types.
   * CDD2A02 Inherited Input and Output are not inverses of each other -
                4.
**** CDD2A02 FAILED ****************************.
Comment 1 Andrew Pinski 2004-12-07 18:54:55 UTC
Does this happen at -O0 and -O2?
Comment 2 Laurent GUERBY 2004-12-07 19:34:54 UTC
It fails only at -O2, it pass at -O0 on x86, x86_64 and ia64.
Comment 3 Eric Botcazou 2005-02-17 16:45:37 UTC
Confirmed as of today on x86.
Comment 4 Eric Botcazou 2005-02-17 16:46:14 UTC
Investigating.
Comment 5 Eric Botcazou 2005-02-18 12:27:57 UTC
It's SRA again, but the problem really originates in the FE's type frobbing with
VIEW_CONVERT_EXPR and the like.  I think we should consider disabling SRA for
the Ada compiler until this mess is sorted out.
Comment 6 Laurent GUERBY 2005-02-19 18:27:42 UTC
I confirm the test PASS with -O2 -fno-tree-sra on x86 and x86_64-linux.
Comment 7 GCC Commits 2005-04-07 06:51:45 UTC
Subject: Bug 18819

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	ebotcazou@gcc.gnu.org	2005-04-07 06:51:30

Modified files:
	gcc            : ChangeLog 
	gcc/doc        : invoke.texi 
	gcc/ada        : ChangeLog misc.c 

Log message:
	PR ada/18659
	PR ada/18819
	ada/
	* misc.c (tree_sra_requested): New global.
	(gnat_init_options): Detect -ftree-sra.
	(gnat_post_options): Enable Tree-SRA only if specifically requested.
	gcc/
	* doc/invoke.texi (Optimize Options): Document that
	-ftree-sra is not automatically enabled for the Ada compiler.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.144&r2=2.7592.2.145
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doc/invoke.texi.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.583.2.9&r2=1.583.2.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.638.4.10&r2=1.638.4.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/misc.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.96.6.1&r2=1.96.6.2

Comment 8 Eric Botcazou 2005-04-07 06:57:14 UTC
It only fails on mainline now.
Comment 9 Laurent GUERBY 2005-06-11 23:19:56 UTC
Still failing as of 4.1.0 Fri Jun 10 20:07:24 UTC 2005 on x86_64-linux.
Comment 10 Mark Mitchell 2005-08-22 02:25:43 UTC
Ada is not release-critical.
Comment 11 Eric Botcazou 2005-11-22 10:25:44 UTC
Investigating again.
Comment 12 Eric Botcazou 2005-12-15 13:29:30 UTC
Subject: Bug 18819

Author: ebotcazou
Date: Thu Dec 15 13:29:14 2005
New Revision: 108576

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=108576
Log:
2005-12-15  Eric Botcazou  <ebotcazou@adacore.com>

	PR ada/18659
	PR ada/18819
ada/
	* misc.c (tree_sra_requested): New global.
	(gnat_init_options): Detect -ftree-sra.
	(gnat_post_options): Enable Tree-SRA only if specifically requested.

gcc/
	* doc/invoke.texi (Optimize Options): Document that
	-ftree-sra is not automatically enabled for the Ada compiler.


Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/ada/ChangeLog
    branches/gcc-4_1-branch/gcc/ada/misc.c
    branches/gcc-4_1-branch/gcc/doc/invoke.texi

Comment 13 Laurent GUERBY 2006-01-17 19:02:37 UTC
http://gcc.gnu.org/ml/gcc-testresults/2006-01/msg00663.html

cdda01 fails on s390-linux on 4.1 with tree-sra disabled.

,.,. CDD2A01 ACATS 2.5 06-01-16 19:32:21
---- CDD2A01 Check that the Read and Write attributes for a type
                extension are created from the parent type's attribute
                (which may be user-defined) and those for the extension 
                components; also check that the default input and output
                attributes are used for a type extension, even if the
                parent type's attribute is user-defined.

raised CONSTRAINT_ERROR : fdd2a00.adb:29 range check failed
FAIL:	cdd2a01

,.,. CDD2A02 ACATS 2.5 06-01-16 19:32:25
---- CDD2A02 Check that the Read, Write, Input, and Output attributes
                are inherited for untagged derived types.

raised CONSTRAINT_ERROR : fdd2a00.adb:29 range check failed
FAIL:	cdd2a02
Comment 14 Ulrich Weigand 2006-01-20 18:39:02 UTC
Some additional details about the s390x failure.  This is caused by a
miscompile of the fdd2a00__write__2 support routine:

        lg      %r4,168(%r15)   # 35    *movdi_64/8     [length = 6]
        lg      %r3,160(%r15)   # 36    *movdi_64/8     [length = 6]
        cgr     %r4,%r3 # 37    *cmpdi_ccs/1    [length = 4]
        stg     %r2,168(%r15)   # 33    *movdi_64/9     [length = 6]

Note how insn 35 reads a stack slot that is uninitialized because
insn 33 has been scheduled later.  This is apparently caused by
an alias set issue.  The code at the .t97.final_cleanup level reads:

  A.63 = system__arith_64__add_with_ovflo_check (D.1421, D.1426);
  R38b = (ada__streams__Tstream_element_offsetB *) &A.63;

where the data type of A.63 is system__arith_64__int64.

This gets expanded into

(insn 32 31 33 3 (set (reg:DI 60)
        (reg:DI 2 %r2)) -1 (nil)
    (nil))

(insn 33 32 34 3 (set (mem/c/i:DI (plus:DI (reg/f:DI 39 virtual-stack-vars)
                (const_int -8 [0xfffffffffffffff8])) [26 A.63+0 S8 A64])
        (reg:DI 60)) -1 (nil)
    (nil))

(insn 34 33 35 3 (parallel [
            (set (reg:DI 43 [ R38b ])
                (plus:DI (reg/f:DI 39 virtual-stack-vars)
                    (const_int -8 [0xfffffffffffffff8])))
            (clobber (reg:CC 33 %cc))
        ]) -1 (nil)
    (nil))

(insn 35 34 36 3 (set (reg:DI 48 [ D.1430 ])
        (mem:DI (reg:DI 43 [ R38b ]) [27 S8 A64])) -1 (nil)
    (nil))

Note alias set 26 in insn 33 vs. alias set 27 in insn 35.

Any ideas why this would be the case?
Comment 15 Laurent GUERBY 2006-01-21 09:32:13 UTC
4.2 fails on amd64-linux as of Fri Jan 20 20:40:28 UTC 2006 (revision 110036)
http://gcc.gnu.org/ml/gcc-testresults/2006-01/msg01071.html

RUN cdd2a02
,.,. CDD2A02 ACATS 2.5 06-01-23 01:01:16
---- CDD2A02 Check that the Read, Write, Input, and Output attributes
                are inherited for untagged derived types.
   * CDD2A02 Inherited Input and Output are not inverses of each other -
                4.
**** CDD2A02 FAILED ****************************.
Comment 16 Eric Botcazou 2006-01-22 10:19:37 UTC
> Any ideas why this would be the case?

The types are not supposed to alias each other.  The lines in the .dg file are:

      R8b : fdd2a00__write__A7b__2 := 
        ada__streams__Tstream_element_offsetB?(
        system__arith_64__add_with_ovflo_check (interfaces__integer_64
        ?(stream.last), interfaces__integer_64?(
        ada__streams__Tstream_element_offsetB(item'length))))'reference;
      [constraint_error when R8b.all >= R5b.all and then (R5b.all < 
        1 or else R8b.all > ada__streams__Tstream_element_offsetB(R3b)) "range check failed"]

ada/trans.c:3053

    case N_Reference:
      /* Like 'Access as far as we are concerned.  */
      gnu_result = gnat_to_gnu (Prefix (gnat_node));
      gnu_result = build_unary_op (ADDR_EXPR, NULL_TREE, gnu_result);
      gnu_result_type = get_unpadded_type (Etype (gnat_node));
      break;

These N_Reference nodes are an endless source of problems because they cause gigi to take the address of objects that are not aliased.  We have been working towards eliminating them as much as possible by using renaming instead; this case (check on the result of a function call) is probably the most delicate one.

No real solution as of this writing, only a poor workaround: not compiling the support files with -gnato (overflow checks).
Comment 17 Eric Botcazou 2006-01-22 11:43:01 UTC
> No real solution as of this writing, only a poor workaround: not compiling the
> support files with -gnato (overflow checks).

Well, I may have spoken too soon. :-)  We are calling Remove_Side_Effects on:

N_Type_Conversion (Node_Id=1679) (analyzed)
 Rewritten: original node = N_Op_Add "Oadd" (Node_Id=39499)
 Parent = N_Range (Node_Id=1681)
 Sloc = 7611  fdd2a00.adb:6:38
 Etype = N_Defining_Identifier "Tstream_element_offsetB" (Entity_Id=2017)
 Subtype_Mark = N_Identifier "Tstream_element_offsetB" (Node_Id=39497)
 Expression = N_Function_Call (Node_Id=39496)
 Conversion_OK = True

It turns out that the fix is already present in the front-end, but inhibited:

      --  If this is a type conversion, leave the type conversion and remove
      --  the side effects in the expression. This is important in several
      --  circumstances: for change of representations, and also when this
      --  is a view conversion to a smaller object, where gigi can end up
      --  creating its own temporary of the wrong size.

      --  ??? this transformation is inhibited for elementary types that are
      --  not involved in a change of representation because it causes
      --  regressions that are not fully understood yet.

      elsif Nkind (Exp) = N_Type_Conversion
        and then (not Is_Elementary_Type (Underlying_Type (Exp_Type))
                   or else Nkind (Parent (Exp)) = N_Assignment_Statement)
      then
         Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
         Scope_Suppress := Svg_Suppress;
         return;

However, another possible fix is to make a copy when we know we will not be able to use a renaming.  Tentative patch to be attached.
Comment 18 Eric Botcazou 2006-01-22 11:44:03 UTC
Created attachment 10701 [details]
Patch for miscompilation on s390x.
Comment 19 Eric Botcazou 2006-01-22 16:31:48 UTC
Created attachment 10706 [details]
Other patch for miscompilation on s390x.
Comment 20 Eric Botcazou 2006-01-22 22:29:49 UTC
Comment on attachment 10701 [details]
Patch for miscompilation on s390x.

Probably too gross.
Comment 21 charlet@adacore.com 2006-01-23 15:12:44 UTC
Subject: Re:  [4.1/4.2 Regression] ACATS cdd2a01 cdd2a02 fail at runtime

> No real solution as of this writing, only a poor workaround: not compiling the
> support files with -gnato (overflow checks).

That's not really an option, since these files must be compiled with
-gnato (well at least report.adb) for proper operation of some ACATS tests.

Arno
Comment 22 Eric Botcazou 2006-01-23 15:15:28 UTC
> That's not really an option, since these files must be compiled with
> -gnato (well at least report.adb) for proper operation of some ACATS tests.

Agreed.  Can I install the front-end fix on the 4.1 branch then?
Comment 23 Eric Botcazou 2006-01-25 14:07:11 UTC
Subject: Bug 18819

Author: ebotcazou
Date: Wed Jan 25 14:06:59 2006
New Revision: 110213

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110213
Log:
	PR ada/18819
	* exp_util.adb (Remove_Side_Effects): Lift enclosing type conversion
	nodes for elementary types in all cases.


Modified:
    branches/gcc-4_1-branch/gcc/ada/ChangeLog
    branches/gcc-4_1-branch/gcc/ada/exp_util.adb

Comment 24 Eric Botcazou 2006-01-25 14:08:46 UTC
Should be fixed on 4.1 branch.
Comment 25 Ulrich Weigand 2006-01-25 18:03:01 UTC
Yes, the patch fixes the problem on s390x.

Thanks!
Comment 26 Arnaud Charlet 2006-02-15 09:40:17 UTC
Subject: Bug 18819

Author: charlet
Date: Wed Feb 15 09:40:13 2006
New Revision: 111069

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=111069
Log:
2006-02-13  Ed Schonberg  <schonberg@adacore.com>
	    Javier Miranda  <miranda@adacore.com>
	    Eric Botcazou  <ebotcazou@adacore.com>

	* exp_util.ads, exp_util.adb (Find_Prim_Op,
	Is_Predefined_Primitive_Operation): When
	searching for the predefined equality operator, verify that operands
	have the same type.
	(Is_Predefined_Dispatching_Operation): Remove the code that looks
	for the last entity in the list of aliased subprograms. This code
	was wrong in case of renamings.
	(Set_Renamed_Subprogram): New procedure
	(Remove_Side_Effects): Replace calls to Etype (Exp) with use of the
	Exp_Type constant computed when entering this subprogram.
	(Known_Null): New function
	(OK_To_Do_Constant_Replacement): New function
	(Known_Non_Null): Check scope before believing Is_Known_Non_Null flag
	(Side_Effect_Free): An attribute reference 'Input is not free of
	side effect, unlike other attributes that are functions. (from code
	reading).
	(Remove_Side_Effects): Expressions that involve packed arrays or records
	are copied at the point of reference, and therefore must be marked as
	renamings of objects.
	(Is_Predefined_Dispatching_Operation): Return false if the operation is
	not a dispatching operation.

	PR ada/18819
	(Remove_Side_Effects): Lift enclosing type conversion nodes for
	elementary types in all cases.


Modified:
    trunk/gcc/ada/exp_util.adb
    trunk/gcc/ada/exp_util.ads

Comment 27 Eric Botcazou 2006-02-15 10:09:18 UTC
Back to the original problem, purely related to SRA.
Comment 28 Eric Botcazou 2006-02-15 10:23:39 UTC
Richard, it's the only remaining failure in ACATS on most platforms: the bad interaction between SRA and aggregates under certain circumstances.  Do you know what amount of work would be required to properly get rid of it?
Comment 29 Richard Kenner 2006-02-15 12:57:27 UTC
Subject: Re:   [4.2 Regression] ACATS cdd2a02 fail at runtime

    Richard, it's the only remaining failure in ACATS on most platforms:
    the bad interaction between SRA and aggregates under certain
    circumstances.  Do you know what amount of work would be required to
    properly get rid of it?

Is this the one with extension records that rename a discriminant?  If so,
the fix involves the front end materializing fields that don't semantically
exist for the purposes of listing all fields in the record.
Comment 30 Eric Botcazou 2006-02-15 17:12:05 UTC
> Is this the one with extension records that rename a discriminant?  If so,
> the fix involves the front end materializing fields that don't semantically
> exist for the purposes of listing all fields in the record.

Yes, that's it.  Is a front-end specialist working on that or...?
Comment 31 Richard Kenner 2006-02-15 17:14:28 UTC
Subject: Re:   [4.2 Regression] ACATS cdd2a02 fail at runtime

    Yes, that's it.  Is a front-end specialist working on that or...?

Nope.  I spoke to Ed S. about it a while ago and he wasn't too enthusiastic
about the idea.  Why don't you make a small test case and let's take it
from there.
Comment 32 Eric Botcazou 2006-03-07 18:33:30 UTC
Created attachment 10984 [details]
Reduced testcase.
Comment 33 Christian Joensson 2007-02-20 13:11:53 UTC
(In reply to comment #32)
> Created an attachment (id=10984) [edit]
> Reduced testcase.
> 

any news?
Comment 34 Eric Botcazou 2007-02-20 13:13:47 UTC
> any news?

The patch has been written at AdaCore.  I'll try to dig it out.
Comment 35 Eric Botcazou 2007-02-21 22:58:55 UTC
Subject: Bug 18819

Author: ebotcazou
Date: Wed Feb 21 22:58:44 2007
New Revision: 122208

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122208
Log:
	PR ada/18819
	* sem_ch3.adb (Create_Constrained_Components): for a subtype of an
	untagged derived type, add hidden components to keep discriminant
	layout consistent, when a given discriminant of the derived type
	constraints several discriminants of the parent type.


Added:
    trunk/gcc/testsuite/gnat.dg/derived_aggregate.adb
Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/sem_ch3.adb
    trunk/gcc/testsuite/ChangeLog

Comment 36 Eric Botcazou 2007-02-21 23:00:17 UTC
Subject: Bug 18819

Author: ebotcazou
Date: Wed Feb 21 23:00:01 2007
New Revision: 122209

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122209
Log:
	PR ada/18819
	* sem_ch3.adb (Create_Constrained_Components): for a subtype of an
	untagged derived type, add hidden components to keep discriminant
	layout consistent, when a given discriminant of the derived type
	constraints several discriminants of the parent type.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gnat.dg/derived_aggregate.adb
Modified:
    branches/gcc-4_2-branch/gcc/ada/ChangeLog
    branches/gcc-4_2-branch/gcc/ada/sem_ch3.adb
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 37 Eric Botcazou 2007-02-21 23:04:14 UTC
At long last.