[cfe-dev] Possible bug in CLang 3.7.1 / 3.8.0

James Y Knight via cfe-dev cfe-dev at lists.llvm.org
Fri Mar 25 11:22:00 PDT 2016


This does seem bogus. Not just for strlcpy, but for any of the recognized
stdlib functions.

E.g. without any includes:
  int main() {
    (void)strcpy;
    return 0;
  }

gcc fails, and emits:
bar.c:2:9: error: ‘strcpy’ undeclared (first use in this function)

clang succeeds, and emits:
bar.c:2:9: warning: implicitly declaring library function 'strcpy' with
type 'char *(char *, const char *)' [-Wimplicit-function-declaration]

GCC's behavior there seems more sensible -- I'd expect the implicit
declarations to only be introduced in the compilation unit when an implicit
declaration would be made for a non-stdlib function. That is to say, when
you're doing a function call, not when using it as a value.

That is, I'd expect the behavior of using strcpy (or strncpy, or any of the
others) to be the same as these:

OK (in both gcc and clang):
  int main() {
    frobnotz(5);
    (void)frobnotz;
  }

Error (in both gcc and clang):
  int main() {
    (void)frobnotz;
  }




On Fri, Mar 25, 2016 at 6:26 AM, Aleksander Alekseev via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hello
>
> Here is a test program:
>
> ```
> #include <string.h>
>
> int main()
> {
>   (void)strlcpy;
>   return 0;
> }
> ```
>
> When I compile it using clang 3.6 compiler reports an error:
>
> ```
> $ /usr/bin/clang-3.6 str.c -o str
> str.c:5:9: error: use of undeclared identifier 'strlcpy'; did you mean
> 'struct'?
>
> str.c:5:9: error: expected expression
> 2 errors generated.
> ```
>
> Its OK, this is an expected behavior.
>
> But newer versions of CLang somehow manage to build this program:
>
> ```
> $ /usr/local/bin/clang-3.7 str.c -o str
>
> str.c:5:9: warning: implicitly declaring library function 'strlcpy'
> with type 'unsigned long (char *, const char *, unsigned
> long)'
>
> str.c:5:9: note: include the header <string.h> or explicitly provide a
> declaration for 'strlcpy'
>
> 1 warning generated.
>
> $ ./str
>
> $ /usr/local/bin/clang-3.8 str.c -o str
>
> str.c:5:9: warning: implicitly declaring library function 'strlcpy'
> with type 'unsigned long (char *, const char *, unsigned
> long)' [-Wimplicit-function-declaration]
>
> str.c:5:9: note: include the header <string.h> or explicitly provide a
> declaration for 'strlcpy' 1 warning generated.
> ```
>
> First of all <string.h> is already included. Also there is no strlcpy
> procedure on this system at all (Ubuntu Linux 14.04 x64). Thus this
> program should not compile.
>
> It seems to be a serious bug since projects that use Autotools rely on
> clang 3.6 behaviour while checking weather current system has strlcpy
> procedure.
>
> Or maybe I just don't understand something?
>
> --
> Best regards,
> Aleksander Alekseev
> http://eax.me/
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160325/09dd7ce3/attachment.html>


More information about the cfe-dev mailing list