Skip to content

[clang][test] add TestLanguage.def to specify all tested language versions #94243

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

Conversation

5chmidti
Copy link
Contributor

@5chmidti 5chmidti commented Jun 3, 2024

Adds a def file to have a single location where tested language versions are specified. Removes the need to update multiple locations in the testing infrastructure to add a new language version to be tested. Test instatiation can now include all languages without needing to specify them.
This patch also adds pretty printing for instantiated test names. That means, that a test instantiated with C++23 will have the name ...TestSuite/TestName/CXX23 instead ending with some number (index of the argument for instantiation of the test), which provides a better experience when encountering a test failure with a specific language version. The suffix will also contain an _win if the target contains win.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jun 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 3, 2024

@llvm/pr-subscribers-clang

Author: Julian Schmidt (5chmidti)

Changes

Adds a def file to have a single location where tested language versions are specified. Removes the need to update multiple locations in the testing infrastructure to add a new language version to be tested. Test instatiation can now include all languages without needing to specify them.
This patch also adds pretty printing for instantiated test names. That means, that a test instantiated with C++23 will have the name ...TestSuite/TestName/CXX23 instead ending with some number (index of the argument for instantiation of the test), which improves a better experience when encountering a test failure with a specific language version. The suffix will also contain an _win if the target contains win.


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

12 Files Affected:

  • (modified) clang/include/clang/Testing/CommandLineArgs.h (+8-9)
  • (modified) clang/include/clang/Testing/TestClangConfig.h (+125-21)
  • (added) clang/include/clang/Testing/TestLanguage.def (+39)
  • (modified) clang/lib/Testing/CommandLineArgs.cpp (+52-67)
  • (modified) clang/unittests/AST/MatchVerifier.h (+6-31)
  • (modified) clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (+12-6)
  • (modified) clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (+7-3)
  • (modified) clang/unittests/Tooling/Syntax/BuildTreeTest.cpp (+6-2)
  • (modified) clang/unittests/Tooling/Syntax/MutationsTest.cpp (+5-2)
  • (modified) clang/unittests/Tooling/Syntax/SynthesisTest.cpp (+5-2)
  • (modified) clang/unittests/Tooling/Syntax/TreeTest.cpp (+10-4)
  • (modified) clang/unittests/Tooling/Syntax/TreeTestBase.cpp (+5-2)
diff --git a/clang/include/clang/Testing/CommandLineArgs.h b/clang/include/clang/Testing/CommandLineArgs.h
index e71907e8bbd0c..52beac7254fef 100644
--- a/clang/include/clang/Testing/CommandLineArgs.h
+++ b/clang/include/clang/Testing/CommandLineArgs.h
@@ -21,19 +21,18 @@
 namespace clang {
 
 enum TestLanguage {
-  Lang_C89,
-  Lang_C99,
-  Lang_CXX03,
-  Lang_CXX11,
-  Lang_CXX14,
-  Lang_CXX17,
-  Lang_CXX20,
-  Lang_CXX23,
+#define TESTLANGUAGE(lang, version, std_flag, version_index)                   \
+  Lang_##lang##version,
+#include "clang/Testing/TestLanguage.def"
+
   Lang_OpenCL,
   Lang_OBJC,
-  Lang_OBJCXX
+  Lang_OBJCXX,
 };
 
+std::vector<TestLanguage> getCOrLater(int MinimumStd);
+std::vector<TestLanguage> getCXXOrLater(int MinimumStd);
+
 std::vector<std::string> getCommandLineArgsForTesting(TestLanguage Lang);
 std::vector<std::string> getCC1ArgsForTesting(TestLanguage Lang);
 
diff --git a/clang/include/clang/Testing/TestClangConfig.h b/clang/include/clang/Testing/TestClangConfig.h
index 1b4efca80e9d4..4dd1eb9b6f39a 100644
--- a/clang/include/clang/Testing/TestClangConfig.h
+++ b/clang/include/clang/Testing/TestClangConfig.h
@@ -27,37 +27,117 @@ struct TestClangConfig {
   /// The argument of the `-target` command line flag.
   std::string Target;
 
-  bool isC() const { return Language == Lang_C89 || Language == Lang_C99; }
-
-  bool isC99OrLater() const { return Language == Lang_C99; }
-
-  bool isCXX() const {
-    return Language == Lang_CXX03 || Language == Lang_CXX11 ||
-           Language == Lang_CXX14 || Language == Lang_CXX17 ||
-           Language == Lang_CXX20 || Language == Lang_CXX23;
+  bool isC() const {
+    return false
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
+  || Language == Lang_##lang##version
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+        ;
   }
 
-  bool isCXX11OrLater() const {
-    return Language == Lang_CXX11 || Language == Lang_CXX14 ||
-           Language == Lang_CXX17 || Language == Lang_CXX20 ||
-           Language == Lang_CXX23;
+  bool isCOrLater(int MinimumStdVersion) const {
+    const auto MinimumStdVersionIndex = 0
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
+  +(MinimumStdVersion == version ? version_index : 0)
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+        ;
+    switch (Language) {
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
+  case Lang_##lang##version:                                                   \
+    return MinimumStdVersionIndex <= version_index;
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+    default:
+      return false;
+    }
   }
 
-  bool isCXX14OrLater() const {
-    return Language == Lang_CXX14 || Language == Lang_CXX17 ||
-           Language == Lang_CXX20 || Language == Lang_CXX23;
+  bool isC99OrLater() const { return isCOrLater(99); }
+
+  bool isCOrEarlier(int MaximumStdVersion) const {
+    const auto MaximumStdVersionIndex = 0
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
+  +(MaximumStdVersion == version ? version_index : 0)
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+        ;
+    switch (Language) {
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
+  case Lang_##lang##version:                                                   \
+    return MaximumStdVersionIndex >= version_index;
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+    default:
+      return false;
+    }
   }
 
-  bool isCXX17OrLater() const {
-    return Language == Lang_CXX17 || Language == Lang_CXX20 ||
-           Language == Lang_CXX23;
+  bool isCXX() const {
+    return false
+#define TESTLANGUAGE
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
+  || Language == Lang_##lang##version
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+        ;
   }
 
-  bool isCXX20OrLater() const {
-    return Language == Lang_CXX20 || Language == Lang_CXX23;
+  bool isCXXOrLater(int MinimumStdVersion) const {
+    const auto MinimumStdVersionIndex = 0
+#define TESTLANGUAGE
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
+  +(MinimumStdVersion == version ? version_index : 0)
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+        ;
+    switch (Language) {
+#define TESTLANGUAGE
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
+  case Lang_##lang##version:                                                   \
+    return MinimumStdVersionIndex <= version_index;
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+    default:
+      return false;
+    }
   }
 
-  bool isCXX23OrLater() const { return Language == Lang_CXX23; }
+  bool isCXX11OrLater() const { return isCXXOrLater(11); }
+
+  bool isCXX14OrLater() const { return isCXXOrLater(14); }
+
+  bool isCXX17OrLater() const { return isCXXOrLater(17); }
+
+  bool isCXX20OrLater() const { return isCXXOrLater(20); }
+
+  bool isCXX23OrLater() const { return isCXXOrLater(23); }
+
+  bool isCXXOrEarlier(int MaximumStdVersion) const {
+    const auto MaximumStdVersionIndex = 0
+#define TESTLANGUAGE
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
+  +(MaximumStdVersion == version ? version_index : 0)
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+        ;
+    switch (Language) {
+#define TESTLANGUAGE
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
+  case Lang_##lang##version:                                                   \
+    return MaximumStdVersionIndex >= version_index;
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+    default:
+      return false;
+    }
+  }
 
   bool supportsCXXDynamicExceptionSpecification() const {
     return Language == Lang_CXX03 || Language == Lang_CXX11 ||
@@ -75,6 +155,30 @@ struct TestClangConfig {
     return Result;
   }
 
+  std::string toShortString() const {
+    std::string Result;
+    llvm::raw_string_ostream OS(Result);
+    switch (Language) {
+#define TESTLANGUAGE(lang, version, std_flag, version_index)                   \
+  case Lang_##lang##version:                                                   \
+    OS << (#lang #version);                                                    \
+    break;
+#include "clang/Testing/TestLanguage.def"
+    case Lang_OpenCL:
+      OS << "OpenCL";
+      break;
+    case Lang_OBJC:
+      OS << "OBJC";
+      break;
+    case Lang_OBJCXX:
+      OS << "OBJCXX";
+      break;
+    }
+
+    OS << (Target.find("win") != std::string::npos ? "_win" : "");
+    return Result;
+  }
+
   std::string toString() const {
     std::string Result;
     llvm::raw_string_ostream OS(Result);
diff --git a/clang/include/clang/Testing/TestLanguage.def b/clang/include/clang/Testing/TestLanguage.def
new file mode 100644
index 0000000000000..88155a3e3d920
--- /dev/null
+++ b/clang/include/clang/Testing/TestLanguage.def
@@ -0,0 +1,39 @@
+
+//===-- TestLanguage.def - Language Versions for Testing --------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TESTLANGUAGE
+#error "TESTLANGUAGE must be defined before including this file"
+#endif
+
+#ifndef TESTLANGUAGE_C
+#define TESTLANGUAGE_C TESTLANGUAGE
+#endif
+
+#ifndef TESTLANGUAGE_CXX
+#define TESTLANGUAGE_CXX TESTLANGUAGE
+#endif
+
+TESTLANGUAGE_C(C, 89, c89, 0)
+TESTLANGUAGE_C(C, 99, c99, 1)
+TESTLANGUAGE_C(C, 11, c11, 2)
+TESTLANGUAGE_C(C, 17, c17, 3)
+TESTLANGUAGE_C(C, 23, c23, 4)
+
+// TESTLANGUAGE_CXX(CXX, 98, c++98, 0)
+TESTLANGUAGE_CXX(CXX, 03, c++03, 1)
+TESTLANGUAGE_CXX(CXX, 11, c++11, 2)
+TESTLANGUAGE_CXX(CXX, 14, c++14, 3)
+TESTLANGUAGE_CXX(CXX, 17, c++17, 4)
+TESTLANGUAGE_CXX(CXX, 20, c++20, 5)
+TESTLANGUAGE_CXX(CXX, 23, c++23, 6)
+TESTLANGUAGE_CXX(CXX, 26, c++26, 7)
+
+#undef TESTLANGUAGE_CXX
+#undef TESTLANGUAGE_C
+#undef TESTLANGUAGE
diff --git a/clang/lib/Testing/CommandLineArgs.cpp b/clang/lib/Testing/CommandLineArgs.cpp
index 3abc689b93e8d..15d5ad2bdc287 100644
--- a/clang/lib/Testing/CommandLineArgs.cpp
+++ b/clang/lib/Testing/CommandLineArgs.cpp
@@ -11,99 +11,84 @@
 #include "llvm/Support/ErrorHandling.h"
 
 namespace clang {
+std::vector<TestLanguage> getCOrLater(const int MinimumStd) {
+  std::vector<TestLanguage> Result{};
+
+#define TESTLANGUAGE(lang, version, std_flag, version_index)
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
+  if (version >= MinimumStd)                                                   \
+    Result.push_back(Lang_##lang##version);
+#include "clang/Testing/TestLanguage.def"
+
+  return Result;
+}
+std::vector<TestLanguage> getCXXOrLater(const int MinimumStd) {
+  std::vector<TestLanguage> Result{};
+
+#define TESTLANGUAGE(lang, version, std_flag, version_index)
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
+  if (version >= MinimumStd)                                                   \
+    Result.push_back(Lang_##lang##version);
+#include "clang/Testing/TestLanguage.def"
+
+  return Result;
+}
 
 std::vector<std::string> getCommandLineArgsForTesting(TestLanguage Lang) {
-  std::vector<std::string> Args;
   // Test with basic arguments.
   switch (Lang) {
-  case Lang_C89:
-    Args = {"-x", "c", "-std=c89"};
-    break;
-  case Lang_C99:
-    Args = {"-x", "c", "-std=c99"};
-    break;
-  case Lang_CXX03:
-    Args = {"-std=c++03", "-frtti"};
-    break;
-  case Lang_CXX11:
-    Args = {"-std=c++11", "-frtti"};
-    break;
-  case Lang_CXX14:
-    Args = {"-std=c++14", "-frtti"};
-    break;
-  case Lang_CXX17:
-    Args = {"-std=c++17", "-frtti"};
-    break;
-  case Lang_CXX20:
-    Args = {"-std=c++20", "-frtti"};
-    break;
-  case Lang_CXX23:
-    Args = {"-std=c++23", "-frtti"};
-    break;
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
+  case Lang_##lang##version:                                                   \
+    return { "-x", "c", "-std=" #std_flag };
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
+  case Lang_##lang##version:                                                   \
+    return { "-std=" #std_flag, "-frtti" };
+#include "clang/Testing/TestLanguage.def"
+
   case Lang_OBJC:
-    Args = {"-x", "objective-c", "-frtti", "-fobjc-nonfragile-abi"};
-    break;
+    return {"-x", "objective-c", "-frtti", "-fobjc-nonfragile-abi"};
   case Lang_OBJCXX:
-    Args = {"-x", "objective-c++", "-frtti"};
-    break;
+    return {"-x", "objective-c++", "-frtti"};
   case Lang_OpenCL:
     llvm_unreachable("Not implemented yet!");
   }
-  return Args;
+  llvm_unreachable("Not implemented yet!");
 }
 
 std::vector<std::string> getCC1ArgsForTesting(TestLanguage Lang) {
-  std::vector<std::string> Args;
   switch (Lang) {
-  case Lang_C89:
-    Args = {"-xc", "-std=c89"};
-    break;
-  case Lang_C99:
-    Args = {"-xc", "-std=c99"};
-    break;
-  case Lang_CXX03:
-    Args = {"-std=c++03"};
-    break;
-  case Lang_CXX11:
-    Args = {"-std=c++11"};
-    break;
-  case Lang_CXX14:
-    Args = {"-std=c++14"};
-    break;
-  case Lang_CXX17:
-    Args = {"-std=c++17"};
-    break;
-  case Lang_CXX20:
-    Args = {"-std=c++20"};
-    break;
-  case Lang_CXX23:
-    Args = {"-std=c++23"};
-    break;
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
+  case Lang_##lang##version:                                                   \
+    return { "-xc", "-std=" #std_flag };
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
+  case Lang_##lang##version:                                                   \
+    return { "-std=" #std_flag };
+#include "clang/Testing/TestLanguage.def"
+
   case Lang_OBJC:
-    Args = {"-xobjective-c"};
+    return {"-xobjective-c"};
     break;
   case Lang_OBJCXX:
-    Args = {"-xobjective-c++"};
+    return {"-xobjective-c++"};
     break;
   case Lang_OpenCL:
     llvm_unreachable("Not implemented yet!");
   }
-  return Args;
+  llvm_unreachable("Not implemented yet!");
 }
 
 StringRef getFilenameForTesting(TestLanguage Lang) {
   switch (Lang) {
-  case Lang_C89:
-  case Lang_C99:
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
+  case Lang_##lang##version:                                                   \
     return "input.c";
-
-  case Lang_CXX03:
-  case Lang_CXX11:
-  case Lang_CXX14:
-  case Lang_CXX17:
-  case Lang_CXX20:
-  case Lang_CXX23:
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
+  case Lang_##lang##version:                                                   \
     return "input.cc";
+#include "clang/Testing/TestLanguage.def"
 
   case Lang_OpenCL:
     return "input.cl";
diff --git a/clang/unittests/AST/MatchVerifier.h b/clang/unittests/AST/MatchVerifier.h
index da1e351da4a09..4a574e3242f60 100644
--- a/clang/unittests/AST/MatchVerifier.h
+++ b/clang/unittests/AST/MatchVerifier.h
@@ -88,38 +88,13 @@ MatchVerifier<NodeType>::match(const std::string &Code,
 
   StringRef FileName;
   switch (L) {
-  case Lang_C89:
-    Args.push_back("-std=c89");
-    FileName = "input.c";
-    break;
-  case Lang_C99:
-    Args.push_back("-std=c99");
-    FileName = "input.c";
-    break;
-  case Lang_CXX03:
-    Args.push_back("-std=c++03");
-    FileName = "input.cc";
-    break;
-  case Lang_CXX11:
-    Args.push_back("-std=c++11");
-    FileName = "input.cc";
-    break;
-  case Lang_CXX14:
-    Args.push_back("-std=c++14");
-    FileName = "input.cc";
-    break;
-  case Lang_CXX17:
-    Args.push_back("-std=c++17");
-    FileName = "input.cc";
-    break;
-  case Lang_CXX20:
-    Args.push_back("-std=c++20");
-    FileName = "input.cc";
-    break;
-  case Lang_CXX23:
-    Args.push_back("-std=c++23");
-    FileName = "input.cc";
+#define TESTLANGUAGE(lang, version, std_flag, version_index)                                  \
+  case Lang_##lang##version:                                                   \
+    Args.push_back("-std=" #std_flag);                                         \
+    FileName = getFilenameForTesting(Lang_##lang##version);                    \
     break;
+#include "clang/Testing/TestLanguage.def"
+
   case Lang_OpenCL:
     Args.push_back("-cl-no-stdinc");
     FileName = "input.cl";
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 2e42b85808953..aed6a6408adc9 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1224,7 +1224,7 @@ TEST_P(ASTMatchersTest, CastExpression_MatchesImplicitCasts) {
 }
 
 TEST_P(ASTMatchersTest, CastExpr_DoesNotMatchNonCasts) {
-  if (GetParam().Language == Lang_C89 || GetParam().Language == Lang_C99) {
+  if (GetParam().isC()) {
     // This does have a cast in C
     EXPECT_TRUE(matches("char c = '0';", implicitCastExpr()));
   } else {
@@ -1678,7 +1678,7 @@ TEST_P(ASTMatchersTest, FunctionProtoType) {
 }
 
 TEST_P(ASTMatchersTest, FunctionProtoType_C) {
-  if (!GetParam().isC()) {
+  if (!GetParam().isCOrEarlier(17)) {
     return;
   }
   EXPECT_TRUE(notMatches("void f();", functionProtoType()));
@@ -2745,8 +2745,11 @@ TEST(MatchFinderAPI, MatchesDynamic) {
 
 static std::vector<TestClangConfig> allTestClangConfigs() {
   std::vector<TestClangConfig> all_configs;
-  for (TestLanguage lang : {Lang_C89, Lang_C99, Lang_CXX03, Lang_CXX11,
-                            Lang_CXX14, Lang_CXX17, Lang_CXX20, Lang_CXX23}) {
+  for (TestLanguage lang : {
+#define TESTLANGUAGE(lang, version, std_flag, version_index)                   \
+  Lang_##lang##version,
+#include "clang/Testing/TestLanguage.def"
+       }) {
     TestClangConfig config;
     config.Language = lang;
 
@@ -2770,8 +2773,11 @@ static std::vector<TestClangConfig> allTestClangConfigs() {
   return all_configs;
 }
 
-INSTANTIATE_TEST_SUITE_P(ASTMatchersTests, ASTMatchersTest,
-                         testing::ValuesIn(allTestClangConfigs()));
+INSTANTIATE_TEST_SUITE_P(
+    ASTMatchersTests, ASTMatchersTest, testing::ValuesIn(allTestClangConfigs()),
+    [](const testing::TestParamInfo<TestClangConfig> &Info) {
+      return Info.param.toShortString();
+    });
 
 } // namespace ast_matchers
 } // namespace clang
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index af99c73f1945f..ada3be287ed59 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -3070,10 +3070,13 @@ B func1() { return 42; }
     auto M = expr(unless(integerLiteral(equals(24)))).bind("intLit");
     EXPECT_TRUE(matchAndVerifyResultTrue(
         Code, traverse(TK_AsIs, M),
-        std::make_unique<VerifyIdIsBoundTo<Expr>>("intLit", 6)));
+        std::make_unique<VerifyIdIsBoundTo<Expr>>("intLit", 6),
+        {"-std=c++11"}));
+
     EXPECT_TRUE(matchAndVerifyResultTrue(
         Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
-        std::make_unique<VerifyIdIsBoundTo<Expr>>("intLit", 1)));
+        std::make_unique<VerifyIdIsBoundTo<Expr>>("intLit", 1),
+        {"-std=c++11"}));
   }
   {
     auto M =
@@ -3116,7 +3119,8 @@ B func1() { return 42; }
     auto M = expr().bind("allExprs");
     EXPECT_TRUE(matchAndVerifyResultTrue(
         Code, traverse(TK_AsIs, M),
-        std::make_unique<VerifyIdIsBoundTo<Expr>>("allExprs", 6)));
+        std::make_unique<VerifyIdIsBoundTo<Expr>>("allExprs", 6),
+        {"-std=c++11"}));
     EXPECT_TRUE(matchAndVerifyResultTrue(
         Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
         std::make_unique<VerifyIdIsBoundTo<Expr>>("allExprs", 1)));
diff --git a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
index 37e3546dc9087..4ff5e8b65a686 100644
--- a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -88,8 +88,12 @@ class BuildSyntaxTreeTest : public SyntaxTreeTest {
   }
 };
 
-INSTANTIATE_TEST_SUITE_P(SyntaxTreeTests, BuildSyntaxTreeTest,
-                        testing::ValuesIn(allTestClangConfigs()) );
+INSTANTIATE_TEST_SUITE_P(
+    SyntaxTreeTests, BuildSyntaxTreeTest,
+    testing::ValuesIn(allTestClangConfigs()),
+    [](const testing::TestParamInfo<TestClangConfig> &Info) {
+      return Info.param.toShortString();
+    });
 
 TEST_P(BuildSyntaxTreeTest, Simple) {
   EXPECT_TRUE(treeDumpEqual(
diff --git a/clang/unittests/Tooling/Syntax/MutationsTest.cpp b/clang/unittests/Tooling/Syntax/MutationsTest.cpp
index 1c3d6aac7183b..35692fd52181a 100644
--- a/clang/unittests/Tooling/Syntax/MutationsTest.cpp
+++ b/clang/unittests/Tooling/Syntax/MutationsTest.cpp
@@ -54,8 +54,11 @@ class MutationTest : public SyntaxTreeTest {
   };
 };
 
-INSTANTIATE_TEST_SUITE_P(SyntaxTreeTests, MutationTest,
-                        ::testing::ValuesIn(allTestClangConfigs()) );
+INSTANTIATE_TEST_SUITE_P(
+    SyntaxTreeTests, MutationTest, ::testing::ValuesIn(allTestClangConfigs()),
+    [](const testing::TestParamInfo<TestClangConfig> &Info) {
+      return Info.param.toShortString();
+    });
 
 TEST_P(MutationTest, RemoveStatement_InCompound) {
   CheckTransformation(RemoveStatement, "void test() { [[100+100;]] test(); }",
diff --git a/clang/unittests/Tooling/Syntax/SynthesisTe...
[truncated]

Copy link

github-actions bot commented Jun 3, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@5chmidti 5chmidti force-pushed the users/5chmidti/specify_test_language_versions_in_def_file branch from ab818f8 to 1c6f2a0 Compare June 3, 2024 16:36
@5chmidti 5chmidti force-pushed the users/5chmidti/specify_test_language_versions_in_def_file branch from 1c6f2a0 to 1383ace Compare July 12, 2024 21:59
@5chmidti
Copy link
Contributor Author

rebased on trunk

@5chmidti
Copy link
Contributor Author

ping

…sions

Adds a def file to have a single location where tested language versions are
specified. Removes the need to update multiple locations in the testing
infrastructure to add a new language version to be tested.
Test instatiation can now include all languages without needing to
specify them.
This patch also adds pretty printing for instantiated test names.
That means, that a test instantiated with C++23 will have the
name `...TestSuite/TestName/CXX23` instead ending with some number
(index of the argument for instantiation of the test), which improves a
better experience when encountering a test failure with a specific
language version. The suffix will also contain an `_win` if the target
contains `win`.
@5chmidti 5chmidti force-pushed the users/5chmidti/specify_test_language_versions_in_def_file branch from 82f048e to 4da7732 Compare August 24, 2024 10:54
@5chmidti
Copy link
Contributor Author

rebase + ping. @AaronBallman could you check if this is okay now? I could merge the AST matcher doc testing stack if that is the case

bool isCXX23OrLater() const { return isCXXOrLater(23); }

bool isCXXOrEarlier(int MaximumStdVersion) const {
const auto MaximumStdVersionIndex = 0
Copy link
Member

Choose a reason for hiding this comment

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

Just a random thought, but couldn’t we simply do this here?

return isCXX() && !isCXXOrLater(MaximumStdVersion + 1);

Copy link
Member

Choose a reason for hiding this comment

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

Ah, actually, no, this is passing in the version not the version index, so I’m not sure it would.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it could be expressed when isCXX(int) is introduced:

  bool isCXXOrEarlier(int MaximumStdVersion) const {
    return isCXX() &&
           (isCXX(MaximumStdVersion) || !isCXXOrLater(MaximumStdVersion));
  }

I've pushed a change that does just that

case Lang_OpenCL:
llvm_unreachable("Not implemented yet!");
}
return Args;
llvm_unreachable("Not implemented yet!");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
llvm_unreachable("Not implemented yet!");
llvm_unreachable("Invalid language");

The message as-is suggests that there is more that needs to be done here, which isn’t really the case at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

(That applies to all of these llvm_unreachable calls, not just here)

@@ -1224,7 +1224,7 @@ TEST_P(ASTMatchersTest, CastExpression_MatchesImplicitCasts) {
}

TEST_P(ASTMatchersTest, CastExpr_DoesNotMatchNonCasts) {
if (GetParam().Language == Lang_C89 || GetParam().Language == Lang_C99) {
if (GetParam().isC()) {
Copy link
Member

Choose a reason for hiding this comment

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

Don’t we need isCOrEarlier() here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

C99OrEarlier, but good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was that previously only Lang_C89 and Lang_C99 were even declared in the TestLanguage enum, so I enabled the test for all C languages in this case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, okay, that's a reasonable change then, thank you!

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

modulo things brought up by @Sirraide, this is looking good!

@@ -1224,7 +1224,7 @@ TEST_P(ASTMatchersTest, CastExpression_MatchesImplicitCasts) {
}

TEST_P(ASTMatchersTest, CastExpr_DoesNotMatchNonCasts) {
if (GetParam().Language == Lang_C89 || GetParam().Language == Lang_C99) {
if (GetParam().isC()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

C99OrEarlier, but good catch!

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

LGTM, unless @Sirraide has other concerns. Thank you for the improvement!

@5chmidti 5chmidti requested a review from Sirraide September 6, 2024 17:26
@5chmidti
Copy link
Contributor Author

@Sirraide because this is touching the unit test infra, I held of on merging so you could take another look once you were back.

Copy link
Member

@Sirraide Sirraide left a comment

Choose a reason for hiding this comment

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

Ah, no, I didn’t have anything else to comment on; lgtm too

@5chmidti 5chmidti merged commit 7dfdca1 into main Sep 27, 2024
8 checks passed
@5chmidti 5chmidti deleted the users/5chmidti/specify_test_language_versions_in_def_file branch September 27, 2024 11:03
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Sep 27, 2024
…sions (llvm#94243)

Adds a def file to have a single location where tested language versions
are specified. Removes the need to update multiple locations in the
testing infrastructure to add a new language version to be tested. Test
instatiation can now include all languages without needing to specify
them.
This patch also adds pretty printing for instantiated test names. That
means, that a test instantiated with C++23 will have the name
`...TestSuite/TestName/CXX23` instead ending with some number (index of
the argument for instantiation of the test), which provides a better
experience when encountering a test failure with a specific language
version. The suffix will also contain an `_win` if the target contains
`win`.

---------

Co-authored-by: Sirraide <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants