Bug 19334 - darwin backend places some CONST_DECLs in the wrong section
Summary: darwin backend places some CONST_DECLs in the wrong section
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Andrew Pinski
URL:
Keywords: patch, wrong-code
: 19335 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-01-08 20:05 UTC by Andrew Pinski
Modified: 2005-01-13 00:47 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc-darwin
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-01-08 20:06:57


Attachments
Putative patch (576 bytes, patch)
2005-01-08 20:47 UTC, Tobias Schlüter
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-01-08 20:05:09 UTC
integer*1 k, k2, k3, ka
      call c_i1(ISHFT(k,-BIT_SIZE(k)))
      end
      subroutine c_i1(i)
      integer*1 i
      end

Compile this at -O1 on ppc, we recieve an error message:
/usr/bin/ld: f90-intrinsic-bit.o 8 byte literal section (__TEXT,__literal8) size is not a multiple of 8 bytes
collect2: ld returned 1 exit status

If we look into the .s file, we have:
        .literal8
LC0:
        .byte   0

But that means the even though the type of the constant decl is of size one, the type of the value which 
is stored there is of size 8 which is just wrong.

I think this worked before but I could be wrong.
Comment 1 Andrew Pinski 2005-01-08 20:06:57 UTC
This is just a reduction of the "gfortran.dg/g77/f90-intrinsic-bit.f" test.
reference testresults (not from me):
http://gcc.gnu.org/ml/gcc-testresults/2005-01/msg00348.html
Comment 2 Andrew Pinski 2005-01-08 20:32:58 UTC
*** Bug 19335 has been marked as a duplicate of this bug. ***
Comment 3 Andrew Pinski 2005-01-08 20:33:50 UTC
Oh, one more thing from PR 19335, -fmerge-constants is what causes it to fail.
Comment 4 Tobias Schlüter 2005-01-08 20:47:04 UTC
Created attachment 7906 [details]
Putative patch

2005-01-08  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/19334
	* trans-intrinsic.c (gfc_conv_intrinsic_ishft): Correct type-safety
	problem.
Comment 5 Andrew Pinski 2005-01-09 02:16:18 UTC
nope, this patch did not fix it.
Comment 6 Tobias Schlüter 2005-01-09 11:56:57 UTC
Is the reduced testcase also not fixed by the patch, or is this a new issue?
Comment 7 Tobias Schlüter 2005-01-09 12:29:46 UTC
Hm,

I've instrumented the tree-dumper to print the widths and signednesses of
integer constants, i.e.
Index: tree-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-pretty-print.c,v
retrieving revision 2.52
diff -u -p -r2.52 tree-pretty-print.c
--- tree-pretty-print.c 9 Dec 2004 10:54:36 -0000       2.52
+++ tree-pretty-print.c 9 Jan 2005 12:20:44 -0000
@@ -532,6 +532,18 @@ dump_generic_node (pretty_printer *buffe
        }
       else
        pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
+
+      if (tree_int_cst_sgn (TYPE_MIN_VALUE (TREE_TYPE (node))) < 0)
+       {
+         /* signed type.  */
+         pp_string (buffer, "_S");
+       }
+      else
+       {
+         /* unsigned type.  */
+         pp_string (buffer, "_U");
+       }
+      pp_wide_integer (buffer, TYPE_PRECISION (TREE_TYPE (node)));
       break;

     case REAL_CST:

now for gfortran both with and without my patch I get:
[tobi@marktplatz tests]$ cat pr19334.f90.t02.original
MAIN__ ()
{
  int1 k;

  {
    int1 C.454 = 0_S8;

    c_i1 (&C.454);
  }
}


c_i1 (i)
{
  (void) 0_U32;


which looks correct.  The same goes for the optimized dump:
[tobi@marktplatz tests]$ cat pr19334.f90.t63.optimized

;; Function MAIN__ (MAIN__)

Analyzing Edge Insertions.
MAIN__ ()
{
  int1 C.454 = 0_S8;
  int1 k;

<bb 0>:
  c_i1 (&C.454);
  return;

}



;; Function c_i1 (c_i1__)

Analyzing Edge Insertions.
c_i1 (i)
{
<bb 0>:
  return;

}


Maybe this is an optimizer issue? Or is there something else I should be looking
for?
Comment 8 Tobias Schlüter 2005-01-09 12:30:27 UTC
also, I'm on i686, which could be making a difference even though it shouldn't
at this stage.
Comment 9 Andrew Pinski 2005-01-09 15:29:49 UTC
  int1 C.454 = 0_S8;

The 8 is where the problem is, it is just plainly wrong, it should be 1.
Comment 10 Tobias Schlüter 2005-01-09 15:36:27 UTC
Subject: Re:  ISHFT has the wrong type for constant values

pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-09 15:29 -------
>   int1 C.454 = 0_S8;
> 
> The 8 is where the problem is, it is just plainly wrong, it should be 1.
> 
8 bits, unless I'm completely mistaken.
Comment 11 Andrew Pinski 2005-01-09 15:47:04 UTC
Then this must be a target bug, I will look into it.
Comment 12 Francois-Xavier Coudert 2005-01-09 16:50:59 UTC
Reduced case (from FP19335) still fails on powerpc-darwin with Tobias' patch.
The output from gfortran -fdump-tree-gimple (I hope this was the right thing to
do) is the same with and without -fmerge-constants, though the second fails at
link time. Here is the tree, with Tobias' modification to the pretty printer:

MAIN__ ()
{
  int1 k;

  k = 0_S8;
  _gfortran_filename = "reduced.f";
  _gfortran_line = 3_S32;
  _gfortran_ioparm.unit = 6_S32;
  _gfortran_ioparm.list_format = 1_S32;
  _gfortran_st_write ();
  {
    int1 C.417 = 0_S8;

    _gfortran_transfer_integer (&C.417, 1_S32);
  }
  _gfortran_st_write_done ();
}
Comment 13 Andrew Pinski 2005-01-09 19:21:29 UTC
Here is a reduced testcase now without ISHFT:
      call c_i1(0_1)
      end

Comment 14 Tobias Schlüter 2005-01-09 19:28:24 UTC
(In reply to comment #12)
> The output from gfortran -fdump-tree-gimple (I hope this was the right thing to
> do)

-fdump-tree-original gives you the output of the frontend, so if the frontend
produces crap, it will be in this dump.  In your case it didn't make a
difference, but usually the gimple dump is much harder to read because the
originial generic gets converted to ssa form (single static assignment).  IIUC,
of course.
Comment 15 Andrew Pinski 2005-01-09 19:31:26 UTC
(In reply to comment #14)
> (In reply to comment #12)
> > The output from gfortran -fdump-tree-gimple (I hope this was the right thing to
> > do)
> 
> -fdump-tree-original gives you the output of the frontend, so if the frontend
> produces crap, it will be in this dump.  In your case it didn't make a
> difference, but usually the gimple dump is much harder to read because the
> originial generic gets converted to ssa form (single static assignment).  IIUC,
> of course.

Actually -fdump-tree-gimple dumps gimple form which is a lowered form of generic (not all the way 
down but slightly more, in that gimple have a simplified grammar per statement and generic).
Comment 16 Andrew Pinski 2005-01-09 20:07:12 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-01/msg00491.html>.
Comment 17 Andrew Pinski 2005-01-13 00:47:11 UTC
Fixed.
Comment 18 GCC Commits 2005-01-13 00:47:55 UTC
Subject: Bug 19334

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pinskia@gcc.gnu.org	2005-01-13 00:47:45

Modified files:
	gcc            : ChangeLog 
	gcc/config     : darwin.c 

Log message:
	2005-01-12  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR target/19334
	* config/darwin.c (machopic_select_section): Use TYPE_SIZE_UNIT instead
	of TYPE_SIZE where we mean the number of bytes.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7104&r2=2.7105
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/darwin.c.diff?cvsroot=gcc&r1=1.104&r2=1.105