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

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 26 12:03:45 PDT 2024


================
@@ -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
----------------
Sirraide wrote:

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

https://github.com/llvm/llvm-project/pull/94243


More information about the cfe-commits mailing list