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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Dominic Plunkett <[email protected]>:

https://gcc.gnu.org/g:71bf33cd85c7c7f06efc8296a1a6af2bb204c669

commit r17-6866-g71bf33cd85c7c7f06efc8296a1a6af2bb204c669
Author: Dominic P <[email protected]>
Date:   Mon Nov 30 21:54:42 2026 +0000

    analyzer: handle calls whose fnspec says they write only errno

    region_model::on_call_pre treats a call to a builtin that it does not
    know as free of side effects only if the builtin is const or pure
    (const since r12-7270-g5fbcbcaff72, PR analyzer/104576).  Under
    -fmath-errno, acos, sqrt, log and the other math builtins that may set
    errno are neither, so a call to one of them may write any externally
    visible memory.  With acosf in place of sinf in uninit-pr104576.c, the
    analyzer then forgets *flag across the call and reports a use of
    uninitialized t on a path that cannot be taken.

    The fnspec of these builtins says that they write no memory other than
    errno.  When the fnspec says that a call may write errno and nothing
    through its pointer arguments, conjure a new value for errno and treat
    the call as having no other side effects.  This also applies to
    aligned_alloc and GOMP_alloc, whose fnspec is "mC" and which are not
    known functions of the analyzer: they no longer clobber globals.

    Assisted-by: Claude Opus 5.5 (Anthropic)
    Signed-off-by: Dominic P <[email protected]>

    gcc/analyzer/ChangeLog:

            * region-model.cc: Include "attr-fnspec.h".
            (region_model::on_call_pre): Handle calls whose fnspec says that
            they write only errno.

    gcc/testsuite/ChangeLog:

            * c-c++-common/analyzer/errno-math-1.c: New test.

Reply via email to