Bug 30452 - [4.2, 4.1 only] Strange syntax error with high-value character
Summary: [4.2, 4.1 only] Strange syntax error with high-value character
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: 19292
  Show dependency treegraph
 
Reported: 2007-01-12 22:50 UTC by Thomas Koenig
Modified: 2007-01-31 07:38 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.0
Known to fail: 4.2.0 4.1.2
Last reconfirmed: 2007-01-13 07:00:46


Attachments
scanner.c-diff (221 bytes, text/plain)
2007-01-13 11:51 UTC, Thomas Koenig
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2007-01-12 22:50:09 UTC
This shouldn't be rejected. g77 accepts this.

$ cat char.f
      program main
      if (char (254) /= "รพ") call abort
      end program main
$ gfortran char.f
char.f:2.24:

      if (char (254) /= "\xFE") call abort
                       1
Error: Unterminated character constant beginning at (1)
$ g77 char.f
$
Comment 1 Jerry DeLisle 2007-01-13 07:00:45 UTC
At the lowest level, next_char in scanner.c is returning -2. That is not right for sure.  I am wondering if there is an error reading the file.  I will dig further.
Comment 2 Jerry DeLisle 2007-01-13 07:20:10 UTC
Turns out that the character 254 which is Hex FE is also the 2's complement representation of -2 which is what is used to signal an error if there is a missing delimiter.  It should not be converting this to an int -2
Comment 3 Thomas Koenig 2007-01-13 08:42:26 UTC
Subject: Re:  Strange syntax error with high-value character

jvdelisle at gcc dot gnu dot org wrote:

> Turns out that the character 254 which is Hex FE is also the 2's complement
> representation of -2 which is what is used to signal an error if there is a
> missing delimiter.  It should not be converting this to an int -2

Same thing happens for character 255, BTW.
Comment 4 Thomas Koenig 2007-01-13 11:51:25 UTC
Subject: Re:  Strange syntax error with high-value character

jvdelisle at gcc dot gnu dot org wrote:

> Turns out that the character 254 which is Hex FE is also the 2's complement
> representation of -2 which is what is used to signal an error if there is a
> missing delimiter.  It should not be converting this to an int -2

Here's a patch which fixes the testcase.

Currently regtesting.
Comment 5 Thomas Koenig 2007-01-13 11:51:25 UTC
Created attachment 12895 [details]
scanner.c-diff
Comment 6 Jerry DeLisle 2007-01-13 18:45:09 UTC
Assuming this regression tests OK, I think this is an "obvious and simple"  Thanks :)

Comment 7 Thomas Koenig 2007-01-14 11:01:32 UTC
Subject: Bug 30452

Author: tkoenig
Date: Sun Jan 14 11:01:20 2007
New Revision: 120768

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120768
Log:
2007-01-14  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/30452
	* scanner.c(next_char):  Cast next character to unsigned
	to avoid confusion with error return codes.

2007-01-14  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/30452
	* gfortran.dg/string_0xfe_0xff_1.f90:  New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/string_0xfe_0xff_1.f90
Modified:
    trunk/gcc/fortran/scanner.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 Thomas Koenig 2007-01-15 20:27:36 UTC
Fixed on trunk, will backport to 4.2 in a week or so.
Comment 9 Thomas Koenig 2007-01-31 07:37:28 UTC
Subject: Bug 30452

Author: tkoenig
Date: Wed Jan 31 07:37:08 2007
New Revision: 121378

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121378
Log:
2007-01-31  Thomas Koenig  <Thomas.Koenig@online.de>

	Backport from trunk
	PR fortran/30452
	* scanner.c(next_char):  Cast next character to unsigned
	to avoid confusion with error return codes.

2007-01-31  Thomas Koenig  <Thomas.Koenig@online.de>

	Backport from trunk
	PR fortran/30452
	* gfortran.dg/string_0xfe_0xff_1.f90:  New test.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/string_0xfe_0xff_1.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/scanner.c

Comment 10 Thomas Koenig 2007-01-31 07:38:18 UTC
Fixed on trunk and 4.2.  Closing.

One down, a few more to go :-)