public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106529] New: existence of sincos is assumed
@ 2022-08-04 21:36 tk at giga dot or.at
  2022-08-04 21:37 ` [Bug c/106529] " tk at giga dot or.at
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: tk at giga dot or.at @ 2022-08-04 21:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106529

            Bug ID: 106529
           Summary: existence of sincos is assumed
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tk at giga dot or.at
  Target Milestone: ---
              Host: NetBSD/amd64
            Target: NetBSD/amd64
             Build: NetBSD/amd64

Created attachment 53411
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53411&action=edit
second example

NetBSD does not provide sincos (perhaps it should).
gcc 12.1.0 reports warnings that make no sense here.

Example program 1:

# cat >> sincos.c
int main() {
return sincos();
}

# gcc -o sincos sincos.c
sincos.c: In function ‘main’:
sincos.c:2:8: warning: implicit declaration of function ‘sincos’
[-Wimplicit-function-declaration]
    2 | return sincos();
      |        ^~~~~~
sincos.c:1:1: note: include ‘<math.h>’ or provide a declaration of ‘sincos’
  +++ |+#include <math.h>
    1 | int main() {
sincos.c:2:8: warning: incompatible implicit declaration of built-in function
‘sincos’ [-Wbuiltin-declaration-mismatch]
    2 | return sincos();
      |        ^~~~~~
sincos.c:2:8: note: include ‘<math.h>’ or provide a declaration of ‘sincos’
sincos.c:2:8: error: too few arguments to function ‘sincos’

I agree that in general it is helpful to include math.h for sincos(), but not
on NetBSD, where sincos() is not provided by libc.

Even more confusing, the warning comes even when math.h is already included -
example 2:

# cat > sincos.c
#include <math.h>
int main() {
return sincos();
}
# gcc -o sincos sincos.c
sincos.c: In function ‘main’:
sincos.c:3:8: warning: implicit declaration of function ‘sincos’
[-Wimplicit-function-declaration]
    3 | return sincos();
      |        ^~~~~~
sincos.c:2:1: note: include ‘<math.h>’ or provide a declaration of ‘sincos’
    1 | #include <math.h>
  +++ |+#include <math.h>
    2 | int main() {
sincos.c:3:8: warning: incompatible implicit declaration of built-in function
‘sincos’ [-Wbuiltin-declaration-mismatch]
    3 | return sincos();
      |        ^~~~~~
sincos.c:3:8: note: include ‘<math.h>’ or provide a declaration of ‘sincos’
sincos.c:3:8: error: too few arguments to function ‘sincos’



Environment details:
# gcc -v
Using built-in specs.
COLLECT_GCC=/usr/pkg/gcc12/bin/gcc
COLLECT_LTO_WRAPPER=/usr/pkg/gcc12/libexec/gcc/x86_64--netbsd/12.1.0/lto-wrapper
Target: x86_64--netbsd
Configured with: ../gcc-12.1.0/configure --disable-libstdcxx-pch --enable-nls
--with-libiconv-prefix=/usr --enable-__cxa_atexit
--with-gxx-include-dir=/usr/pkg/gcc12/include/c++/ --disable-libssp
--enable-languages='c obj-c++ objc fortran c++' --enable-shared
--enable-long-long --with-local-prefix=/usr/pkg/gcc12 --enable-threads=posix
--with-boot-ldflags='-static-libstdc++ -static-libgcc -Wl,-R/usr/pkg/lib
-Wl,-zrelro -Wl,-znow ' --without-zstd --with-arch=nocona --with-tune=nocona
--with-fpmath=sse --with-system-zlib --with-gnu-ld --with-ld=/usr/bin/ld
--with-gnu-as --with-as=/usr/bin/as --prefix=/usr/pkg/gcc12
--build=x86_64--netbsd --host=x86_64--netbsd --infodir=/usr/pkg/gcc12/info
--mandir=/usr/pkg/gcc12/man
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.1.0 (GCC) 

Running on NetBSD-9.99.99/amd64.

Savetemps:
/usr/pkg/gcc12/bin/gcc -v -save-temps sincos.c -o sincos 
Using built-in specs.
COLLECT_GCC=/usr/pkg/gcc12/bin/gcc
COLLECT_LTO_WRAPPER=/usr/pkg/gcc12/libexec/gcc/x86_64--netbsd/12.1.0/lto-wrapper
Target: x86_64--netbsd
Configured with: ../gcc-12.1.0/configure --disable-libstdcxx-pch --enable-nls
--with-libiconv-prefix=/usr --enable-__cxa_atexit
--with-gxx-include-dir=/usr/pkg/gcc12/include/c++/ --disable-libssp
--enable-languages='c obj-c++ objc fortran c++' --enable-shared
--enable-long-long --with-local-prefix=/usr/pkg/gcc12 --enable-threads=posix
--with-boot-ldflags='-static-libstdc++ -static-libgcc -Wl,-R/usr/pkg/lib
-Wl,-zrelro -Wl,-znow ' --without-zstd --with-arch=nocona --with-tune=nocona
--with-fpmath=sse --with-system-zlib --with-gnu-ld --with-ld=/usr/bin/ld
--with-gnu-as --with-as=/usr/bin/as --prefix=/usr/pkg/gcc12
--build=x86_64--netbsd --host=x86_64--netbsd --infodir=/usr/pkg/gcc12/info
--mandir=/usr/pkg/gcc12/man
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'sincos' '-mtune=nocona'
'-march=nocona'
 /usr/pkg/gcc12/libexec/gcc/x86_64--netbsd/12.1.0/cc1 -E -quiet -v sincos.c
-mtune=nocona -march=nocona -fpch-preprocess -o sincos.i
ignoring nonexistent directory
"/usr/pkg/gcc12/lib/gcc/x86_64--netbsd/12.1.0/../../../../x86_64--netbsd/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/pkg/gcc12/lib/gcc/x86_64--netbsd/12.1.0/include
 /usr/pkg/gcc12/include
 /usr/pkg/gcc12/lib/gcc/x86_64--netbsd/12.1.0/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'sincos' '-mtune=nocona'
'-march=nocona'
 /usr/pkg/gcc12/libexec/gcc/x86_64--netbsd/12.1.0/cc1 -fpreprocessed sincos.i
-quiet -dumpbase sincos.c -dumpbase-ext .c -mtune=nocona -march=nocona -version
-o sincos.s
GNU C17 (GCC) version 12.1.0 (x86_64--netbsd)
        compiled by GNU C version 12.1.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.1.0, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C17 (GCC) version 12.1.0 (x86_64--netbsd)
        compiled by GNU C version 12.1.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.1.0, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ab1d70000bedd16cbf4ffd28defbd834
sincos.c: In function ‘main’:
sincos.c:3:8: warning: implicit declaration of function ‘sincos’
[-Wimplicit-function-declaration]
    3 | return sincos();
      |        ^~~~~~
sincos.c:2:1: note: include ‘<math.h>’ or provide a declaration of ‘sincos’
    1 | #include <math.h>
  +++ |+#include <math.h>
    2 | int main() {
sincos.c:3:8: warning: incompatible implicit declaration of built-in function
‘sincos’ [-Wbuiltin-declaration-mismatch]
    3 | return sincos();
      |        ^~~~~~
sincos.c:3:8: note: include ‘<math.h>’ or provide a declaration of ‘sincos’
sincos.c:3:8: error: too few arguments to function ‘sincos’

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/106529] existence of sincos is assumed
  2022-08-04 21:36 [Bug c/106529] New: existence of sincos is assumed tk at giga dot or.at
@ 2022-08-04 21:37 ` tk at giga dot or.at
  2022-08-04 21:37 ` tk at giga dot or.at
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: tk at giga dot or.at @ 2022-08-04 21:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106529

--- Comment #1 from Thomas Klausner <tk at giga dot or.at> ---
Created attachment 53412
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53412&action=edit
.i file from save-temps

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/106529] existence of sincos is assumed
  2022-08-04 21:36 [Bug c/106529] New: existence of sincos is assumed tk at giga dot or.at
  2022-08-04 21:37 ` [Bug c/106529] " tk at giga dot or.at
@ 2022-08-04 21:37 ` tk at giga dot or.at
  2022-08-04 21:39 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: tk at giga dot or.at @ 2022-08-04 21:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106529

--- Comment #2 from Thomas Klausner <tk at giga dot or.at> ---
Created attachment 53413
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53413&action=edit
.s file from save-temps

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/106529] existence of sincos is assumed
  2022-08-04 21:36 [Bug c/106529] New: existence of sincos is assumed tk at giga dot or.at
  2022-08-04 21:37 ` [Bug c/106529] " tk at giga dot or.at
  2022-08-04 21:37 ` tk at giga dot or.at
@ 2022-08-04 21:39 ` redi at gcc dot gnu.org
  2022-08-04 21:41 ` [Bug target/106529] " tk at giga dot or.at
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-08-04 21:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106529

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Those warnings just match a predefined list of names and suggest the right
header. If 'sincos' is not found, it says to include <math.h>, there's no check
for which OS you're on or whether math.h has been included already. It's much
simpler than that.

Yes, sometimes including <math.h> isn't the solution, but it does say "or
provide a declaration of sincos" so it's not wrong.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/106529] existence of sincos is assumed
  2022-08-04 21:36 [Bug c/106529] New: existence of sincos is assumed tk at giga dot or.at
                   ` (2 preceding siblings ...)
  2022-08-04 21:39 ` redi at gcc dot gnu.org
@ 2022-08-04 21:41 ` tk at giga dot or.at
  2022-08-04 23:03 ` tk at giga dot or.at
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: tk at giga dot or.at @ 2022-08-04 21:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106529

--- Comment #4 from Thomas Klausner <tk at giga dot or.at> ---
Well, I can one-up that one:

int sincos();
int main() {
return sincos();
}

gives:

sincos.c:1:5: warning: conflicting types for built-in function ‘sincos’;
expected ‘void(double,  double *, double *)’ [-Wbuiltin-declaration-mismatch]
    1 | int sincos();
      |     ^~~~~~
sincos.c:1:1: note: ‘sincos’ is declared in header ‘<math.h>’
  +++ |+#include <math.h>
    1 | int sincos();
ld: /tmp//ccO3U7pd.o: in function `main':
sincos.c:(.text+0xa): undefined reference to `sincos'


a) there is no conflict since there is no builtin or otherwise sincos()
function
b) it is not declared in math.h

the linker warning is correct though :)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/106529] existence of sincos is assumed
  2022-08-04 21:36 [Bug c/106529] New: existence of sincos is assumed tk at giga dot or.at
                   ` (3 preceding siblings ...)
  2022-08-04 21:41 ` [Bug target/106529] " tk at giga dot or.at
@ 2022-08-04 23:03 ` tk at giga dot or.at
  2022-08-05  6:57 ` rguenth at gcc dot gnu.org
  2022-08-05  9:36 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: tk at giga dot or.at @ 2022-08-04 23:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106529

--- Comment #5 from Thomas Klausner <tk at giga dot or.at> ---
For context, I stumbled over this because meson misdetects sincos on NetBSD.

https://github.com/mesonbuild/meson/issues/10641

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/106529] existence of sincos is assumed
  2022-08-04 21:36 [Bug c/106529] New: existence of sincos is assumed tk at giga dot or.at
                   ` (4 preceding siblings ...)
  2022-08-04 23:03 ` tk at giga dot or.at
@ 2022-08-05  6:57 ` rguenth at gcc dot gnu.org
  2022-08-05  9:36 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-08-05  6:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106529

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-08-05
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Definitely improvements are possible.  For header suggestions we could devise a
way to tell whether a #include <foo> was already seen (not so easy - separate
preprocessing, but line markers could eventually tell), for an incompatible
declaration we probably should avoid giving this kind of diagnostic.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/106529] existence of sincos is assumed
  2022-08-04 21:36 [Bug c/106529] New: existence of sincos is assumed tk at giga dot or.at
                   ` (5 preceding siblings ...)
  2022-08-05  6:57 ` rguenth at gcc dot gnu.org
@ 2022-08-05  9:36 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-08-05  9:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106529

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Thomas Klausner from comment #4)
> a) there is no conflict since there is no builtin or otherwise sincos()
> function
> b) it is not declared in math.h

As it says, it's a built-in function automatically recognized by GCC, which is
documented here:
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
With -std=c17 instead of the -std=gnu17 default that doesn't happen.

The warning is correct, GCC gives that special handling. You can use
-fno-builtin-sincos to disable the handling for this particular function, but
maybe that should be the default on NetBSD.


> the linker warning is correct though :)

Error, not warning :)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-08-05  9:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04 21:36 [Bug c/106529] New: existence of sincos is assumed tk at giga dot or.at
2022-08-04 21:37 ` [Bug c/106529] " tk at giga dot or.at
2022-08-04 21:37 ` tk at giga dot or.at
2022-08-04 21:39 ` redi at gcc dot gnu.org
2022-08-04 21:41 ` [Bug target/106529] " tk at giga dot or.at
2022-08-04 23:03 ` tk at giga dot or.at
2022-08-05  6:57 ` rguenth at gcc dot gnu.org
2022-08-05  9:36 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).