This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug optimization/13609] New: sscanf optimization error
- From: "BStrauss-gcc at feliscatus dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Jan 2004 22:02:02 -0000
- Subject: [Bug optimization/13609] New: sscanf optimization error
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Different results for small test program when compiled -O2 vs no optimization
(non-optimized version is right):
#define cNV2N(a, b) printf("-> %10u expected %10u\n",
convertNtopVersionToNumber(a), b)
unsigned int convertNtopVersionToNumber(char *versionString) {
/* This one is purely an arbitrary conversion.
*
* But it knows about the version # schemes we've used in the past
* e.g. 2.2c, 2.2.50, 2.2.97, 3.0pre1, 3.0rc1 etc. so that the number truly
is relative
* for numeric testing.
*
* The goal is to get the following converted to ascending numeric order:
*
* 1.3 2.1 2.1.2 2.1.3 2.1.50 2.1.90 2.2 2.2a 2.2b 2.2c 2.2.50 2.2.97
3.0pre1 3.0rc1 3.0
*
* e.g.:
*
* 1.3 103000000
* 2.1 201000000
* 2.1.1 201000001
* 2.1.2 201000002
* 2.1.3 201000003
* 2.1.50 201050000
* 2.1.90 201090000
* 2.2 202000000
* 2.2a 202000100
* 2.2b 202000200
* 2.2c 202000300
* 2.2.50 202050000
* 2.2.90 202090000
* 3.0pre1 299998001
* 3.0rc1 299999001
* 3.0rc2 299999002
* 3.0 300000000
*
* n.m -> nmm000000
* n.m.x -> nmmyyy0xx (if x>=50 yyy=x else xx=x)
* n.ml -> nmm000l00 (where a=1, b=2, etc.)
*/
unsigned int f, n=0, m=0, x=0, y=0, c=0, prerc=0;
unsigned char l=0;
if (versionString == 0) {
return 999999999;
}
printf("'%10s'", versionString);
f = sscanf(versionString, "%u.%upre%u", &n, &m, &x);
if(f>=3) {
prerc=2;
} else {
f = sscanf(versionString, "%u.%urc%u", &n, &m, &x);
if(f>=3) {
prerc=1;
} else {
f = sscanf(versionString, "%u.%u%[a-z].%u", &n, &m, &l, &x);
if(f>=3) {
if(l>0)
l = tolower(l) - 'a' + 1;
} else {
l = 0;
f = sscanf(versionString, "%u.%u.%u", &n, &m, &x);
if (f<=0) {
return 999999999;
}
}
}
}
if (x>=50) {
y=x;
x=0;
}
printf("\tis n%u m%u y%u l%u x%u prerc%u f=%u\t", n, m, y, l, x, prerc, f);
return n*100000000 + m*1000000 + y*1000 + l*100 + x - 1000*prerc;
}
int main(int argc, char *argv[]) {
cNV2N("2.2", 202000000);
cNV2N("2.2c", 202000300);
cNV2N("2.2c.1", 202000301);
}
$ gcc sscanftest.c -o sscanftest
$ ./sscanftest
' 2.2' is n2 m2 y0 l0 x0 prerc0 f=2 -> 202000000 expected
202000000
' 2.2c' is n2 m2 y0 l3 x0 prerc0 f=3 -> 202000300 expected
202000300
' 2.2c.1' is n2 m2 y0 l3 x1 prerc0 f=4 -> 202000301 expected
202000301
$ gcc -O2 sscanftest.c -o sscanftest
$ ./sscanftest
' 2.2' is n2 m2 y0 l0 x0 prerc0 f=2 -> 202000000 expected
202000000
' 2.2c' is n0 m2 y0 l3 x0 prerc0 f=3 -> 2000300 expected
202000300
' 2.2c.1' is n0 m2 y0 l3 x1 prerc0 f=4 -> 2000301 expected
202000301
$ gcc --version
gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
--
Summary: sscanf optimization error
Product: gcc
Version: 3.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: BStrauss-gcc at feliscatus dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13609