Skip to content

[clang-tidy] Add -std argument in check_clang_tidy.py for C files #150791

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

localspook
Copy link
Contributor

@localspook localspook commented Jul 26, 2025

Before, C tests were run with whatever Clang defaults to when you don't specify a standard.

The tests are adapted to account for various things:

  • typeof is changed to __typeof__; the non-__ugly__ spelling is only available with GNU extensions or C23.
  • In C23, bool is a keyword, so typedef foo bool; is invalid.
  • In C23, f() means f(void), not "takes arbitrary parameters".
  • In C23, K&R-style function definitions are removed.

We could also, instead of making the autodetection logic in check_clang_tidy.py more elaborate, force all tests to specify -std explicitly.

@llvmbot
Copy link
Member

llvmbot commented Jul 26, 2025

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

@llvm/pr-subscribers-clang-tidy

Author: Victor Chernyakin (localspook)

Changes

Before, the tests were run with whatever Clang defaults to when you don't specify a standard.

The tests are adapted to account for various things:

  • typeof is changed to __typeof__; the non-__ugly__ spelling is only available with GNU extensions or C23.
  • In C23, bool is a keyword, so typedef foo bool; is invalid.
  • In C23, f() means f(void), not "takes arbitrary parameters".
  • In C23, K&R-style function definitions are removed.

We could also, instead of making the autodetection logic in check_clang_tidy.py more elaborate, force all tests to specify -std explicitly.


Patch is 26.41 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/150791.diff

24 Files Affected:

  • (modified) clang-tools-extra/test/clang-tidy/check_clang_tidy.py (+13-4)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h (+2)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c (+2-2)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry.c (+2-2)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c (+5-5)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-relatedness.c (+9-7)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters.c (+22-6)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c (+1-1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-before-safe.c (+1-1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe.c (+1-1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c (+1-1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c (+1-1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-undef-stdc-want-lib-ext1.c (+1-1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.c (+5-2)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.c (+2-2)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c (+6-6)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/google/objc-function-naming.m (+1-1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.c (+1-1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.c (+6-2)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c (+1-1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c (+1-2)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-standard-types.h (+1-1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c (+3-3)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c (+1-1)
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 774bc970ef284..7e43c23d0e883 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -135,8 +135,7 @@ def __init__(self, args: argparse.Namespace, extra_args: List[str]) -> None:
                 "-fblocks",
             ] + self.clang_extra_args
 
-        if extension in [".cpp", ".hpp", ".mm"]:
-            self.clang_extra_args.append("-std=" + self.std)
+        self.clang_extra_args.append("-std=" + self.std)
 
         # Tests should not rely on STL being available, and instead provide mock
         # implementations of relevant APIs.
@@ -374,7 +373,7 @@ def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
     parser.add_argument(
         "-std",
         type=csv,
-        default=["c++11-or-later"],
+        default=None,
         help="Passed to clang. Special -or-later values are expanded.",
     )
     parser.add_argument(
@@ -382,7 +381,17 @@ def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
         action="store_true",
         help="allow partial line matches for fixes",
     )
-    return parser.parse_known_args()
+
+    args, extra_args = parser.parse_known_args()
+    if args.std is None:
+        _, extension = os.path.splitext(args.assume_filename or args.input_file_name)
+        args.std = (
+            ["c++11-or-later"]
+            if extension in [".cpp", ".hpp", ".mm"]
+            else ["c99-or-later"]
+        )
+
+    return (args, extra_args)
 
 
 def main() -> None:
diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h
index 28c26b73ba6b4..011c869d2b9a7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h
@@ -11,6 +11,8 @@
 
 // Special system calls.
 
+#if __STDC_VERSION__ < 202311L
 void other_call();
+#endif
 
 #endif // _SYSTEM_OTHER_H_
diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c b/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c
index 56c382c87f1f3..3f60860e1f425 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c
@@ -2,7 +2,7 @@
 
 #define MY_TEMP_FAILURE_RETRY(x) \
   ({                             \
-    typeof(x) __z;               \
+    __typeof__(x) __z;           \
     do                           \
       __z = (x);                 \
     while (__z == -1);           \
@@ -11,7 +11,7 @@
 
 #define MY_OTHER_TEMP_FAILURE_RETRY(x) \
   ({                                   \
-    typeof(x) __z;                     \
+    __typeof__(x) __z;                 \
     do                                 \
       __z = (x);                       \
     while (__z == -1);                 \
diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry.c b/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry.c
index 461fb4ad52542..1c71ebb75604e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry.c
@@ -2,7 +2,7 @@
 
 #define TEMP_FAILURE_RETRY(x)                                                  \
   ({                                                                           \
-    typeof(x) __z;                                                             \
+    __typeof__(x) __z;                                                         \
     do                                                                         \
       __z = (x);                                                               \
     while (__z == -1);                                                         \
@@ -130,7 +130,7 @@ void obscured_temp_failure_retry(void) {
 #undef TEMP_FAILURE_RETRY
 #define IMPL(x)                                                                \
   ({                                                                           \
-    typeof(x) __z;                                                             \
+    __typeof__(x) __z;                                                         \
     do                                                                         \
       __z = (x);                                                               \
     while (__z == -1);                                                         \
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
index a4cb7347f88c6..0f4389c885e8f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
@@ -1,11 +1,11 @@
 // RUN: %check_clang_tidy %s bugprone-branch-clone %t
 int x = 0;
 int y = 1;
-#define a(b, c) \
-  typeof(b) d;  \
-  if (b)        \
-    d = b;      \
-  else if (c)   \
+#define a(b, c)    \
+  __typeof__(b) d; \
+  if (b)           \
+    d = b;         \
+  else if (c)      \
     d = b;
 
 void f(void) {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-relatedness.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-relatedness.c
index 7231361a2e080..3d01f5745deaa 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-relatedness.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-relatedness.c
@@ -9,7 +9,6 @@
 // RUN:     bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold: 0 \
 // RUN:  }}' -- -Wno-strict-prototypes -x c
 
-int myprint();
 int add(int X, int Y);
 
 void notRelated(int A, int B) {}
@@ -19,13 +18,16 @@ void notRelated(int A, int B) {}
 
 int addedTogether(int A, int B) { return add(A, B); } // NO-WARN: Passed to same function.
 
+// FIXME: This triggers a false positive: the "passed to same function" heuristic
+// can't map the parameter index 1 to A and B because myprint() has no
+// parameters.
+//     warning: 2 adjacent parameters of 'passedToSameKNRFunction' of similar type ('int')
+//     note: the first parameter in the range is 'A'
+//     note: the last parameter in the range is 'B'
+#if 0
+int myprint();
 void passedToSameKNRFunction(int A, int B) {
   myprint("foo", A);
   myprint("bar", B);
 }
-// CHECK-MESSAGES: :[[@LINE-4]]:30: warning: 2 adjacent parameters of 'passedToSameKNRFunction' of similar type ('int')
-// CHECK-MESSAGES: :[[@LINE-5]]:34: note: the first parameter in the range is 'A'
-// CHECK-MESSAGES: :[[@LINE-6]]:41: note: the last parameter in the range is 'B'
-// This is actually a false positive: the "passed to same function" heuristic
-// can't map the parameter index 1 to A and B because myprint() has no
-// parameters.
+#endif
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters.c
index b6c9bf4ad0c15..1d06afd85f468 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters.c
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
+// RUN: %check_clang_tidy -std=c99,c11,c17 -check-suffixes=,BEFORE-23 %s bugprone-easily-swappable-parameters %t \
 // RUN:   -config='{CheckOptions: { \
 // RUN:     bugprone-easily-swappable-parameters.MinimumLength: 2, \
 // RUN:     bugprone-easily-swappable-parameters.IgnoredParameterNames: "", \
@@ -7,7 +7,18 @@
 // RUN:     bugprone-easily-swappable-parameters.ModelImplicitConversions: 0, \
 // RUN:     bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 0, \
 // RUN:     bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold: 0 \
-// RUN:  }}' -- -Wno-strict-prototypes -x c
+// RUN:  }}' -- -Wno-strict-prototypes
+//
+// RUN: %check_clang_tidy -std=c23 %s bugprone-easily-swappable-parameters %t \
+// RUN:   -config='{CheckOptions: { \
+// RUN:     bugprone-easily-swappable-parameters.MinimumLength: 2, \
+// RUN:     bugprone-easily-swappable-parameters.IgnoredParameterNames: "", \
+// RUN:     bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)", \
+// RUN:     bugprone-easily-swappable-parameters.QualifiersMix: 0, \
+// RUN:     bugprone-easily-swappable-parameters.ModelImplicitConversions: 0, \
+// RUN:     bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 0, \
+// RUN:     bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold: 0 \
+// RUN:  }}' -- -Wno-strict-prototypes
 
 #define bool _Bool
 #define true 1
@@ -45,8 +56,11 @@ void pointerConversion(int *IP, long *LP) {}
 
 void testVariadicsCall() {
   int IVal = 1;
+
+#if __STDC_VERSION__ < 202311L
   decl(IVal); // NO-WARN: Particular calls to "variadics" are like template
               // instantiations, and we do not model them.
+#endif
 
   variadic(IVal);          // NO-WARN.
   variadic(IVal, 2, 3, 4); // NO-WARN.
@@ -64,13 +78,15 @@ void taggedTypes2(struct S SVar1, struct S SVar2) {}
 
 void wrappers(struct { int I; } I1, struct { int I; } I2) {} // NO-WARN: Distinct anonymous types.
 
+#if __STDC_VERSION__ < 202311L
 void knr(I, J)
   int I;
   int J;
 {}
-// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: 2 adjacent parameters of 'knr' of similar type ('int')
-// CHECK-MESSAGES: :[[@LINE-4]]:7: note: the first parameter in the range is 'I'
-// CHECK-MESSAGES: :[[@LINE-4]]:7: note: the last parameter in the range is 'J'
+// CHECK-MESSAGES-BEFORE-23: :[[@LINE-3]]:3: warning: 2 adjacent parameters of 'knr' of similar type ('int')
+// CHECK-MESSAGES-BEFORE-23: :[[@LINE-4]]:7: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES-BEFORE-23: :[[@LINE-4]]:7: note: the last parameter in the range is 'J'
+#endif
 
 void boolAsWritten(bool B1, bool B2) {} // NO-WARN: The type name is ignored.
 // Note that "bool" is a macro that expands to "_Bool" internally, but it is
@@ -145,7 +161,7 @@ void thisIsGettingRidiculous(MAKE_PRIMITIVE_WRAPPER(int) I1,
 void macroMagic3(MAKE_LOGICAL_TYPE(char) B1, MAKE_LOGICAL_TYPE(long) B2) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 2 adjacent parameters of 'macroMagic3' of similar type ('bool')
 // CHECK-MESSAGES: :[[@LINE-4]]:30: note: expanded from macro 'MAKE_LOGICAL_TYPE'
-// CHECK-MESSAGES: :[[@LINE-136]]:14: note: expanded from macro 'bool'
+// CHECK-MESSAGES: :[[@LINE-141]]:14: note: expanded from macro 'bool'
 // CHECK-MESSAGES: :[[@LINE-4]]:42: note: the first parameter in the range is 'B1'
 // CHECK-MESSAGES: :[[@LINE-5]]:70: note: the last parameter in the range is 'B2'
 
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c
index a383958fbb906..b241d683b0cdc 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
 
 #include "not-null-terminated-result-c.h"
 
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-before-safe.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-before-safe.c
index 434cfcc0ca9d5..ea7e183b92531 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-before-safe.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-before-safe.c
@@ -1,7 +1,7 @@
 // RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
 // RUN: -config="{CheckOptions: \
 // RUN: {bugprone-not-null-terminated-result.WantToUseSafeFunction: true}}" \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
 
 #include "not-null-terminated-result-c.h"
 
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe.c
index 5a5e35ef733f6..ae430878daf21 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe.c
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
 
 #include "not-null-terminated-result-c.h"
 
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c
index 0628d0ca53300..94806714efc86 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
 
 #include "not-null-terminated-result-c.h"
 
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c
index 4970af83bf4b6..366c1698e4f2d 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
 
 // FIXME: Something wrong with the APInt un/signed conversion on Windows:
 // in 'strncmp(str6, "string", 7);' it tries to inject '4294967302' as length.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-undef-stdc-want-lib-ext1.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-undef-stdc-want-lib-ext1.c
index 2704dc1ee513b..bb5961f3b421e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-undef-stdc-want-lib-ext1.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-undef-stdc-want-lib-ext1.c
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
 
 #include "not-null-terminated-result-c.h"
 
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.c
index c7daec0870f49..a8f6f3bba20b9 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.c
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-signal-handler %t -- -- -isystem %clang_tidy_headers
+// RUN: %check_clang_tidy -std=c99,c11,c17 -check-suffixes=,BEFORE-23 %s bugprone-signal-handler %t -- -- -isystem %clang_tidy_headers
+// RUN: %check_clang_tidy -std=c23-or-later %s bugprone-signal-handler %t -- -- -isystem %clang_tidy_headers
 
 #include "signal.h"
 #include "stdlib.h"
@@ -174,8 +175,10 @@ void test_other(void) {
   signal(SIGINT, handler_signal);
 
   signal(SIGINT, _Exit);
+#if __STDC_VERSION__ < 202311L
   signal(SIGINT, other_call);
-  // CHECK-NOTES: :[[@LINE-1]]:18: warning: standard function 'other_call' may not be asynchronous-safe; using it as a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES-BEFORE-23: :[[@LINE-1]]:18: warning: standard function 'other_call' may not be asynchronous-safe; using it as a signal handler may be dangerous [bugprone-signal-handler]
+#endif
   signal(SIGINT, f_extern_handler);
   // CHECK-NOTES: :[[@LINE-1]]:18: warning: cannot verify that external function 'f_extern_handler' is asynchronous-safe; using it as a signal handler may be dangerous [bugprone-signal-handler]
 
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.c
index b898071a56613..871715b22cc56 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.c
@@ -1,5 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-sizeof-expression %t -- --
-// RUN: %check_clang_tidy %s bugprone-sizeof-expression %t -- -- -x c++
+// RUN: %check_clang_tidy %s bugprone-sizeof-expression %t
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-sizeof-expression %t -- -- -x c++
 
 #ifdef __cplusplus
 #define STRKWD
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 0409dd6bfcaa3..a87bc84434bd7 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
@@ -5,14 +5,14 @@
 // 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__
-// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K         %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__   -D__STDC_WANT_LIB_EXT1__=1
-// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K-CERT-ONLY  %s bugprone-unsafe-functions %t -- \
+// RUN: %check_clang_tidy -std=c11-or-later -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 -std=c11-or-later -check-suffix=WITHOUT-ANNEX-K         %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__   -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -std=c11-or-later -check-suffix=WITHOUT-ANNEX-K         %s bugprone-unsafe-functions %t -- -- -D__STDC_LIB_EXT1__=1 -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -std=c11-or-later -check-suffix=WITHOUT-ANNEX-K         %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__   -D__STDC_WANT_LIB_EXT1__=1
+// RUN: %check_clang_tidy -std=c11-or-later -check-suffix=WITH-ANNEX-K-CERT-ONLY  %s bugprone-unsafe-functions %t -- \
 // RUN:   -config="{CheckOptions: {bugprone-unsafe-functions.ReportMoreUnsafeFunctions: false}}" \
 // RUN:                                                                                            -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
-// RUN: %check_clang_tidy -check-suffix=WITH-NONE-ENABLED       %s...
[truncated]

Copy link
Contributor

@vbvictor vbvictor left a comment

Choose a reason for hiding this comment

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

Thank you for working on this.
This change is worth ReleaseNotes IMO, you could add them, we had release notes for change in check_clang_tidy.

Nit: try to start PR header with "Add/Fix/Update/Make" as majority commits in LLVM (e.g. Add -std argument in check_clang_tidy.py for C files). It takes less time for the reviewer to understand what you did because it follows established format. In general it's good to follow conventional commits (but LLVM use add instead of feat).

@localspook localspook changed the title [clang-tidy] Stop ignoring -std argument in check_clang_tidy.py for C files [clang-tidy] Add -std argument in check_clang_tidy.py for C files Jul 27, 2025
localspook and others added 2 commits July 28, 2025 06:19
Copy link
Contributor

@vbvictor vbvictor left a comment

Choose a reason for hiding this comment

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

LGTM, but I think we should wait for a second approve for some time. It's a kind-of big change and improvement for tests.

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.

4 participants