[all-commits] [llvm/llvm-project] abc873: [analyzer] Restrict CallDescription fuzzy builtin ...

Balazs Benics via All-commits all-commits at lists.llvm.org
Fri Feb 11 01:45:53 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: abc873694ff7cde3def6860564521e059cb542f8
      https://github.com/llvm/llvm-project/commit/abc873694ff7cde3def6860564521e059cb542f8
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2022-02-11 (Fri, 11 Feb 2022)

  Changed paths:
    M clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
    M clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp

  Log Message:
  -----------
  [analyzer] Restrict CallDescription fuzzy builtin matching

`CallDescriptions` for builtin functions relaxes the match rules
somewhat, so that the `CallDescription` will match for calls that have
some prefix or suffix. This was achieved by doing a `StringRef::contains()`.
However, this is somewhat problematic for builtins that are substrings
of each other.

Consider the following:

`CallDescription{ builtin, "memcpy"}` will match for
`__builtin_wmemcpy()` calls, which is unfortunate.

This patch addresses/works around the issue by checking if the
characters around the function's name are not part of the 'name'
semantically. In other words, to accept a match for `"memcpy"` the call
should not have alphanumeric (`[a-zA-Z]`) characters around the 'match'.

So, `CallDescription{ builtin, "memcpy"}` will not match on:

 - `__builtin_wmemcpy: there is a `w` alphanumeric character before the match.
 - `__builtin_memcpyFOoBar_inline`: there is a `F` character after the match.
 - `__builtin_memcpyX_inline`: there is an `X` character after the match.

But it will still match for:
 - `memcpy`: exact match
 - `__builtin_memcpy`: there is an _ before the match
 - `__builtin_memcpy_inline`: there is an _ after the match
 - `memcpy_inline_builtinFooBar`: there is an _ after the match

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D118388




More information about the All-commits mailing list