https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75637
>From 61385bf2fa5c7369812eed6d40d04599f2383ee0 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan <abhina.sreeskanthara...@ibm.com> Date: Fri, 15 Dec 2023 14:39:23 -0500 Subject: [PATCH 1/2] check if we have dlfcn.h and dladdr --- clang/tools/libclang/CIndexer.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 77da2e4fa5ead0..fafdd215bf705d 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -17,6 +17,7 @@ #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" @@ -125,21 +126,28 @@ const std::string &CIndexer::getClangResourcesPath() { #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else + bool pathFound = false; +#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; - std::string Path; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. LibClangPath += info.dli_fname; - } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { - // If we can't get the path using dladdr, try to get the main executable - // path. This may be needed when we're statically linking libclang with - // musl libc, for example. - LibClangPath += Path; - } else { - // It's rather unlikely we end up here. But it could happen, so report an - // error instead of crashing. - llvm::report_fatal_error("could not locate Clang resource path"); + pathFound = true; + } +#endif + std::string Path; + if (!pathFound) { + if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { + // If we can't get the path using dladdr, try to get the main executable + // path. This may be needed when we're statically linking libclang with + // musl libc, for example. + LibClangPath += Path; + } else { + // It's rather unlikely we end up here. But it could happen, so report an + // error instead of crashing. + llvm::report_fatal_error("could not locate Clang resource path"); + } } #endif >From 5e16c335f627768edd408cbce16c8fa16c8efc5b Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan <abhina.sreeskanthara...@ibm.com> Date: Mon, 18 Dec 2023 09:54:28 -0500 Subject: [PATCH 2/2] address nit --- clang/tools/libclang/CIndexer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index fafdd215bf705d..0623ae69fe01ed 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -126,18 +126,18 @@ const std::string &CIndexer::getClangResourcesPath() { #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else - bool pathFound = false; + bool PathFound = false; #if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. LibClangPath += info.dli_fname; - pathFound = true; + PathFound = true; } #endif std::string Path; - if (!pathFound) { + if (!PathFound) { if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { // If we can't get the path using dladdr, try to get the main executable // path. This may be needed when we're statically linking libclang with _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits