Description: Fix build with LLVM 22 (createDiagnostics API change)
 LLVM 22 removed the CompilerInstance::createDiagnostics(FileSystem &,
 DiagnosticConsumer *) overload, which made the clang frontend fail to build
 with "no matching function for call to createDiagnostics". Create the
 diagnostics engine with the real file system and the invocation's diagnostic
 options (as the removed overload did) and install it on the compiler instance
 via setDiagnostics().
 .
 The new code is guarded by LLVM_VERSION_MAJOR >= 22, so builds against
 LLVM <= 21 are left untouched.
Author: tangxiaofeng <tangxiaofeng@kylinos.cn>
Forwarded: not-needed
Last-Update: 2026-10-19

--- bpfcc-0.35.0+ds.orig/src/cc/frontends/clang/loader.cc
+++ bpfcc-0.35.0+ds/src/cc/frontends/clang/loader.cc
@@ -464,7 +464,15 @@ int ClangLoader::do_compile(
   }
   invocation0.getFrontendOpts().DisableFree = false;
 
-#if LLVM_VERSION_MAJOR >= 20
+#if LLVM_VERSION_MAJOR >= 22
+  // LLVM 22 removed the createDiagnostics(FileSystem &, DiagnosticConsumer *)
+  // overload. Build the diagnostics engine with the real file system and the
+  // invocation's diagnostic options (as the removed overload did) and install
+  // it on the compiler instance.
+  compiler0.setDiagnostics(CompilerInstance::createDiagnostics(
+      *llvm::vfs::getRealFileSystem(), compiler0.getDiagnosticOpts(),
+      new IgnoringDiagConsumer(), true, &compiler0.getCodeGenOpts()));
+#elif LLVM_VERSION_MAJOR >= 20
   compiler0.createDiagnostics(*llvm::vfs::getRealFileSystem(), new IgnoringDiagConsumer());
 #else
   compiler0.createDiagnostics(new IgnoringDiagConsumer());
@@ -487,7 +495,12 @@ int ClangLoader::do_compile(
   add_main_input(invocation1, main_path, &*out_buf);
   invocation1.getFrontendOpts().DisableFree = false;
 
-#if LLVM_VERSION_MAJOR >= 20
+#if LLVM_VERSION_MAJOR >= 22
+  // Same as above, with a default diagnostic consumer.
+  compiler1.setDiagnostics(CompilerInstance::createDiagnostics(
+      *llvm::vfs::getRealFileSystem(), compiler1.getDiagnosticOpts(), nullptr,
+      true, &compiler1.getCodeGenOpts()));
+#elif LLVM_VERSION_MAJOR >= 20
   compiler1.createDiagnostics(*llvm::vfs::getRealFileSystem());
 #else
   compiler1.createDiagnostics();
@@ -517,7 +530,12 @@ int ClangLoader::do_compile(
   invocation2.getCodeGenOpts().setInlining(CodeGenOptions::NormalInlining);
   // suppress warnings in the 2nd pass, but bail out on errors (our fault)
   invocation2.getDiagnosticOpts().IgnoreWarnings = true;
-#if LLVM_VERSION_MAJOR >= 20
+#if LLVM_VERSION_MAJOR >= 22
+  // Same as above, with a default diagnostic consumer.
+  compiler2.setDiagnostics(CompilerInstance::createDiagnostics(
+      *llvm::vfs::getRealFileSystem(), compiler2.getDiagnosticOpts(), nullptr,
+      true, &compiler2.getCodeGenOpts()));
+#elif LLVM_VERSION_MAJOR >= 20
   compiler2.createDiagnostics(*llvm::vfs::getRealFileSystem());
 #else
   compiler2.createDiagnostics();
