Re: confusing messages from clang
On 20 Feb 2016, at 08:33, Alex Denisov <1101.deb...@gmail.com> wrote: >> On 20 Feb 2016, at 01:57, Steve Kargl>> wrote: >> >> If anyone is interesting fixing FreeBSD's C compiler, it >> would be appreciated. ... >> foo.c:21:1: error: use of undeclared identifier 'corrupt'; did you mean >> 'crypt'? >> corrupt: >> ^~~ >> crypt >> /usr/include/unistd.h:450:7: note: 'crypt' declared here >> char*crypt(const char *, const char *); >>^ >> foo.c:21:8: error: expected ';' after return statement >> corrupt: >> ^ >> ; >> foo.c:14:12: error: use of undeclared label 'corrupt' >> goto corrupt; >> ^ ... > I’ve submitted the bug to LLVM’s bugzilla: > https://llvm.org/bugs/show_bug.cgi?id=26678 > > Also, it looks like OS agnostic. At least I see the same behaviour on OSX as > well. Yes, the messages could definitely be improved. But for a compiler, it is sometimes hard to guess the 'intent' of the code, though. :) Note that gcc (I used 6.0 from ports) gives similarly confused messages: foo.c: In function 'foo': foo.c:21:1: error: 'corrupt' undeclared (first use in this function) corrupt: ^~~ foo.c:21:1: note: each undeclared identifier is reported only once for each function it appears in foo.c:21:1: warning: 'return' with a value, in function returning void foo.c:5:1: note: declared here foo(int i) ^~~ foo.c:21:8: error: expected ';' before ':' token corrupt: ^ foo.c:14:6: error: label 'corrupt' used but not defined goto corrupt; ^~~~ In gcc's case, it appears to read the statement as "return corrupt:", causing it to first complain about the undeclared identifier, and then about a missing semicolon. Later, the label is of course still not defined, so it complains again. -Dimitry signature.asc Description: Message signed with OpenPGP using GPGMail
Re: confusing messages from clang
C compilers are always doing best effort attempts to report when you feed them code that is not valid C. For example, in this case: On 20 Feb 2016, at 00:57, Steve Karglwrote: > if (i > 0) > goto corrupt; This is valid, as long as you have a label called corrupt to look for. You do not, however, because: > return; > > whoops: > printf("whoops\n"); > return > > corrupt: > printf("corrupt\n”); The statement: > return corrupt: printf("corrupt\n"); is just confusing. It appears to be trying to return the value in corrupt (which is not an identifier that corresponds to any valid variable) and then has some trailing characters after the end of the statement. Fortunately, the compiler tells you exactly what is wrong: First it says: > foo.c:21:1: error: use of undeclared identifier 'corrupt'; did you mean > 'crypt'? > corrupt: > ^~~ Here, it is telling you that the value passed to your return statement is an undeclared identifier. Then it tells you that you have more tokens after the end of your return statement: > foo.c:21:8: error: expected ';' after return statement > corrupt: > ^ > ; I am slightly surprised that there’s no warning that a return statement with a value is invalid in a function that returns void, but perhaps that’s because after finding two things wrong with one statement it gives up. The correct fix, of course, is to insert the missing semicolon after the return at the end of line 19. If you had tried compiling the same thing with gcc 5, then you would have noticed that you get very similar error messages (though gcc doesn’t attempt to provide a fixit hint and does warn that you have a return statement returning a value from a function that returns void). David ___ freebsd-toolchain@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain To unsubscribe, send any mail to "freebsd-toolchain-unsubscr...@freebsd.org"
Re: confusing messages from clang
Hi Steve, I’ve submitted the bug to LLVM’s bugzilla: https://llvm.org/bugs/show_bug.cgi?id=26678 Also, it looks like OS agnostic. At least I see the same behaviour on OSX as well. -- AlexDenisov Software Engineer, http://lowlevelbits.org > On 20 Feb 2016, at 01:57, Steve Kargl> wrote: > > If anyone is interesting fixing FreeBSD's C compiler, it > would be appreciated. > > % cat foo.c > #include > #include > > void > foo(int i) > { > if (i < 0) > goto whoops; > > if (i == 0) > printf("foo\n"); > > if (i > 0) > goto corrupt; > return; > > whoops: > printf("whoops\n"); > return > > corrupt: > printf("corrupt\n"); > } > > % cc -c foo.c > foo.c:21:1: error: use of undeclared identifier 'corrupt'; did you mean > 'crypt'? > corrupt: > ^~~ > crypt > /usr/include/unistd.h:450:7: note: 'crypt' declared here > char*crypt(const char *, const char *); > ^ > foo.c:21:8: error: expected ';' after return statement > corrupt: > ^ > ; > foo.c:14:12: error: use of undeclared label 'corrupt' > goto corrupt; > ^ > 3 errors generated. > > > No, I did not mean crypt. 'corrupt' is a defined label. > The missing semicolon occurs in line 19, but the line is > not properly identified in error output. > > -- > Steve > ___ > freebsd-toolchain@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain > To unsubscribe, send any mail to "freebsd-toolchain-unsubscr...@freebsd.org" signature.asc Description: Message signed with OpenPGP using GPGMail
confusing messages from clang
If anyone is interesting fixing FreeBSD's C compiler, it would be appreciated. % cat foo.c #include #include void foo(int i) { if (i < 0) goto whoops; if (i == 0) printf("foo\n"); if (i > 0) goto corrupt; return; whoops: printf("whoops\n"); return corrupt: printf("corrupt\n"); } % cc -c foo.c foo.c:21:1: error: use of undeclared identifier 'corrupt'; did you mean 'crypt'? corrupt: ^~~ crypt /usr/include/unistd.h:450:7: note: 'crypt' declared here char*crypt(const char *, const char *); ^ foo.c:21:8: error: expected ';' after return statement corrupt: ^ ; foo.c:14:12: error: use of undeclared label 'corrupt' goto corrupt; ^ 3 errors generated. No, I did not mean crypt. 'corrupt' is a defined label. The missing semicolon occurs in line 19, but the line is not properly identified in error output. -- Steve ___ freebsd-toolchain@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain To unsubscribe, send any mail to "freebsd-toolchain-unsubscr...@freebsd.org"