Skip to content

[Clang] [NFC] Introduce a helper for emitting compatibility diagnostics #132348

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 12 commits into from
Apr 2, 2025

Conversation

Sirraide
Copy link
Member

This is a follow-up to #132129.

Currently, only Parser and SemaBase get a DiagCompat() helper; I’m planning to keep refactoring compatibility warnings and add more helpers to other classes as needed. I also refactored a single parser compat warning just to make sure everything works properly when diagnostics across multiple components (i.e. Sema and Parser in this case) are involved.

Another thing I noticed is that the DiagnosticAST.h, DiagnosticAnalysis.h, etc. headers are quite repetitive; I think we should be able to tablegen those as well; I’m planning to explore that in a separate pr after this because updating all of them every time I changed something while working on this pr has been rather tedious.

@Sirraide Sirraide added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Mar 21, 2025
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 21, 2025

@llvm/pr-subscribers-clang

Author: None (Sirraide)

Changes

This is a follow-up to #132129.

Currently, only Parser and SemaBase get a DiagCompat() helper; I’m planning to keep refactoring compatibility warnings and add more helpers to other classes as needed. I also refactored a single parser compat warning just to make sure everything works properly when diagnostics across multiple components (i.e. Sema and Parser in this case) are involved.

Another thing I noticed is that the DiagnosticAST.h, DiagnosticAnalysis.h, etc. headers are quite repetitive; I think we should be able to tablegen those as well; I’m planning to explore that in a separate pr after this because updating all of them every time I changed something while working on this pr has been rather tedious.


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

32 Files Affected:

  • (modified) clang/include/clang/Basic/CMakeLists.txt (+10)
  • (modified) clang/include/clang/Basic/Diagnostic.td (+18)
  • (modified) clang/include/clang/Basic/DiagnosticAST.h (+12)
  • (modified) clang/include/clang/Basic/DiagnosticAnalysis.h (+12)
  • (modified) clang/include/clang/Basic/DiagnosticComment.h (+12)
  • (modified) clang/include/clang/Basic/DiagnosticCrossTU.h (+12)
  • (modified) clang/include/clang/Basic/DiagnosticDriver.h (+12)
  • (modified) clang/include/clang/Basic/DiagnosticFrontend.h (+12)
  • (modified) clang/include/clang/Basic/DiagnosticIDs.h (+18)
  • (modified) clang/include/clang/Basic/DiagnosticInstallAPI.h (+12)
  • (modified) clang/include/clang/Basic/DiagnosticLex.h (+12)
  • (modified) clang/include/clang/Basic/DiagnosticParse.h (+12)
  • (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+6-6)
  • (modified) clang/include/clang/Basic/DiagnosticRefactoring.h (+12)
  • (modified) clang/include/clang/Basic/DiagnosticSema.h (+13)
  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1)
  • (modified) clang/include/clang/Basic/DiagnosticSerialization.h (+12)
  • (modified) clang/include/clang/Parse/Parser.h (+6)
  • (modified) clang/include/clang/Sema/SemaBase.h (+4)
  • (modified) clang/lib/Basic/Diagnostic.cpp (+2)
  • (modified) clang/lib/Basic/DiagnosticIDs.cpp (+46)
  • (modified) clang/lib/Parse/ParseDecl.cpp (+2-5)
  • (modified) clang/lib/Parse/Parser.cpp (+9)
  • (modified) clang/lib/Sema/SemaBase.cpp (+6)
  • (modified) clang/lib/Sema/SemaDecl.cpp (+3-8)
  • (modified) clang/lib/Sema/SemaDeclCXX.cpp (+21-54)
  • (modified) clang/lib/Sema/SemaExpr.cpp (+1-3)
  • (modified) clang/lib/Sema/SemaTemplate.cpp (+4-15)
  • (modified) clang/test/Misc/show-diag-options.c (+1-1)
  • (modified) clang/utils/TableGen/ClangDiagnosticsEmitter.cpp (+44)
  • (modified) clang/utils/TableGen/TableGen.cpp (+6)
  • (modified) clang/utils/TableGen/TableGenBackends.h (+3)
diff --git a/clang/include/clang/Basic/CMakeLists.txt b/clang/include/clang/Basic/CMakeLists.txt
index a671d5c764c22..6be6d063c20b4 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -8,6 +8,11 @@ macro(clang_diag_gen component)
     -gen-clang-diags-enums -clang-component=${component}
     SOURCE Diagnostic.td
     TARGET ClangDiagnostic${component}Enums)
+
+  clang_tablegen(Diagnostic${component}CompatIDs.inc
+    -gen-clang-diags-compat-ids -clang-component=${component}
+    SOURCE Diagnostic.td
+    TARGET ClangDiagnostic${component}CompatIDs)
 endmacro(clang_diag_gen)
 
 clang_diag_gen(Analysis)
@@ -31,6 +36,11 @@ clang_tablegen(DiagnosticIndexName.inc -gen-clang-diags-index-name
   SOURCE Diagnostic.td
   TARGET ClangDiagnosticIndexName)
 
+clang_tablegen(DiagnosticAllCompatIDs.inc
+  -gen-clang-diags-compat-ids
+  SOURCE Diagnostic.td
+  TARGET ClangDiagnosticAllCompatIDs)
+
 clang_tablegen(AttrList.inc -gen-clang-attr-list
   -I ${CMAKE_CURRENT_SOURCE_DIR}/../../
   SOURCE Attr.td
diff --git a/clang/include/clang/Basic/Diagnostic.td b/clang/include/clang/Basic/Diagnostic.td
index b31d846210a8e..65b19f3feea4f 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -155,6 +155,19 @@ class DefaultWarnNoWerror {
 }
 class DefaultRemark { Severity DefaultSeverity = SEV_Remark; }
 
+class CompatWarningId<string name, int std, string diag, string diag_pre> {
+  string Component = ?;
+  string Name = name;
+  string Diag = diag;
+  string DiagPre = diag_pre;
+  int Std = std;
+
+  // This is unused, but Tablegen will complain if it's missing because we define
+  // the compatibility ids in the same place as the other diagnostics (which means
+  // that we'll be inside a 'let CategoryName = "" in { ... }' block).
+  string CategoryName = ?;
+}
+
 // C++ compatibility warnings.
 multiclass CXXCompat<
     string message,
@@ -178,6 +191,11 @@ multiclass CXXCompat<
                                      "CXX98Compat",
                                      "CXXPre"#std_ver#"Compat"))>,
         DefaultIgnore;
+
+    def : CompatWarningId<
+        NAME, std_ver,
+        "compat_cxx"#std_ver#"_"#NAME,
+        "compat_pre_cxx"#std_ver#"_"#NAME>;
 }
 
 // These generate pairs of C++ compatibility warnings of the form:
diff --git a/clang/include/clang/Basic/DiagnosticAST.h b/clang/include/clang/Basic/DiagnosticAST.h
index 4f82114b7406b..41e2598f7cc3b 100644
--- a/clang/include/clang/Basic/DiagnosticAST.h
+++ b/clang/include/clang/Basic/DiagnosticAST.h
@@ -36,6 +36,18 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticASTCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICAST_H
diff --git a/clang/include/clang/Basic/DiagnosticAnalysis.h b/clang/include/clang/Basic/DiagnosticAnalysis.h
index 1a49461bcd173..5ead092b946c5 100644
--- a/clang/include/clang/Basic/DiagnosticAnalysis.h
+++ b/clang/include/clang/Basic/DiagnosticAnalysis.h
@@ -35,6 +35,18 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticAnalysisCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICANALYSIS_H
diff --git a/clang/include/clang/Basic/DiagnosticComment.h b/clang/include/clang/Basic/DiagnosticComment.h
index 53143ef132e4b..08e66e8051834 100644
--- a/clang/include/clang/Basic/DiagnosticComment.h
+++ b/clang/include/clang/Basic/DiagnosticComment.h
@@ -36,6 +36,18 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticCommentCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICCOMMENT_H
diff --git a/clang/include/clang/Basic/DiagnosticCrossTU.h b/clang/include/clang/Basic/DiagnosticCrossTU.h
index 428da95011027..761716d781446 100644
--- a/clang/include/clang/Basic/DiagnosticCrossTU.h
+++ b/clang/include/clang/Basic/DiagnosticCrossTU.h
@@ -36,6 +36,18 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticCrossTUCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICCROSSTU_H
diff --git a/clang/include/clang/Basic/DiagnosticDriver.h b/clang/include/clang/Basic/DiagnosticDriver.h
index c472afa3f6e96..864a23a49e4cd 100644
--- a/clang/include/clang/Basic/DiagnosticDriver.h
+++ b/clang/include/clang/Basic/DiagnosticDriver.h
@@ -36,6 +36,18 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticDriverCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICDRIVER_H
diff --git a/clang/include/clang/Basic/DiagnosticFrontend.h b/clang/include/clang/Basic/DiagnosticFrontend.h
index 766cac3d655b3..3506f05daae54 100644
--- a/clang/include/clang/Basic/DiagnosticFrontend.h
+++ b/clang/include/clang/Basic/DiagnosticFrontend.h
@@ -36,6 +36,18 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticFrontendCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICFRONTEND_H
diff --git a/clang/include/clang/Basic/DiagnosticIDs.h b/clang/include/clang/Basic/DiagnosticIDs.h
index 017ef7065610f..c20bf4fcfccb1 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -25,6 +25,7 @@
 namespace clang {
   class DiagnosticsEngine;
   class DiagnosticBuilder;
+  class LangOptions;
   class SourceLocation;
 
   // Import the diagnostic enums themselves.
@@ -104,6 +105,18 @@ namespace clang {
     };
   }
 
+  namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                \
+    }                                                                          \
+    ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticCommonCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+  } // end namespace diag_compat
+
 class DiagnosticMapping {
   LLVM_PREFERRED_TYPE(diag::Severity)
   unsigned Severity : 3;
@@ -464,6 +477,11 @@ class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
   /// given group name.
   static StringRef getNearestOption(diag::Flavor Flavor, StringRef Group);
 
+  /// Get the appropriate diagnostic Id to use for issuing a compatibility
+  /// diagnostic. For use by the various DiagCompat() helpers.
+  static unsigned getCompatDiagId(const LangOptions &LangOpts,
+                                  unsigned CompatDiagId);
+
 private:
   /// Classify the specified diagnostic ID into a Level, consumable by
   /// the DiagnosticClient.
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPI.h b/clang/include/clang/Basic/DiagnosticInstallAPI.h
index cbdb00362624b..4619bfeea05a2 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPI.h
+++ b/clang/include/clang/Basic/DiagnosticInstallAPI.h
@@ -35,5 +35,17 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticInstallAPICompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // namespace clang
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICINSTALLAPI_H
diff --git a/clang/include/clang/Basic/DiagnosticLex.h b/clang/include/clang/Basic/DiagnosticLex.h
index d14bf97e8642e..6fa90f785bbf8 100644
--- a/clang/include/clang/Basic/DiagnosticLex.h
+++ b/clang/include/clang/Basic/DiagnosticLex.h
@@ -35,6 +35,18 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticLexCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICLEX_H
diff --git a/clang/include/clang/Basic/DiagnosticParse.h b/clang/include/clang/Basic/DiagnosticParse.h
index 275e1a4c39b3f..e2a4368a59c4b 100644
--- a/clang/include/clang/Basic/DiagnosticParse.h
+++ b/clang/include/clang/Basic/DiagnosticParse.h
@@ -36,6 +36,18 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticParseCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICPARSE_H
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 4dc956f7ae6f7..98d598f654cca 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -11,6 +11,12 @@
 //===----------------------------------------------------------------------===//
 
 let Component = "Parse" in {
+let CategoryName = "Parse Issue" in {
+// C++11 compatibility with C++98.
+defm enum_fixed_underlying_type : CXX11Compat<
+  "enumeration types with a fixed underlying type are",
+  /*ext_warn=*/false>;
+}
 
 def err_asm_qualifier_ignored : Error<
   "expected 'volatile', 'inline', 'goto', or '('">, CatInlineAsm;
@@ -107,9 +113,6 @@ def err_enumerator_list_missing_comma : Error<
   "missing ',' between enumerators">;
 def err_enumerator_unnamed_no_def : Error<
   "unnamed enumeration must be a definition">;
-def ext_cxx11_enum_fixed_underlying_type : Extension<
-  "enumeration types with a fixed underlying type are a C++11 extension">,
-  InGroup<CXX11>;
 def ext_ms_c_enum_fixed_underlying_type : Extension<
   "enumeration types with a fixed underlying type are a Microsoft extension">,
   InGroup<MicrosoftFixedEnum>;
@@ -119,9 +122,6 @@ def ext_c23_enum_fixed_underlying_type : Extension<
 def warn_c17_compat_enum_fixed_underlying_type : Warning<
   "enumeration types with a fixed underlying type are incompatible with C standards before C23">,
   DefaultIgnore, InGroup<CPre23Compat>;
-def warn_cxx98_compat_enum_fixed_underlying_type : Warning<
-  "enumeration types with a fixed underlying type are incompatible with C++98">,
-  InGroup<CXX98Compat>, DefaultIgnore;
 def ext_enum_base_in_type_specifier : ExtWarn<
   "non-defining declaration of enumeration with a fixed underlying type is "
   "only permitted as a standalone declaration"
diff --git a/clang/include/clang/Basic/DiagnosticRefactoring.h b/clang/include/clang/Basic/DiagnosticRefactoring.h
index 59d4bc912733a..b3f3a10925f09 100644
--- a/clang/include/clang/Basic/DiagnosticRefactoring.h
+++ b/clang/include/clang/Basic/DiagnosticRefactoring.h
@@ -36,6 +36,18 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticRefactoringCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICREFACTORING_H
diff --git a/clang/include/clang/Basic/DiagnosticSema.h b/clang/include/clang/Basic/DiagnosticSema.h
index 84986c7bccf71..943b2f64f427e 100644
--- a/clang/include/clang/Basic/DiagnosticSema.h
+++ b/clang/include/clang/Basic/DiagnosticSema.h
@@ -35,7 +35,20 @@ enum {
 #undef DIAG_ENUM_END
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
+
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticSemaCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICSEMA_H
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eed06657536f4..18a013b633816 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -61,7 +61,7 @@ defm decomp_decl_cond : CXX26Compat<"structured binding declaration in a conditi
 
 // Compatibility warnings duplicated across multiple language versions.
 foreach std = [14, 20, 23] in {
-  defm constexpr_body_invalid_stmt : CXXCompat<
+  defm cxx#std#_constexpr_body_invalid_stmt : CXXCompat<
     "use of this statement in a constexpr %select{function|constructor}0 is", std>;
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSerialization.h b/clang/include/clang/Basic/DiagnosticSerialization.h
index 6fb836dca1b04..c8fb034e9bd4a 100644
--- a/clang/include/clang/Basic/DiagnosticSerialization.h
+++ b/clang/include/clang/Basic/DiagnosticSerialization.h
@@ -36,6 +36,18 @@ enum {
 #undef DIAG_ENUM_ITEM
 #undef DIAG_ENUM
 } // end namespace diag
+
+namespace diag_compat {
+#define DIAG_COMPAT_IDS_BEGIN() enum {
+#define DIAG_COMPAT_IDS_END()                                                  \
+  }                                                                            \
+  ;
+#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
+#include "clang/Basic/DiagnosticSerializationCompatIDs.inc"
+#undef DIAG_COMPAT_ID
+#undef DIAG_COMPAT_IDS_BEGIN
+#undef DIAG_COMPAT_IDS_END
+} // end namespace diag_compat
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICSERIALIZATION_H
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index fbe2865b1b7c1..928bc585cd811 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1263,6 +1263,12 @@ class Parser : public CodeCompletionHandler {
     return Diag(Tok, DiagID);
   }
 
+  DiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId);
+  DiagnosticBuilder DiagCompat(const Token &Tok, unsigned CompatDiagId);
+  DiagnosticBuilder DiagCompat(unsigned CompatDiagId) {
+    return DiagCompat(Tok, CompatDiagId);
+  }
+
 private:
   void SuggestParentheses(SourceLocation Loc, unsigned DK,
                           SourceRange ParenRange);
diff --git a/clang/include/clang/Sema/SemaBase.h b/clang/include/clang/Sema/SemaBase.h
index 463cae83c7e81..550f530af72f5 100644
--- a/clang/include/clang/Sema/SemaBase.h
+++ b/clang/include/clang/Sema/SemaBase.h
@@ -219,6 +219,10 @@ class SemaBase {
   SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD,
                              bool DeferHint = false);
 
+  /// Emit a compatibility diagnostic.
+  SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId,
+                                   bool DeferHint = false);
+
   /// Build a partial diagnostic.
   PartialDiagnostic PDiag(unsigned DiagID = 0);
 };
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 9e2f134135647..6842e0ef3acb6 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/AllDiagnostics.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Basic/DiagnosticError.h"
@@ -39,6 +40,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <cassert>
+#include <clang/Basic/LangOptions.h>
 #include <cstddef>
 #include <cstdint>
 #include <cstring>
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index ca5b8d2da769e..0ab3ac884a161 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -13,6 +13,7 @@
 #include "clang/Basic/DiagnosticIDs.h"
 #include "clang/Basic/AllDiagnostics.h"
 #include "clang/Basic/DiagnosticCategories.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -769,6 +770,51 @@ StringRef DiagnosticIDs::getNearestOption(diag::Flavor Flavor,
   return Best;
 }
 
+unsigned DiagnosticIDs::getCompatDiagId(const LangOptions &LangOpts,
+                                        unsigned CompatDiagId) {
+  struct CompatDiag {
+    unsigned StdVer;
+    unsigned DiagId;
+    unsigned PreDiagId;
+  };
+
+  // We encode the standard version such that C++98 < C++11 < C++14 etc. The
+  // actual numbers don't really matter for this, but the definitions of the
+  // compat diags in the Tablegen file use the standard version number (i.e.
+  // 98, 11, 14, etc.), so we base the encoding here on that.
+#define DIAG_COMPAT_IDS_BEGIN()
+#define DIAG_COMPAT_IDS_END()
+#define DIAG_COMPAT_ID(Value, Name, Std, Diag, DiagPre)                        \
+  {Std == 98 ? 1998 : 2000 + Std, diag::Diag, diag::DiagPre},
+  static constexpr CompatDiag Diags[]{
+#include "clang/Basic/DiagnosticAllComp...
[truncated]

#define DIAG_COMPAT_IDS_BEGIN()
#define DIAG_COMPAT_IDS_END()
#define DIAG_COMPAT_ID(Value, Name, Std, Diag, DiagPre) \
{Std == 98 ? 1998 : 2000 + Std, diag::Diag, diag::DiagPre},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this function is only handling C++ compat instead of C compat as well... should we name this getCXXCompatDiagId? OR BETTER: Can we just expand this whole thing to work for C as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we just expand this whole thing to work for C as well?

Yes, the plan is to expand this so it can also be used for C compatibility warnings; I’m not 100% sure how that is going to work just yet though.

/// ClangDiagsCompatIDsEmitter - Emit a set of 'compatibility diagnostic ids'
/// that map to a set of 2 regular diagnostic ids each and which are used to
/// simplify emitting compatibility warnings.
void clang::EmitClangDiagsCompatIDs(const llvm::RecordKeeper &Records,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since I'm awful at reading code that generates other code... could you copy/paste the generated stuff here in github?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, e.g. for DiagnosticSemaCompatIDs.inc, this generates:

DIAG_COMPAT_IDS_BEGIN()
DIAG_COMPAT_ID(1,nonclass_type_friend,11,compat_cxx11_nonclass_type_friend,compat_pre_cxx11_nonclass_type_friend)
DIAG_COMPAT_ID(2,static_data_member_in_union,11,compat_cxx11_static_data_member_in_union,compat_pre_cxx11_static_data_member_in_union)
DIAG_COMPAT_ID(3,templ_default_in_function_templ,11,compat_cxx11_templ_default_in_function_templ,compat_pre_cxx11_templ_default_in_function_templ)
DIAG_COMPAT_ID(4,template_arg_extra_parens,11,compat_cxx11_template_arg_extra_parens,compat_pre_cxx11_template_arg_extra_parens)
DIAG_COMPAT_ID(5,typename_outside_of_template,11,compat_cxx11_typename_outside_of_template,compat_pre_cxx11_typename_outside_of_template)
DIAG_COMPAT_ID(6,constexpr_type_definition,14,compat_cxx14_constexpr_type_definition,compat_pre_cxx14_constexpr_type_definition)
DIAG_COMPAT_ID(7,constexpr_local_var,14,compat_cxx14_constexpr_local_var,compat_pre_cxx14_constexpr_local_var)
DIAG_COMPAT_ID(8,constexpr_body_multiple_return,14,compat_cxx14_constexpr_body_multiple_return,compat_pre_cxx14_constexpr_body_multiple_return)
DIAG_COMPAT_ID(9,variable_template,14,compat_cxx14_variable_template,compat_pre_cxx14_variable_template)
DIAG_COMPAT_ID(10,decomp_decl,17,compat_cxx17_decomp_decl,compat_pre_cxx17_decomp_decl)
DIAG_COMPAT_ID(11,inline_variable,17,compat_cxx17_inline_variable,compat_pre_cxx17_inline_variable)
DIAG_COMPAT_ID(12,decomp_decl_spec,20,compat_cxx20_decomp_decl_spec,compat_pre_cxx20_decomp_decl_spec)
DIAG_COMPAT_ID(13,constexpr_local_var_no_init,20,compat_cxx20_constexpr_local_var_no_init,compat_pre_cxx20_constexpr_local_var_no_init)
DIAG_COMPAT_ID(14,constexpr_function_try_block,20,compat_cxx20_constexpr_function_try_block,compat_pre_cxx20_constexpr_function_try_block)
DIAG_COMPAT_ID(15,constexpr_union_ctor_no_init,20,compat_cxx20_constexpr_union_ctor_no_init,compat_pre_cxx20_constexpr_union_ctor_no_init)
DIAG_COMPAT_ID(16,constexpr_ctor_missing_init,20,compat_cxx20_constexpr_ctor_missing_init,compat_pre_cxx20_constexpr_ctor_missing_init)
DIAG_COMPAT_ID(17,adl_only_template_id,20,compat_cxx20_adl_only_template_id,compat_pre_cxx20_adl_only_template_id)
DIAG_COMPAT_ID(18,constexpr_static_var,23,compat_cxx23_constexpr_static_var,compat_pre_cxx23_constexpr_static_var)
DIAG_COMPAT_ID(19,decomp_decl_cond,26,compat_cxx26_decomp_decl_cond,compat_pre_cxx26_decomp_decl_cond)
DIAG_COMPAT_ID(20,cxx14_constexpr_body_invalid_stmt,14,compat_cxx14_cxx14_constexpr_body_invalid_stmt,compat_pre_cxx14_cxx14_constexpr_body_invalid_stmt)
DIAG_COMPAT_ID(21,cxx20_constexpr_body_invalid_stmt,20,compat_cxx20_cxx20_constexpr_body_invalid_stmt,compat_pre_cxx20_cxx20_constexpr_body_invalid_stmt)
DIAG_COMPAT_ID(22,cxx23_constexpr_body_invalid_stmt,23,compat_cxx23_cxx23_constexpr_body_invalid_stmt,compat_pre_cxx23_cxx23_constexpr_body_invalid_stmt)
DIAG_COMPAT_IDS_END()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we anticipating doing this multiple times? Why the BEGIN and END? Is the idea that we'd have a different list for parse vs sema? I'd prefer we get 1 list, then we don't need BEGIN and END, but I haven't thought through this enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

The begin/end is so we don’t end up with this:

enum {
#include "foo.inc" // Defines no enumerators because there are no compat diags for this component
};

i.e. with

enum {
};

which is just an empty enum which is something that some compilers (including Clang) warn about, so the begin/end allows us to do #define DIAG_COMPAT_IDS_BEGIN() enum {, which gets around this because if there are no compat diags at all, this just generates an empty file.

Is the idea that we'd have a different list for parse vs sema?

Yeah, it’s mainly so e.g. parser compatibility diagnostics aren’t visible in sema and vice versa, just like how non-compatibility diagnostics work.

@@ -178,6 +191,11 @@ multiclass CXXCompat<
"CXX98Compat",
"CXXPre"#std_ver#"Compat"))>,
DefaultIgnore;

def : CompatWarningId<
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have another layer of abstraction here for C vs C++ vs whatever other language compat warnings?

Copy link
Member Author

Choose a reason for hiding this comment

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

I’m still figuring out how to integrate the C compatibility warnings; for now this is just for C++, but I think we can definitely extend this later

@Sirraide
Copy link
Member Author

ping

@Sirraide
Copy link
Member Author

Also, because there are some comments about extending this to C: I’d prefer to figure that out in a follow-up pr otherwise this one is probably going to get pretty big

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

@erichkeane
Copy link
Collaborator

I think I'd like the name-change suggested above at minimum if we're not doing C for now. Else LGTM.

@Sirraide Sirraide merged commit 9d06e08 into llvm:main Apr 2, 2025
11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building clang at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/27600

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-ubuntu-fast running on sie-linux-worker while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/21791

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-gcc-ubuntu running on sie-linux-worker3 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/15525

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder clang-cmake-x86_64-avx512-linux running on avx512-intel64 while building clang at step 7 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/133/builds/13837

Here is the relevant piece of the build log for the reference
Step 7 (ninja check 1) failure: stage 1 checked (failure)
FAIL: test_diagnostic_category


@Sirraide
Copy link
Member Author

Sirraide commented Apr 2, 2025

Hmm, not sure what is going on here; I’ll revert this for now and investigate.

Sirraide added a commit that referenced this pull request Apr 2, 2025
…iagnostics" (#134036)

Reverts #132348

Some tests are failing and I still need to figure out what is going on
here.
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder ppc64le-lld-multistage-test running on ppc64le-lld-multistage-test while building clang at step 7 "test-build-stage1-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/168/builds/10420

Here is the relevant piece of the build log for the reference
Step 7 (test-build-stage1-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_category

Step 13 (test-build-stage2-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder clang-ppc64le-linux-test-suite running on ppc64le-clang-test-suite while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/95/builds/11506

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_category


@Sirraide
Copy link
Member Author

Sirraide commented Apr 2, 2025

Ah, I think I’ve found what the problem is: it would seem that moving the diagnostics around in the file caused whatever the ‘diagnostic category number’ is supposed to be of some of these diagnostics to change, and there were tests that check for that that still need to be updated. I’ll update the test and then try to reland this.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder clang-ppc64le-linux-multistage running on ppc64le-clang-multistage-test while building clang at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/76/builds/8389

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
FAIL: test_diagnostic_category

Step 11 (ninja check 2) failure: stage 2 checked (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-key-instructions running on sie-linux-worker5 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/208/builds/14

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_string_format


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder arc-builder running on arc-worker while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/3/builds/13957

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder clang-debian-cpp20 running on clang-debian-cpp20 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/108/builds/11143

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_string_format


llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Apr 2, 2025
…atibility diagnostics" (#134036)

Reverts llvm/llvm-project#132348

Some tests are failing and I still need to figure out what is going on
here.
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder clang-ppc64le-rhel running on ppc64le-clang-rhel-test while building clang at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/145/builds/6188

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder clang-m68k-linux-cross running on suse-gary-m68k-cross while building clang at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/8021

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-darwin running on doug-worker-3 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/23/builds/8971

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder clang-aarch64-sve2-vla-2stage running on linaro-g4-02 while building clang at step 12 "ninja check 2".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/199/builds/2528

Here is the relevant piece of the build log for the reference
Step 12 (ninja check 2) failure: stage 2 checked (failure)
...
PASS: Flang :: Driver/macro-def-undef.F90 (24755 of 96530)
PASS: Flang :: Driver/override-triple.ll (24756 of 96530)
PASS: Flang :: Driver/include-header.f90 (24757 of 96530)
PASS: Flang :: Driver/predefined-macros-compiler-version.F90 (24758 of 96530)
PASS: Flang :: Driver/phases.f90 (24759 of 96530)
PASS: Flang :: Driver/print-resource-dir.F90 (24760 of 96530)
PASS: Flang :: Driver/parse-fir-error.ll (24761 of 96530)
PASS: Flang :: Driver/parse-error.ll (24762 of 96530)
PASS: Flang :: Driver/mlir-pass-pipeline.f90 (24763 of 96530)
UNRESOLVED: Flang :: Driver/slp-vectorize.ll (24764 of 96530)
******************** TEST 'Flang :: Driver/slp-vectorize.ll' FAILED ********************
Test has no 'RUN:' line
********************
PASS: Flang :: Driver/linker-flags.f90 (24765 of 96530)
PASS: Flang :: Driver/fixed-line-length.f90 (24766 of 96530)
PASS: Flang :: Driver/missing-arg.f90 (24767 of 96530)
PASS: Flang :: Driver/print-pipeline-passes.f90 (24768 of 96530)
PASS: Flang :: Driver/print-target-triple.f90 (24769 of 96530)
PASS: Flang :: Driver/std2018-wrong.f90 (24770 of 96530)
PASS: Flang :: Driver/supported-suffices/f03-suffix.f03 (24771 of 96530)
PASS: Flang :: Driver/pthread.f90 (24772 of 96530)
PASS: Flang :: Driver/parse-ir-error.f95 (24773 of 96530)
PASS: Flang :: Driver/pass-plugin-not-found.f90 (24774 of 96530)
PASS: Flang :: Driver/scanning-error.f95 (24775 of 96530)
PASS: Flang :: Driver/pp-fixed-form.f90 (24776 of 96530)
PASS: Flang :: Driver/mlink-builtin-bc.f90 (24777 of 96530)
PASS: Flang :: Driver/fsave-optimization-record.f90 (24778 of 96530)
PASS: Flang :: Driver/supported-suffices/f08-suffix.f08 (24779 of 96530)
PASS: Flang :: Driver/tco-code-gen-llvm.fir (24780 of 96530)
PASS: Flang :: Driver/lto-bc.f90 (24781 of 96530)
PASS: Flang :: Driver/target.f90 (24782 of 96530)
PASS: Flang :: Driver/target-gpu-features.f90 (24783 of 96530)
PASS: Flang :: Driver/multiple-input-files.f90 (24784 of 96530)
PASS: Flang :: Driver/mllvm.f90 (24785 of 96530)
PASS: Flang :: Driver/q-unused-arguments.f90 (24786 of 96530)
PASS: Flang :: Driver/lto-flags.f90 (24787 of 96530)
PASS: Flang :: Driver/unsupported-vscale-max-min.f90 (24788 of 96530)
PASS: Clangd Unit Tests :: ./ClangdTests/73/81 (24789 of 96530)
PASS: Flang :: Driver/unparse-with-modules.f90 (24790 of 96530)
PASS: Flang :: Driver/no-duplicate-main.f90 (24791 of 96530)
PASS: Flang :: Driver/falias-analysis.f90 (24792 of 96530)
PASS: Flang :: Driver/target-machine-error.f90 (24793 of 96530)
PASS: Flang :: Driver/std2018.f90 (24794 of 96530)
PASS: Flang :: Driver/save-temps.f90 (24795 of 96530)
PASS: Flang :: Driver/unparse-use-analyzed.f95 (24796 of 96530)
PASS: Flang :: Driver/input-from-stdin/input-from-stdin.f90 (24797 of 96530)
PASS: Flang :: Driver/prescanner-diag.f90 (24798 of 96530)
PASS: Flang :: Driver/optimization-remark-invalid.f90 (24799 of 96530)
PASS: Flang :: Driver/save-temps-use-module.f90 (24800 of 96530)

Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request Apr 2, 2025
…cs (llvm#132348)

This is a follow-up to llvm#132129.

Currently, only `Parser` and `SemaBase` get a `DiagCompat()` helper; I’m
planning to keep refactoring compatibility warnings and add more helpers
to other classes as needed. I also refactored a single parser compat
warning just to make sure everything works properly when diagnostics
across multiple components (i.e. Sema and Parser in this case) are
involved.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request Apr 2, 2025
…iagnostics" (llvm#134036)

Reverts llvm#132348

Some tests are failing and I still need to figure out what is going on
here.
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder clang-armv8-quick running on linaro-clang-armv8-quick while building clang at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/154/builds/14281

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-gcc-ubuntu-no-asserts running on doug-worker-6 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/202/builds/433

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
FAIL: test_diagnostic_category


Sirraide added a commit that referenced this pull request Apr 2, 2025
…diagnostics (#132348)" (#134043)

This reapplies #132348 with a fix to the python bindings tests, reverting
076397f.
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 2, 2025

LLVM Buildbot has detected a new failure on builder clang-armv7-global-isel running on linaro-clang-armv7-global-isel while building clang at step 7 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/39/builds/5424

Here is the relevant piece of the build log for the reference
Step 7 (ninja check 1) failure: stage 1 checked (failure)
FAIL: test_diagnostic_category


@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 3, 2025

LLVM Buildbot has detected a new failure on builder clang-with-thin-lto-ubuntu running on as-worker-92 while building clang at step 7 "test-stage1-compiler".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/127/builds/2910

Here is the relevant piece of the build log for the reference
Step 7 (test-stage1-compiler) failure: build (failure)
0.069 [1/2/1] Preparing lit tests
0.639 [1/1/2] cd /home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/bindings/python && /usr/bin/cmake -E env CLANG_NO_DEFAULT_CONFIG=1 CLANG_LIBRARY_PATH=/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/build/stage1/lib /usr/bin/python3.10 -m unittest discover
FAILED: tools/clang/bindings/python/tests/CMakeFiles/check-clang-python /home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/build/stage1/tools/clang/bindings/python/tests/CMakeFiles/check-clang-python 
cd /home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/bindings/python && /usr/bin/cmake -E env CLANG_NO_DEFAULT_CONFIG=1 CLANG_LIBRARY_PATH=/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/build/stage1/lib /usr/bin/python3.10 -m unittest discover
........................................................................F.....F..............................................................................
======================================================================
FAIL: test_diagnostic_category (tests.cindex.test_diagnostics.TestDiagnostics)
Ensure that category properties work.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/bindings/python/tests/cindex/test_diagnostics.py", line 82, in test_diagnostic_category
    self.assertEqual(d.category_number, 2)
AssertionError: 3 != 2

======================================================================
FAIL: test_diagnostic_string_format (tests.cindex.test_diagnostics.TestDiagnostics)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/bindings/python/tests/cindex/test_diagnostics.py", line 124, in test_diagnostic_string_format
    self.assertEqual(
AssertionError: "t.c:1:26: error: expected ';' after struct [2, Parse Issue]" != "t.c:1:26: error: expected ';' after struct [3, Parse Issue]"
- t.c:1:26: error: expected ';' after struct [2, Parse Issue]
?                                             ^
+ t.c:1:26: error: expected ';' after struct [3, Parse Issue]
?                                             ^


----------------------------------------------------------------------
Ran 157 tests in 0.523s

FAILED (failures=2)
ninja: build stopped: subcommand failed.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 3, 2025

LLVM Buildbot has detected a new failure on builder clang-with-lto-ubuntu running on as-worker-91 while building clang at step 7 "test-stage1-compiler".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/49/builds/1238

Here is the relevant piece of the build log for the reference
Step 7 (test-stage1-compiler) failure: build (failure)
0.067 [1/2/1] Preparing lit tests
0.632 [1/1/2] cd /home/buildbot/as-worker-91/clang-with-lto-ubuntu/llvm-project/clang/bindings/python && /usr/bin/cmake -E env CLANG_NO_DEFAULT_CONFIG=1 CLANG_LIBRARY_PATH=/home/buildbot/as-worker-91/clang-with-lto-ubuntu/build/stage1/lib /usr/bin/python3.10 -m unittest discover
FAILED: tools/clang/bindings/python/tests/CMakeFiles/check-clang-python /home/buildbot/as-worker-91/clang-with-lto-ubuntu/build/stage1/tools/clang/bindings/python/tests/CMakeFiles/check-clang-python 
cd /home/buildbot/as-worker-91/clang-with-lto-ubuntu/llvm-project/clang/bindings/python && /usr/bin/cmake -E env CLANG_NO_DEFAULT_CONFIG=1 CLANG_LIBRARY_PATH=/home/buildbot/as-worker-91/clang-with-lto-ubuntu/build/stage1/lib /usr/bin/python3.10 -m unittest discover
........................................................................F.....F..............................................................................
======================================================================
FAIL: test_diagnostic_category (tests.cindex.test_diagnostics.TestDiagnostics)
Ensure that category properties work.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/as-worker-91/clang-with-lto-ubuntu/llvm-project/clang/bindings/python/tests/cindex/test_diagnostics.py", line 82, in test_diagnostic_category
    self.assertEqual(d.category_number, 2)
AssertionError: 3 != 2

======================================================================
FAIL: test_diagnostic_string_format (tests.cindex.test_diagnostics.TestDiagnostics)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/as-worker-91/clang-with-lto-ubuntu/llvm-project/clang/bindings/python/tests/cindex/test_diagnostics.py", line 124, in test_diagnostic_string_format
    self.assertEqual(
AssertionError: "t.c:1:26: error: expected ';' after struct [2, Parse Issue]" != "t.c:1:26: error: expected ';' after struct [3, Parse Issue]"
- t.c:1:26: error: expected ';' after struct [2, Parse Issue]
?                                             ^
+ t.c:1:26: error: expected ';' after struct [3, Parse Issue]
?                                             ^


----------------------------------------------------------------------
Ran 157 tests in 0.516s

FAILED (failures=2)
ninja: build stopped: subcommand failed.

Sirraide added a commit that referenced this pull request Apr 8, 2025
The component diagnostic headers (i.e. `DiagnosticAST.h` and friends)
all follow the same format, and there’s enough of them (and in them) to
where updating all of them has become rather tedious (at least it was
for me while working on #132348), so this patch instead generates all of
them (or rather their contents) via Tablegen.

Also, it seems that `%enum_select` currently wouldn’t work in
`DiagnosticCommonKinds.td` because the infrastructure for that was
missing from `DiagnosticIDs.h`; this patch should fix that as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants