[clang-tools-extra] 9225d08 - [NFC][clang-tidy] Disable test for `bugprone-unsafe-functions` for PlayStation
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 2 07:35:20 PST 2023
Author: Whisperity
Date: 2023-02-02T16:35:08+01:00
New Revision: 9225d08ccca5be900c07eb89e907c4092bbdd462
URL: https://github.com/llvm/llvm-project/commit/9225d08ccca5be900c07eb89e907c4092bbdd462
DIFF: https://github.com/llvm/llvm-project/commit/9225d08ccca5be900c07eb89e907c4092bbdd462.diff
LOG: [NFC][clang-tidy] Disable test for `bugprone-unsafe-functions` for PlayStation
As discussed in [D91000](http://reviews.llvm.org/D91000) with @dyung, the
PlayStation-specific targets are using some custom standard library for
which the current written tests are not appropriate. Even though the
test code defines the `__STDC_LIB_EXT1__` and `__STDC_WANT_LIB_EXT1__`
macros and expected *Annex K.* support, the actual Clang
parser/preprocessor will report these macros as not existing, and thus
fail the tests.
The check reports the **non**-Annex K. functions as suggestions, such as
`fgets()` instead of `gets_s()` to replace `gets()`, so some safe
library suggestions are still there.
This patch is primarily done to unblock the relevant buildbot
[`llvm-clang-x86_64-sie-ubuntu-fast`](http://lab.llvm.org/buildbot/#/builders/139).
This commit partially reverts ed740e741ec22f9aaea09bfc0b87d0801a7c492f,
as the changes to the "caching logic" was not fixing anything.
Added:
Modified:
clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h
clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
index c069cc3ea33ad..ebb49645b5904 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
@@ -226,6 +226,10 @@ void UnsafeFunctionsCheck::registerPPCallbacks(
const SourceManager &SM, Preprocessor *PP,
Preprocessor * /*ModuleExpanderPP*/) {
this->PP = PP;
+}
+
+void UnsafeFunctionsCheck::onEndOfTranslationUnit() {
+ this->PP = nullptr;
IsAnnexKAvailable.reset();
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h
index f04a220fd12e2..369ea25f693cc 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h
@@ -32,6 +32,7 @@ class UnsafeFunctionsCheck : public ClangTidyCheck {
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
+ void onEndOfTranslationUnit() override;
private:
/// If true, additional functions from widely used API-s (such as POSIX) are
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c
index 62754fa68111b..9c8eb7d5cbf11 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c
@@ -1,3 +1,10 @@
+// This test fails on "x86_64-sie" buildbot and "x86_64-scei-ps4" target.
+// According to @dyung, something related to the kind of standard library
+// availability is causing the failure. Even though we explicitly define
+// the relevant macros the check is hunting for in the invocation, the real
+// parsing and preprocessor state will not have that case.
+// UNSUPPORTED: target={{.*-(ps4|ps5)}}
+//
// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K %s bugprone-unsafe-functions %t -- -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__ -U__STDC_WANT_LIB_EXT1__
// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -D__STDC_LIB_EXT1__=1 -U__STDC_WANT_LIB_EXT1__
@@ -16,8 +23,11 @@ size_t wcslen(const wchar_t *S);
void f1(char *S) {
gets(S);
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'gets' is insecure, was deprecated and removed in C11 and C++14; 'gets_s' should be used instead [bugprone-unsafe-functions]
- // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'gets' is insecure, was deprecated and removed in C11 and C++14; 'gets_s' should be used instead
- // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-3]]:3: warning: function 'gets' is insecure, was deprecated and removed in C11 and C++14; 'fgets' should be used instead
+ // FIXME(?): On target=x86_64-scie-ps4, the above warning in the
+ // "-WITH-ANNEX-K" case will still report the suggestion to use 'fgets'
+ // instead of the expected 'get_s', as if "Annex K" was not available.
+ // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-5]]:3: warning: function 'gets' is insecure, was deprecated and removed in C11 and C++14; 'gets_s' should be used instead
+ // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-6]]:3: warning: function 'gets' is insecure, was deprecated and removed in C11 and C++14; 'fgets' should be used instead
strlen(S);
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'strlen' is not bounds-checking; 'strnlen_s' should be used instead
More information about the cfe-commits
mailing list