ltcmelo / psychec

A compiler frontend for the C programming language
BSD 3-Clause "New" or "Revised" License
536 stars 39 forks source link

Pre-ANSI declarations not supported (but are supported by clang/gcc in `-std=c11`) #11

Closed aytey closed 3 years ago

aytey commented 3 years ago

If eligible for the bounty, I wish this to be donated to a local animal charity of the maintainer's choice

GCC version:

gcc (SUSE Linux) 10.2.1 20201202 [revision e563687cf9d3d1278f45aaebd03e0f66531076c9]

clang version:

clang version 11.0.1

Output of gcc -Werror -Wall -Wextra -Wpedantic -pedantic -std=c11 -c $FNAME

(return code 0)

Output of clang -Werror -Wall -Wextra -Wpedantic -pedantic -std=c11 -c $FNAME

(return code 0)

Output of cnip $FNAME

930506-1.c:2:10 error: expected , or `;' or = after declarator, got `double'
long f(a) double a;
          ^
930506-1.c:2:20 warning: missing type specifier, assume `int'
long f(a) double a;
                    ^
930506-1.c:2:20 error: expected <identifier> or `(' starting direct-declarator, got `{'
long f(a) double a;
                    ^
930506-1.c:3:12 warning: missing type specifier, assume `int'
{ return a; }
            ^
930506-1.c:3:12 error: expected <identifier> or `(' starting direct-declarator, got `}'
{ return a; }
            ^

(return code 0)

Content of file

long f(a) double a;
{ return a; }

psychec version

commit 6d7b8249e0f28af105112b217cb33a24f666e148
Author: Leandro T. C. Melo <LTCMELO@GMAIL.COM>
Date:   Tue Feb 23 07:47:25 2021 -0300

    link expression-parsing table in Doxygen documentation
aytey commented 3 years ago

Another example:

GCC version:

gcc (SUSE Linux) 10.2.1 20201202 [revision e563687cf9d3d1278f45aaebd03e0f66531076c9]

clang version:

clang version 11.0.1

Output of gcc -Werror -Wall -Wextra -Wpedantic -pedantic -std=c11 -c $FNAME

(return code 0)

Output of clang -Werror -Wall -Wextra -Wpedantic -pedantic -std=c11 -c $FNAME

(return code 0)

Output of cnip $FNAME

mword1.c:2:14 error: expected , or `;' or = after declarator, got `int'
int foo(a, b) int *a, *b;
              ^
mword1.c:2:26 warning: missing type specifier, assume `int'
int foo(a, b) int *a, *b;
                          ^
mword1.c:2:26 error: expected <identifier> or `(' starting direct-declarator, got `{'
int foo(a, b) int *a, *b;
                          ^
mword1.c:5:2 warning: missing type specifier, assume `int'
  return 0;
  ^
mword1.c:5:2 error: expected <identifier> or `(' starting direct-declarator, got `return'
  return 0;
  ^
mword1.c:5:12 warning: missing type specifier, assume `int'
  return 0;
            ^
mword1.c:5:12 error: expected <identifier> or `(' starting direct-declarator, got `}'
  return 0;
            ^

(return code 0)

Content of file

int foo(a, b) int *a, *b;
{
  *a = *b;
  return 0;
}

psychec version

commit 6d7b8249e0f28af105112b217cb33a24f666e148
Author: Leandro T. C. Melo <LTCMELO@GMAIL.COM>
Date:   Tue Feb 23 07:47:25 2021 -0300

    link expression-parsing table in Doxygen documentation
ltcmelo commented 3 years ago

Thank you again, @andrewvaughanj . This one is a duplicate of #6 , though — but it isn't immediate to notice, since the other bug is reported with another title.

aytey commented 3 years ago

Doh 🤦 I'd missed that was reason for the duffs device one failing!

Do you want me to close this?

ltcmelo commented 3 years ago

Yes, I guess this can be closed.

ltcmelo commented 3 years ago

@andrewvaughanj I also amended the title of the other bug so it'll be easier for others to spot.