public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/50192] New: Wrong character comparision with wide strings
@ 2011-08-25 21:02 tkoenig at gcc dot gnu.org
  2011-08-26  9:27 ` [Bug libfortran/50192] " dominiq at lps dot ens.fr
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-08-25 21:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50192

             Bug #: 50192
           Summary: Wrong character comparision with wide strings
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tkoenig@gcc.gnu.org
                CC: jvdelisle@gcc.gnu.org


ig25@linux-fd1f:~/Krempel/4> cat compare.f90
program main
  character(kind=4,len=2) :: c1, c2
  c1 = 4_' '
  c2 = 4_' '
  c1(1:1) = transfer(257, mold=c1)
  c2(1:1) = transfer(64, mold=c2)
  if (c1 < c2) print *,"strange..."
end program main
ig25@linux-fd1f:~/Krempel/4> gfortran compare.f90
ig25@linux-fd1f:~/Krempel/4> ./a.out
 strange...

The problem is in compare_string.  We use

int
compare_string (gfc_charlen_type len1, const CHARTYPE *s1,
                gfc_charlen_type len2, const CHARTYPE *s2)
{
  const UCHARTYPE *s;
  gfc_charlen_type len;
  int res;

  res = memcmp (s1, s2, ((len1 < len2) ? len1 : len2) * sizeof (CHARTYPE));

which works on big-endian, but not on little-endian, where the memcmp is used
to compare (bytewise) 0x01 0x01 0x00 0x00 vs. 0x40 0x00 0x00 0x00.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libfortran/50192] Wrong character comparision with wide strings
  2011-08-25 21:02 [Bug libfortran/50192] New: Wrong character comparision with wide strings tkoenig at gcc dot gnu.org
@ 2011-08-26  9:27 ` dominiq at lps dot ens.fr
  2011-08-26 11:47 ` tkoenig at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: dominiq at lps dot ens.fr @ 2011-08-26  9:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50192

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-08-26
     Ever Confirmed|0                           |1

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2011-08-26 09:21:48 UTC ---
Confirmed and "strange..." is not printed on ppc.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libfortran/50192] Wrong character comparision with wide strings
  2011-08-25 21:02 [Bug libfortran/50192] New: Wrong character comparision with wide strings tkoenig at gcc dot gnu.org
  2011-08-26  9:27 ` [Bug libfortran/50192] " dominiq at lps dot ens.fr
@ 2011-08-26 11:47 ` tkoenig at gcc dot gnu.org
  2011-08-29 10:05 ` tkoenig at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-08-26 11:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50192

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |tkoenig at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #2 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-08-26 11:28:17 UTC ---
Should be straightforward to fix.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libfortran/50192] Wrong character comparision with wide strings
  2011-08-25 21:02 [Bug libfortran/50192] New: Wrong character comparision with wide strings tkoenig at gcc dot gnu.org
  2011-08-26  9:27 ` [Bug libfortran/50192] " dominiq at lps dot ens.fr
  2011-08-26 11:47 ` tkoenig at gcc dot gnu.org
@ 2011-08-29 10:05 ` tkoenig at gcc dot gnu.org
  2011-08-29 14:33 ` tkoenig at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-08-29 10:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50192

--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-08-29 09:05:18 UTC ---
Author: tkoenig
Date: Mon Aug 29 09:05:11 2011
New Revision: 178173

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178173
Log:
2011-08-29  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR libfortran/50192
    * intrinsics/string_intrinsics.c (memcmp_char4):  New function.
    * intrinsics/string_intrinsics_inc.c:  New macro MEMCMP, either
    set to memcmp or memcmp_char4.
    (compare_string):  Use MEMCMP, with correct size for it.
    * libgfortran.h:  Add prototype for memcmp_char4.

2011-08-29  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR libfortran/50192
    * gfortran.dg/widechar_compare_1.f90:  New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/widechar_compare_1.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/intrinsics/string_intrinsics.c
    trunk/libgfortran/intrinsics/string_intrinsics_inc.c
    trunk/libgfortran/libgfortran.h


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libfortran/50192] Wrong character comparision with wide strings
  2011-08-25 21:02 [Bug libfortran/50192] New: Wrong character comparision with wide strings tkoenig at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-08-29 10:05 ` tkoenig at gcc dot gnu.org
@ 2011-08-29 14:33 ` tkoenig at gcc dot gnu.org
  2011-08-30 21:48 ` tkoenig at gcc dot gnu.org
  2011-09-01 16:42 ` tkoenig at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-08-29 14:33 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50192

--- Comment #4 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-08-29 14:12:01 UTC ---
Author: tkoenig
Date: Mon Aug 29 14:11:54 2011
New Revision: 178238

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178238
Log:
2011-08-29  Thomas Koenig  <tkoenig@gcc.gnu.org>

    Backport from trunk
    PR libfortran/50192
    * intrinsics/string_intrinsics.c (memcmp_char4):  New function.
    * intrinsics/string_intrinsics_inc.c:  New macro MEMCMP, either
    set to memcmp or memcmp_char4.
    (compare_string):  Use MEMCMP, with correct size for it.
    * libgfortran.h:  Add prototype for memcmp_char4.

2011-08-29  Thomas Koenig  <tkoenig@gcc.gnu.org>

    Backport from trunk
    PR libfortran/50192
    * gfortran.dg/widechar_compare_1.f90:  New test.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/widechar_compare_1.f90
Modified:
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_6-branch/libgfortran/ChangeLog
    branches/gcc-4_6-branch/libgfortran/intrinsics/string_intrinsics.c
    branches/gcc-4_6-branch/libgfortran/intrinsics/string_intrinsics_inc.c
    branches/gcc-4_6-branch/libgfortran/libgfortran.h


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libfortran/50192] Wrong character comparision with wide strings
  2011-08-25 21:02 [Bug libfortran/50192] New: Wrong character comparision with wide strings tkoenig at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-08-29 14:33 ` tkoenig at gcc dot gnu.org
@ 2011-08-30 21:48 ` tkoenig at gcc dot gnu.org
  2011-09-01 16:42 ` tkoenig at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-08-30 21:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50192

--- Comment #5 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-08-30 21:36:53 UTC ---
Author: tkoenig
Date: Tue Aug 30 21:36:48 2011
New Revision: 178341

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178341
Log:
2011-08-30  Thomas Koenig  <tkoenig@gcc.gnu.org>

    Backport from trunk
    PR libfortran/50192
    * intrinsics/string_intrinsics.c (memcmp_char4):  New function.
    * intrinsics/string_intrinsics_inc.c:  New macro MEMCMP, either
    set to memcmp or memcmp_char4.
    (compare_string):  Use MEMCMP, with correct size for it.
    * libgfortran.h:  Add prototype for memcmp_char4.

2011-08-30  Thomas Koenig  <tkoenig@gcc.gnu.org>

    Backport from trunk
    PR libfortran/50192
    * gfortran.dg/widechar_compare_1.f90:  New test.


Added:
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/widechar_compare_1.f90
Modified:
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_5-branch/libgfortran/ChangeLog
    branches/gcc-4_5-branch/libgfortran/intrinsics/string_intrinsics.c
    branches/gcc-4_5-branch/libgfortran/intrinsics/string_intrinsics_inc.c
    branches/gcc-4_5-branch/libgfortran/libgfortran.h


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libfortran/50192] Wrong character comparision with wide strings
  2011-08-25 21:02 [Bug libfortran/50192] New: Wrong character comparision with wide strings tkoenig at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2011-08-30 21:48 ` tkoenig at gcc dot gnu.org
@ 2011-09-01 16:42 ` tkoenig at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-09-01 16:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50192

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #6 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-09-01 16:41:45 UTC ---
Fixed on trunk, 4.6 and 4.5.

Backporting to 4.4 failed because the test case ICE'd due to PR 50267.

Closing as fixed; if anybody feels differently, maybe it would be wise to
tackle PR 50267 first.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-09-01 16:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-25 21:02 [Bug libfortran/50192] New: Wrong character comparision with wide strings tkoenig at gcc dot gnu.org
2011-08-26  9:27 ` [Bug libfortran/50192] " dominiq at lps dot ens.fr
2011-08-26 11:47 ` tkoenig at gcc dot gnu.org
2011-08-29 10:05 ` tkoenig at gcc dot gnu.org
2011-08-29 14:33 ` tkoenig at gcc dot gnu.org
2011-08-30 21:48 ` tkoenig at gcc dot gnu.org
2011-09-01 16:42 ` tkoenig at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).