llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.3k stars 11.68k forks source link

clang warning on static inlines with -Wunused-function #23086

Open llvmbot opened 9 years ago

llvmbot commented 9 years ago
Bugzilla Link 22712
Version 3.6
OS All
Attachments [bzip2 compressed preprocessed source file for gdb-7.9https://user-images.githubusercontent.com/60944935/143751025-702cb8d3-b5ea-4a31-b223-56bc47ca5635.gz)
Reporter LLVM Bugzilla Contributor
CC @emaste,@P-p-H-d,@zygoloid

Extended Description

Clang 3.5, 3.6 and 3.7svn are all erroneously warning on static inlines as seen in gdb-7.9/gdb/remote.c...

remote.c:2567:1058: warning: unused function 'VEC_thread_item_t_embedded_size' [-Wunused-function] remote.c:2567:1210: warning: unused function 'VEC_thread_item_t_embedded_init' [-Wunused-function] remote.c:2567:2076: warning: unused function 'VEC_thread_item_t_pop' [-Wunused-function] ...

I can't find the clang documentation but FSF gcc's shows...

-Wunused-function Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall.

The attached preprocessed source for gdb-7.9/gdb/remote.c reproduces the problem with...

clang-3.6 -Wunused-function -c remote.i

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 9 years ago

That makes sense; we should probably consider the functions to not be in the main source file if they were expanded from a macro that was defined outside that file. That perhaps doesn't go far enough (consider a macro defined in the main source file, that produces several functions, where after each macro invocation only a subset of the functions is used) but seems like a good start.

llvmbot commented 9 years ago

Clang's rule for this warning is somewhat different; we base the decision to warn on whether the function is defined in the main source file versus in a header file.

Why do these unused functions exist in remote.c? If they're being conditionally used, the usual convention is to also conditionally define them.

See https://sourceware.org/ml/gdb/2015-02/msg00072.html and https://sourceware.org/ml/gdb/2015-02/msg00074.html for an explanation.

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 9 years ago

Clang's rule for this warning is somewhat different; we base the decision to warn on whether the function is defined in the main source file versus in a header file.

Why do these unused functions exist in remote.c? If they're being conditionally used, the usual convention is to also conditionally define them.