]> git.ipfire.org Git - thirdparty/gcc.git/commit
c,c++: Fix incorrect warning with asm defined symbols
authorMichal Jires <mjires@suse.cz>
Fri, 30 Jan 2026 15:42:48 +0000 (16:42 +0100)
committerMichal Jires <mjires@suse.cz>
Thu, 5 Feb 2026 14:42:35 +0000 (15:42 +0100)
commitfa20d1d7095122c7fc0e701b08ec383a60404bb0
tree93444f0c5b3281d37f617b25f4a1b5651abd3eab
parentce8a84ba6719a71365b611a94cc2454dd157f3b2
c,c++: Fix incorrect warning with asm defined symbols

Static symbols defined in assembly cause wrong "used but never defined"
warning.

static void asm_fn();
asm("%cc0:" :: ":"(&asm_fn));

This happens in C,C++ frontends before cgraph is created where the
relevant flags are located.

We can suppress these warnings with OPT_Wunused.
C,C++ frontends and cgraphunit suppressed OPT_Wunused and
OPT_Wunused_function interchangeably, so we unify suppression to
only OPT_Wunused.

PR testsuite/123559

gcc/c/ChangeLog:

* c-decl.cc (c_write_global_declarations_1): Check and suppress
OPT_Wunused.
* c-typeck.cc (build_asm_expr): Suppress OPT_Wunused.

gcc/ChangeLog:

* cgraphunit.cc (check_global_declaration): Suppress OPT_Wunused.

gcc/cp/ChangeLog:

* decl.cc (wrapup_namespace_globals): Check and suppress OPT_Wunused.
* semantics.cc (finish_asm_stmt): Suppress OPT_Wunused.

gcc/testsuite/ChangeLog:

* c-c++-common/toplevel-extended-asm-1.c: New test.
gcc/c/c-decl.cc
gcc/c/c-typeck.cc
gcc/cgraphunit.cc
gcc/cp/decl.cc
gcc/cp/semantics.cc
gcc/testsuite/c-c++-common/toplevel-extended-asm-1.c [new file with mode: 0644]