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

--- Comment #11 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
(In reply to Andrew Cooper from comment #9)
[...snip...]
> Would a const annotation on get_cpu_info() be likely to help?  It occurs to
> me that this is true in all cases that the compiler could legitimately
> reason about.  (It would only cease being true if we fell off our stack, at
> which point UB is the very least of our worries.)

Probably not (without further patching of the analyzer, at least).

For functions it can't see the definition of, the analyzer will respect const
annotations and treat such a function as always returning the same results when
given the same set of arguments.

However, I don't think it will respect a const annotation on an function it can
see the definition of; I think in your case it will simply try to (badly)
simulate the insides of get_cpu_info.   To what extent that's going to lead to
false positives is hard to say.

Reply via email to