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

            Bug ID: 128594
           Summary: flag_instrument_functions_exclude_p queries
                    decl_printable_name at verbosity 1, making
                    -finstrument-functions-exclude-function-list unable to
                    match C++ parameter or return types as documented in
                    invoke.texi
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 220245569 at seu dot edu.cn
                CC: 220255623 at seu dot edu.cn, jianhao.xu at seu dot edu.cn
  Target Milestone: ---
            Target: *-*-*

Reproducer
----------
$ cat trigger.cpp
namespace ns {
  int blah(int x) { return x + 1; }
}
int main() { return ns::blah(41); }

Compile command / flags:
podman exec defuzz-toolchain-daemon /opt/gcc16/bin/x86_64-linux-gnu-g++ -O0
-finstrument-functions '-finstrument-functions-exclude-function-list=int
ns::blah(int)' -S -o - /tmp/t13.cpp | grep -A12 '_ZN2ns4blahEi:'

Observed output (GCC 16.2.0):
_ZN2ns4blahEi:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        subq    $16, %rsp
        movl    %edi, -4(%rbp)
        movq    8(%rbp), %rax
        movq    %rax, %rsi
        movl    $_ZN2ns4blahEi, %edi
        call    __cyg_profile_func_enter

Expected behavior:
-finstrument-functions-exclude-function-list must either match against
verbosity-2 decl_printable_name (which includes the C++ signature as documented
in invoke.texi:18232-18234) in addition to verbosity-1, or invoke.texi must
match the implementation.

Root cause
----------
Source location: gcc/gimplify.cc:21895-21912
(flag_instrument_functions_exclude_p), gcc/cp/error.cc:3659-3677
(lang_decl_name), gcc/doc/invoke.texi:18232-18234

gcc/doc/invoke.texi:18232-18234 explicitly documents that for
-finstrument-functions-exclude-function-list=sym,sym,..., 'In C++, the function
name includes the function signature, for example: vector<int> blah(const
vector<int> &).' However, flag_instrument_functions_exclude_p
(gcc/gimplify.cc:21900) obtains the function name via 'name =
lang_hooks.decl_printable_name (fndecl, 1);'. In the C++ front end,
cxx_printable_name_internal -> lang_decl_name (gcc/cp/error.cc:3659-3677) only
sets TFF_DECL_SPECIFIERS (return type) and prints the parameter list when
verbosity >= 2; for v == 1, it prints only the scope-qualified name
('ns::blah') without return type or parameter types! Consequently, passing any
C++ signature with parameter types or return type as documented in invoke.texi
(or trying to exclude one C++ overload without excluding all overloads of the
same name) never matches.

Impact:
C++ functions intended to be excluded from
__cyg_profile_func_enter/__cyg_profile_func_exit (such as low-level hooks or
specific overloads specified by signature per invoke.texi) remain instrumented,
causing infinite recursion in profiling/tracing hooks or failing to exclude
targeted C++ overloads.

Suggested Fix
-------------
In gcc/gimplify.cc:21900 (flag_instrument_functions_exclude_p), check both
lang_hooks.decl_printable_name (fndecl, 1) and lang_hooks.decl_printable_name
(fndecl, 2) against vec_char_p (flag_instrument_functions_exclude_functions).

Reply via email to