Skip to content

[clang-tidy] Do not flag strerror in concurrency-mt-unsafe #140520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025

Conversation

carlosgalvezp
Copy link
Contributor

The docs of the check state:

Glibc’s list is compiled from GNU web documentation with a search for MT-Safe tag

And strerror fulfills exactly that: https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html

Function: char * strerror (int errnum)
Preliminary: | MT-Safe | AS-Unsafe heap i18n | AC-Unsafe mem | See POSIX Safety Concepts.

So concurrency-mt-unsafe should not flag it.

Fixes #140515

The docs of the check state:

> Glibc’s list is compiled from GNU web documentation with a search for MT-Safe tag

And strerror fulfills exactly that: https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html

> Function: char * strerror (int errnum)
> Preliminary: | MT-Safe | AS-Unsafe heap i18n | AC-Unsafe mem | See POSIX Safety Concepts.

So concurrency-mt-unsafe should not flag it.

Fixes llvm#140515
@llvmbot
Copy link
Member

llvmbot commented May 19, 2025

@llvm/pr-subscribers-clang-tidy

Author: Carlos Galvez (carlosgalvezp)

Changes

The docs of the check state:

> Glibc’s list is compiled from GNU web documentation with a search for MT-Safe tag

And strerror fulfills exactly that: https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html

> Function: char * strerror (int errnum)
> Preliminary: | MT-Safe | AS-Unsafe heap i18n | AC-Unsafe mem | See POSIX Safety Concepts.

So concurrency-mt-unsafe should not flag it.

Fixes #140515


Full diff: https://github.com/llvm/llvm-project/pull/140520.diff

3 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp (-1)
  • (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/concurrency/mt-unsafe-glibc.cpp (+3)
diff --git a/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp b/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp
index acffaa30d418e..cf076bb40484f 100644
--- a/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp
@@ -153,7 +153,6 @@ static const clang::StringRef GlibcFunctions[] = {
     "::sigsuspend",
     "::sleep",
     "::srand48",
-    "::strerror",
     "::strsignal",
     "::strtok",
     "::tcflow",
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 9b29ab12e1bfa..bd78b26b583c8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -172,6 +172,10 @@ Changes in existing checks
   <clang-tidy/checks/cert/err33-c>` check by fixing false positives when
   a function name is just prefixed with a targeted function name.
 
+- Improved :doc:`concurrency-mt-unsafe
+  <clang-tidy/checks/concurrency/mt-unsafe>` check by fixing a false positive
+  where `strerror` was flagged as MT-unsafe.
+
 - Improved :doc:`misc-const-correctness
   <clang-tidy/checks/misc/const-correctness>` check by adding the option
   `AllowedTypes`, that excludes specified types from const-correctness
diff --git a/clang-tools-extra/test/clang-tidy/checkers/concurrency/mt-unsafe-glibc.cpp b/clang-tools-extra/test/clang-tidy/checkers/concurrency/mt-unsafe-glibc.cpp
index 8b137de005a47..14d1912683795 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/concurrency/mt-unsafe-glibc.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/concurrency/mt-unsafe-glibc.cpp
@@ -3,6 +3,7 @@
 extern unsigned int sleep (unsigned int __seconds);
 extern int *gmtime (const int *__timer);
 extern char *dirname (char *__path);
+extern char *strerror(int errnum);
 
 void foo() {
   sleep(2);
@@ -12,4 +13,6 @@ void foo() {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [concurrency-mt-unsafe]
 
   dirname(nullptr);
+
+  strerror(0);
 }

@llvmbot
Copy link
Member

llvmbot commented May 19, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Carlos Galvez (carlosgalvezp)

Changes

The docs of the check state:

> Glibc’s list is compiled from GNU web documentation with a search for MT-Safe tag

And strerror fulfills exactly that: https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html

> Function: char * strerror (int errnum)
> Preliminary: | MT-Safe | AS-Unsafe heap i18n | AC-Unsafe mem | See POSIX Safety Concepts.

So concurrency-mt-unsafe should not flag it.

Fixes #140515


Full diff: https://github.com/llvm/llvm-project/pull/140520.diff

3 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp (-1)
  • (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/concurrency/mt-unsafe-glibc.cpp (+3)
diff --git a/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp b/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp
index acffaa30d418e..cf076bb40484f 100644
--- a/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp
@@ -153,7 +153,6 @@ static const clang::StringRef GlibcFunctions[] = {
     "::sigsuspend",
     "::sleep",
     "::srand48",
-    "::strerror",
     "::strsignal",
     "::strtok",
     "::tcflow",
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 9b29ab12e1bfa..bd78b26b583c8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -172,6 +172,10 @@ Changes in existing checks
   <clang-tidy/checks/cert/err33-c>` check by fixing false positives when
   a function name is just prefixed with a targeted function name.
 
+- Improved :doc:`concurrency-mt-unsafe
+  <clang-tidy/checks/concurrency/mt-unsafe>` check by fixing a false positive
+  where `strerror` was flagged as MT-unsafe.
+
 - Improved :doc:`misc-const-correctness
   <clang-tidy/checks/misc/const-correctness>` check by adding the option
   `AllowedTypes`, that excludes specified types from const-correctness
diff --git a/clang-tools-extra/test/clang-tidy/checkers/concurrency/mt-unsafe-glibc.cpp b/clang-tools-extra/test/clang-tidy/checkers/concurrency/mt-unsafe-glibc.cpp
index 8b137de005a47..14d1912683795 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/concurrency/mt-unsafe-glibc.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/concurrency/mt-unsafe-glibc.cpp
@@ -3,6 +3,7 @@
 extern unsigned int sleep (unsigned int __seconds);
 extern int *gmtime (const int *__timer);
 extern char *dirname (char *__path);
+extern char *strerror(int errnum);
 
 void foo() {
   sleep(2);
@@ -12,4 +13,6 @@ void foo() {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [concurrency-mt-unsafe]
 
   dirname(nullptr);
+
+  strerror(0);
 }

Copy link
Member

@PiotrZSL PiotrZSL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@carlosgalvezp carlosgalvezp merged commit 322d019 into llvm:main May 19, 2025
12 checks passed
@carlosgalvezp carlosgalvezp deleted the strerror branch May 19, 2025 19:27
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
The docs of the check state:

> Glibc’s list is compiled from GNU web documentation with a search for
MT-Safe tag

And strerror fulfills exactly that:
https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html

> Function: char * strerror (int errnum)
> Preliminary: | MT-Safe | AS-Unsafe heap i18n | AC-Unsafe mem | See
POSIX Safety Concepts.

So concurrency-mt-unsafe should not flag it.

Fixes llvm#140515

---------

Co-authored-by: Carlos Gálvez <[email protected]>
Co-authored-by: EugeneZelenko <[email protected]>
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 6, 2025
The docs of the check state:

> Glibc’s list is compiled from GNU web documentation with a search for
MT-Safe tag

And strerror fulfills exactly that:
https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html

> Function: char * strerror (int errnum)
> Preliminary: | MT-Safe | AS-Unsafe heap i18n | AC-Unsafe mem | See
POSIX Safety Concepts.

So concurrency-mt-unsafe should not flag it.

Fixes llvm#140515

---------

Co-authored-by: Carlos Gálvez <[email protected]>
Co-authored-by: EugeneZelenko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang-tidy] concurrency-mt-unsafe should not flag strerror
4 participants