[clang-tools-extra] Ensure functions are anchored in the global namespace (PR #99380)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 17 12:43:17 PDT 2024
https://github.com/matthew-f created https://github.com/llvm/llvm-project/pull/99380
The regular expressions match functions that aren't anchored in the global namespace. For example `::remove` matches any object with a `removeXyz` method. This change is to remove these false positives
>From d5aa95877b2c33189be77ecd2914565f77a76ba8 Mon Sep 17 00:00:00 2001
From: matthew-f <551862+matthew-f at users.noreply.github.com>
Date: Tue, 16 Jul 2024 20:50:45 +0200
Subject: [PATCH 1/4] Ensure functions are in the global namespace
---
.../bugprone/UnusedReturnValueCheck.cpp | 124 +++++++++---------
1 file changed, 62 insertions(+), 62 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index 73373147e96fc..c5252966ebe6f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -76,69 +76,69 @@ UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
"::std::upper_bound$;"
"::std::vector::at$;"
// C standard library
- "::bsearch$;"
- "::ferror$;"
- "::feof$;"
- "::isalnum$;"
- "::isalpha$;"
- "::isblank$;"
- "::iscntrl$;"
- "::isdigit$;"
- "::isgraph$;"
- "::islower$;"
- "::isprint$;"
- "::ispunct$;"
- "::isspace$;"
- "::isupper$;"
- "::iswalnum$;"
- "::iswprint$;"
- "::iswspace$;"
- "::isxdigit$;"
- "::memchr$;"
- "::memcmp$;"
- "::strcmp$;"
- "::strcoll$;"
- "::strncmp$;"
- "::strpbrk$;"
- "::strrchr$;"
- "::strspn$;"
- "::strstr$;"
- "::wcscmp$;"
+ "^::bsearch$;"
+ "^::ferror$;"
+ "^::feof$;"
+ "^::isalnum$;"
+ "^::isalpha$;"
+ "^::isblank$;"
+ "^::iscntrl$;"
+ "^::isdigit$;"
+ "^::isgraph$;"
+ "^::islower$;"
+ "^::isprint$;"
+ "^::ispunct$;"
+ "^::isspace$;"
+ "^::isupper$;"
+ "^::iswalnum$;"
+ "^::iswprint$;"
+ "^::iswspace$;"
+ "^::isxdigit$;"
+ "^::memchr$;"
+ "^::memcmp$;"
+ "^::strcmp$;"
+ "^::strcoll$;"
+ "^::strncmp$;"
+ "^::strpbrk$;"
+ "^::strrchr$;"
+ "^::strspn$;"
+ "^::strstr$;"
+ "^::wcscmp$;"
// POSIX
- "::access$;"
- "::bind$;"
- "::connect$;"
- "::difftime$;"
- "::dlsym$;"
- "::fnmatch$;"
- "::getaddrinfo$;"
- "::getopt$;"
- "::htonl$;"
- "::htons$;"
- "::iconv_open$;"
- "::inet_addr$;"
- "::isascii$;"
- "::isatty$;"
- "::mmap$;"
- "::newlocale$;"
- "::openat$;"
- "::pathconf$;"
- "::pthread_equal$;"
- "::pthread_getspecific$;"
- "::pthread_mutex_trylock$;"
- "::readdir$;"
- "::readlink$;"
- "::recvmsg$;"
- "::regexec$;"
- "::scandir$;"
- "::semget$;"
- "::setjmp$;"
- "::shm_open$;"
- "::shmget$;"
- "::sigismember$;"
- "::strcasecmp$;"
- "::strsignal$;"
- "::ttyname"))),
+ "^::access$;"
+ "^::bind$;"
+ "^^::connect$;"
+ "^::difftime$;"
+ "^::dlsym$;"
+ "^::fnmatch$;"
+ "^::getaddrinfo$;"
+ "^::getopt$;"
+ "^::htonl$;"
+ "^::htons$;"
+ "^::iconv_open$;"
+ "^::inet_addr$;"
+ "^::isascii$;"
+ "^::isatty$;"
+ "^::mmap$;"
+ "^::newlocale$;"
+ "^::openat$;"
+ "^::pathconf$;"
+ "^::pthread_equal$;"
+ "^::pthread_getspecific$;"
+ "^::pthread_mutex_trylock$;"
+ "^::readdir$;"
+ "^::readlink$;"
+ "^::recvmsg$;"
+ "^::regexec$;"
+ "^::scandir$;"
+ "^::semget$;"
+ "^::setjmp$;"
+ "^::shm_open$;"
+ "^::shmget$;"
+ "^::sigismember$;"
+ "^::strcasecmp$;"
+ "^::strsignal$;"
+ "^::ttyname"))),
CheckedReturnTypes(utils::options::parseStringList(
Options.get("CheckedReturnTypes", "::std::error_code$;"
"::std::error_condition$;"
>From c4fd20f61f518f6c9c35704a2edbcfbeb102bdc6 Mon Sep 17 00:00:00 2001
From: matthew-f <551862+matthew-f at users.noreply.github.com>
Date: Tue, 16 Jul 2024 20:54:43 +0200
Subject: [PATCH 2/4] Ensure functions are in the global namespace
---
.../clang-tidy/bugprone/UnusedReturnValueCheck.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index c5252966ebe6f..8601aefa60c6c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -107,7 +107,7 @@ UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
// POSIX
"^::access$;"
"^::bind$;"
- "^^::connect$;"
+ "^::connect$;"
"^::difftime$;"
"^::dlsym$;"
"^::fnmatch$;"
>From a70dab488be4ede79f39e21fcea5579cf3f07dff Mon Sep 17 00:00:00 2001
From: matthew-f <551862+matthew-f at users.noreply.github.com>
Date: Tue, 16 Jul 2024 21:04:42 +0200
Subject: [PATCH 3/4] Ensure functions are anchored in the global namespace
---
.../bugprone/UnusedReturnValueCheck.cpp | 54 +++++++++----------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index 8601aefa60c6c..955a9b94dfaf6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -48,33 +48,33 @@ UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
CheckedFunctions(utils::options::parseStringList(
- Options.get("CheckedFunctions", "::std::async$;"
- "::std::launder$;"
- "::std::remove$;"
- "::std::remove_if$;"
- "::std::unique$;"
- "::std::unique_ptr::release$;"
- "::std::basic_string::empty$;"
- "::std::vector::empty$;"
- "::std::back_inserter$;"
- "::std::distance$;"
- "::std::find$;"
- "::std::find_if$;"
- "::std::inserter$;"
- "::std::lower_bound$;"
- "::std::make_pair$;"
- "::std::map::count$;"
- "::std::map::find$;"
- "::std::map::lower_bound$;"
- "::std::multimap::equal_range$;"
- "::std::multimap::upper_bound$;"
- "::std::set::count$;"
- "::std::set::find$;"
- "::std::setfill$;"
- "::std::setprecision$;"
- "::std::setw$;"
- "::std::upper_bound$;"
- "::std::vector::at$;"
+ Options.get("CheckedFunctions", "^::std::async$;"
+ "^::std::launder$;"
+ "^::std::remove$;"
+ "^::std::remove_if$;"
+ "^::std::unique$;"
+ "^::std::unique_ptr::release$;"
+ "^::std::basic_string::empty$;"
+ "^::std::vector::empty$;"
+ "^::std::back_inserter$;"
+ "^::std::distance$;"
+ "^::std::find$;"
+ "^::std::find_if$;"
+ "^::std::inserter$;"
+ "^::std::lower_bound$;"
+ "^::std::make_pair$;"
+ "^::std::map::count$;"
+ "^::std::map::find$;"
+ "^::std::map::lower_bound$;"
+ "^::std::multimap::equal_range$;"
+ "^::std::multimap::upper_bound$;"
+ "^::std::set::count$;"
+ "^::std::set::find$;"
+ "^::std::setfill$;"
+ "^::std::setprecision$;"
+ "^::std::setw$;"
+ "^::std::upper_bound$;"
+ "^::std::vector::at$;"
// C standard library
"^::bsearch$;"
"^::ferror$;"
>From 0700840a2e4aae3d00ac49d1652274bbf0bc8412 Mon Sep 17 00:00:00 2001
From: matthew-f <551862+matthew-f at users.noreply.github.com>
Date: Wed, 17 Jul 2024 21:34:10 +0200
Subject: [PATCH 4/4] Ensure functions are anchored in the global namespace
The regular expressions match functions that aren't anchored in the global namespace. For example "::remove" matches and object with a "removeXyz" method. This change is to remove these false positives
---
.../clang-tidy/cert/CERTTidyModule.cpp | 354 +++++++++---------
1 file changed, 177 insertions(+), 177 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index ffb62b409b29b..8b5be9cd95f76 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -49,183 +49,183 @@ namespace {
// with NULL argument and in this case the check is not applicable:
// `mblen, mbrlen, mbrtowc, mbtowc, wctomb, wctomb_s`.
// FIXME: The check can be improved to handle such cases.
-const llvm::StringRef CertErr33CCheckedFunctions = "::aligned_alloc;"
- "::asctime_s;"
- "::at_quick_exit;"
- "::atexit;"
- "::bsearch;"
- "::bsearch_s;"
- "::btowc;"
- "::c16rtomb;"
- "::c32rtomb;"
- "::calloc;"
- "::clock;"
- "::cnd_broadcast;"
- "::cnd_init;"
- "::cnd_signal;"
- "::cnd_timedwait;"
- "::cnd_wait;"
- "::ctime_s;"
- "::fclose;"
- "::fflush;"
- "::fgetc;"
- "::fgetpos;"
- "::fgets;"
- "::fgetwc;"
- "::fopen;"
- "::fopen_s;"
- "::fprintf;"
- "::fprintf_s;"
- "::fputc;"
- "::fputs;"
- "::fputwc;"
- "::fputws;"
- "::fread;"
- "::freopen;"
- "::freopen_s;"
- "::fscanf;"
- "::fscanf_s;"
- "::fseek;"
- "::fsetpos;"
- "::ftell;"
- "::fwprintf;"
- "::fwprintf_s;"
- "::fwrite;"
- "::fwscanf;"
- "::fwscanf_s;"
- "::getc;"
- "::getchar;"
- "::getenv;"
- "::getenv_s;"
- "::gets_s;"
- "::getwc;"
- "::getwchar;"
- "::gmtime;"
- "::gmtime_s;"
- "::localtime;"
- "::localtime_s;"
- "::malloc;"
- "::mbrtoc16;"
- "::mbrtoc32;"
- "::mbsrtowcs;"
- "::mbsrtowcs_s;"
- "::mbstowcs;"
- "::mbstowcs_s;"
- "::memchr;"
- "::mktime;"
- "::mtx_init;"
- "::mtx_lock;"
- "::mtx_timedlock;"
- "::mtx_trylock;"
- "::mtx_unlock;"
- "::printf_s;"
- "::putc;"
- "::putwc;"
- "::raise;"
- "::realloc;"
- "::remove;"
- "::rename;"
- "::scanf;"
- "::scanf_s;"
- "::setlocale;"
- "::setvbuf;"
- "::signal;"
- "::snprintf;"
- "::snprintf_s;"
- "::sprintf;"
- "::sprintf_s;"
- "::sscanf;"
- "::sscanf_s;"
- "::strchr;"
- "::strerror_s;"
- "::strftime;"
- "::strpbrk;"
- "::strrchr;"
- "::strstr;"
- "::strtod;"
- "::strtof;"
- "::strtoimax;"
- "::strtok;"
- "::strtok_s;"
- "::strtol;"
- "::strtold;"
- "::strtoll;"
- "::strtoul;"
- "::strtoull;"
- "::strtoumax;"
- "::strxfrm;"
- "::swprintf;"
- "::swprintf_s;"
- "::swscanf;"
- "::swscanf_s;"
- "::thrd_create;"
- "::thrd_detach;"
- "::thrd_join;"
- "::thrd_sleep;"
- "::time;"
- "::timespec_get;"
- "::tmpfile;"
- "::tmpfile_s;"
- "::tmpnam;"
- "::tmpnam_s;"
- "::tss_create;"
- "::tss_get;"
- "::tss_set;"
- "::ungetc;"
- "::ungetwc;"
- "::vfprintf;"
- "::vfprintf_s;"
- "::vfscanf;"
- "::vfscanf_s;"
- "::vfwprintf;"
- "::vfwprintf_s;"
- "::vfwscanf;"
- "::vfwscanf_s;"
- "::vprintf_s;"
- "::vscanf;"
- "::vscanf_s;"
- "::vsnprintf;"
- "::vsnprintf_s;"
- "::vsprintf;"
- "::vsprintf_s;"
- "::vsscanf;"
- "::vsscanf_s;"
- "::vswprintf;"
- "::vswprintf_s;"
- "::vswscanf;"
- "::vswscanf_s;"
- "::vwprintf_s;"
- "::vwscanf;"
- "::vwscanf_s;"
- "::wcrtomb;"
- "::wcschr;"
- "::wcsftime;"
- "::wcspbrk;"
- "::wcsrchr;"
- "::wcsrtombs;"
- "::wcsrtombs_s;"
- "::wcsstr;"
- "::wcstod;"
- "::wcstof;"
- "::wcstoimax;"
- "::wcstok;"
- "::wcstok_s;"
- "::wcstol;"
- "::wcstold;"
- "::wcstoll;"
- "::wcstombs;"
- "::wcstombs_s;"
- "::wcstoul;"
- "::wcstoull;"
- "::wcstoumax;"
- "::wcsxfrm;"
- "::wctob;"
- "::wctrans;"
- "::wctype;"
- "::wmemchr;"
- "::wprintf_s;"
- "::wscanf;"
- "::wscanf_s;";
+const llvm::StringRef CertErr33CCheckedFunctions = "^::aligned_alloc;"
+ "^::asctime_s;"
+ "^::at_quick_exit;"
+ "^::atexit;"
+ "^::bsearch;"
+ "^::bsearch_s;"
+ "^::btowc;"
+ "^::c16rtomb;"
+ "^::c32rtomb;"
+ "^::calloc;"
+ "^::clock;"
+ "^::cnd_broadcast;"
+ "^::cnd_init;"
+ "^::cnd_signal;"
+ "^::cnd_timedwait;"
+ "^::cnd_wait;"
+ "^::ctime_s;"
+ "^::fclose;"
+ "^::fflush;"
+ "^::fgetc;"
+ "^::fgetpos;"
+ "^::fgets;"
+ "^::fgetwc;"
+ "^::fopen;"
+ "^::fopen_s;"
+ "^::fprintf;"
+ "^::fprintf_s;"
+ "^::fputc;"
+ "^::fputs;"
+ "^::fputwc;"
+ "^::fputws;"
+ "^::fread;"
+ "^::freopen;"
+ "^::freopen_s;"
+ "^::fscanf;"
+ "^::fscanf_s;"
+ "^::fseek;"
+ "^::fsetpos;"
+ "^::ftell;"
+ "^::fwprintf;"
+ "^::fwprintf_s;"
+ "^::fwrite;"
+ "^::fwscanf;"
+ "^::fwscanf_s;"
+ "^::getc;"
+ "^::getchar;"
+ "^::getenv;"
+ "^::getenv_s;"
+ "^::gets_s;"
+ "^::getwc;"
+ "^::getwchar;"
+ "^::gmtime;"
+ "^::gmtime_s;"
+ "^::localtime;"
+ "^::localtime_s;"
+ "^::malloc;"
+ "^::mbrtoc16;"
+ "^::mbrtoc32;"
+ "^::mbsrtowcs;"
+ "^::mbsrtowcs_s;"
+ "^::mbstowcs;"
+ "^::mbstowcs_s;"
+ "^::memchr;"
+ "^::mktime;"
+ "^::mtx_init;"
+ "^::mtx_lock;"
+ "^::mtx_timedlock;"
+ "^::mtx_trylock;"
+ "^::mtx_unlock;"
+ "^::printf_s;"
+ "^::putc;"
+ "^::putwc;"
+ "^::raise;"
+ "^::realloc;"
+ "^::remove;"
+ "^::rename;"
+ "^::scanf;"
+ "^::scanf_s;"
+ "^::setlocale;"
+ "^::setvbuf;"
+ "^::signal;"
+ "^::snprintf;"
+ "^::snprintf_s;"
+ "^::sprintf;"
+ "^::sprintf_s;"
+ "^::sscanf;"
+ "^::sscanf_s;"
+ "^::strchr;"
+ "^::strerror_s;"
+ "^::strftime;"
+ "^::strpbrk;"
+ "^::strrchr;"
+ "^::strstr;"
+ "^::strtod;"
+ "^::strtof;"
+ "^::strtoimax;"
+ "^::strtok;"
+ "^::strtok_s;"
+ "^::strtol;"
+ "^::strtold;"
+ "^::strtoll;"
+ "^::strtoul;"
+ "^::strtoull;"
+ "^::strtoumax;"
+ "^::strxfrm;"
+ "^::swprintf;"
+ "^::swprintf_s;"
+ "^::swscanf;"
+ "^::swscanf_s;"
+ "^::thrd_create;"
+ "^::thrd_detach;"
+ "^::thrd_join;"
+ "^::thrd_sleep;"
+ "^::time;"
+ "^::timespec_get;"
+ "^::tmpfile;"
+ "^::tmpfile_s;"
+ "^::tmpnam;"
+ "^::tmpnam_s;"
+ "^::tss_create;"
+ "^::tss_get;"
+ "^::tss_set;"
+ "^::ungetc;"
+ "^::ungetwc;"
+ "^::vfprintf;"
+ "^::vfprintf_s;"
+ "^::vfscanf;"
+ "^::vfscanf_s;"
+ "^::vfwprintf;"
+ "^::vfwprintf_s;"
+ "^::vfwscanf;"
+ "^::vfwscanf_s;"
+ "^::vprintf_s;"
+ "^::vscanf;"
+ "^::vscanf_s;"
+ "^::vsnprintf;"
+ "^::vsnprintf_s;"
+ "^::vsprintf;"
+ "^::vsprintf_s;"
+ "^::vsscanf;"
+ "^::vsscanf_s;"
+ "^::vswprintf;"
+ "^::vswprintf_s;"
+ "^::vswscanf;"
+ "^::vswscanf_s;"
+ "^::vwprintf_s;"
+ "^::vwscanf;"
+ "^::vwscanf_s;"
+ "^::wcrtomb;"
+ "^::wcschr;"
+ "^::wcsftime;"
+ "^::wcspbrk;"
+ "^::wcsrchr;"
+ "^::wcsrtombs;"
+ "^::wcsrtombs_s;"
+ "^::wcsstr;"
+ "^::wcstod;"
+ "^::wcstof;"
+ "^::wcstoimax;"
+ "^::wcstok;"
+ "^::wcstok_s;"
+ "^::wcstol;"
+ "^::wcstold;"
+ "^::wcstoll;"
+ "^::wcstombs;"
+ "^::wcstombs_s;"
+ "^::wcstoul;"
+ "^::wcstoull;"
+ "^::wcstoumax;"
+ "^::wcsxfrm;"
+ "^::wctob;"
+ "^::wctrans;"
+ "^::wctype;"
+ "^::wmemchr;"
+ "^::wprintf_s;"
+ "^::wscanf;"
+ "^::wscanf_s;";
} // namespace
More information about the cfe-commits
mailing list