clang_wrap.h: optionally pass VFS to createDiagnostics
authorSven Verdoolaege <sven.verdoolaege@gmail.com>
Sun, 26 Oct 2025 14:46:15 +0000 (26 15:46 +0100)
committerSven Verdoolaege <sven.verdoolaege@gmail.com>
Sat, 22 Nov 2025 14:26:18 +0000 (22 15:26 +0100)
Since llvmorg-20-init-12950-gbdd10d9d249b ([NFC] Explicitly pass a VFS
when creating DiagnosticsEngine (#115852), Thu Nov 21 12:11:41 2024 +0100),
createDiagnostics takes a VFS argument.
Note that the llvm::vfs namespace does not exist in early versions
of clang, so it is difficult to detect the need for a VFS argument
at compile time.

Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
interface/include/isl-interface/clang_wrap.h
interface/include/isl-interface/config.h.in
m4/ax_detect_clang.m4

index 8cb025f..b0a6cc9 100644 (file)
@@ -152,11 +152,22 @@ static TargetInfo *create_target_info(CompilerInstance *Clang,
 
 #endif
 
+#ifdef CREATEDIAGNOSTICS_TAKES_VFS
+
+static void create_diagnostics(CompilerInstance *Clang)
+{
+       Clang->createDiagnostics(*llvm::vfs::getRealFileSystem());
+}
+
+#else
+
 static void create_diagnostics(CompilerInstance *Clang)
 {
        Clang->createDiagnostics();
 }
 
+#endif
+
 static void create_preprocessor(CompilerInstance *Clang)
 {
        Clang->createPreprocessor(TU_Complete);
index 2a40b44..045dc56 100644 (file)
@@ -2,6 +2,7 @@
 #define ISL_CLANG_WRAP_CONFIG_H
 
 #undef CREATE_FROM_ARGS_TAKES_ARRAYREF
+#undef CREATEDIAGNOSTICS_TAKES_VFS
 #undef CREATETARGETINFO_TAKES_SHARED_PTR
 #undef HAVE_LLVM_OPTION_ARG_H
 #undef HAVE_TARGETPARSER_HOST_H
index d3758a5..de5bb86 100644 (file)
@@ -170,6 +170,14 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 AC_CHECK_HEADER([llvm/Option/Arg.h],
        [AC_DEFINE([HAVE_LLVM_OPTION_ARG_H], [],
                   [Define if llvm/Option/Arg.h exists])])
+# llvmorg-20-init-12950-gbdd10d9d249b
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+              [[#include <clang/Frontend/CompilerInstance.h>]], [[
+       clang::CompilerInstance *Clang;
+       Clang->createDiagnostics(*llvm::vfs::getRealFileSystem());
+]])], [AC_DEFINE([CREATEDIAGNOSTICS_TAKES_VFS], [],
+       [Define if CompilerInstance::createDiagnostics takes VFS])])
+
 
 LDFLAGS="$CLANG_LDFLAGS $LDFLAGS"