Skip to content

Commit 9225d08

Browse files
committed
[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 ed740e7, as the changes to the "caching logic" was not fixing anything.
1 parent 5e01234 commit 9225d08

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ void UnsafeFunctionsCheck::registerPPCallbacks(
226226
const SourceManager &SM, Preprocessor *PP,
227227
Preprocessor * /*ModuleExpanderPP*/) {
228228
this->PP = PP;
229+
}
230+
231+
void UnsafeFunctionsCheck::onEndOfTranslationUnit() {
232+
this->PP = nullptr;
229233
IsAnnexKAvailable.reset();
230234
}
231235

clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class UnsafeFunctionsCheck : public ClangTidyCheck {
3232

3333
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
3434
Preprocessor *ModuleExpanderPP) override;
35+
void onEndOfTranslationUnit() override;
3536

3637
private:
3738
/// If true, additional functions from widely used API-s (such as POSIX) are

clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// This test fails on "x86_64-sie" buildbot and "x86_64-scei-ps4" target.
2+
// According to @dyung, something related to the kind of standard library
3+
// availability is causing the failure. Even though we explicitly define
4+
// the relevant macros the check is hunting for in the invocation, the real
5+
// parsing and preprocessor state will not have that case.
6+
// UNSUPPORTED: target={{.*-(ps4|ps5)}}
7+
//
18
// 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
29
// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__ -U__STDC_WANT_LIB_EXT1__
310
// 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);
1623
void f1(char *S) {
1724
gets(S);
1825
// 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]
19-
// 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
20-
// 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
26+
// FIXME(?): On target=x86_64-scie-ps4, the above warning in the
27+
// "-WITH-ANNEX-K" case will still report the suggestion to use 'fgets'
28+
// instead of the expected 'get_s', as if "Annex K" was not available.
29+
// 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
30+
// 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
2131

2232
strlen(S);
2333
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'strlen' is not bounds-checking; 'strnlen_s' should be used instead

0 commit comments

Comments
 (0)