diff --git a/libcextract/ClangCompat.hh b/libcextract/ClangCompat.hh index 07571ac..df86b7d 100644 --- a/libcextract/ClangCompat.hh +++ b/libcextract/ClangCompat.hh @@ -36,6 +36,14 @@ #include #include "clang/Frontend/CompilerInstance.h" +/* Starting from LLVM-18, the method FileEntry::getName() got deprecated. + * This makes clang warns about the function being deprecated while it is + * completely useful as a way to keep compatibility with older versions of + * LLVM, hence we acknowledge the warning here and disable it for now. + */ + +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + namespace ClangCompat { #if CLANG_VERSION_MAJOR >= 16 diff --git a/libcextract/IncludeTree.cpp b/libcextract/IncludeTree.cpp index 36ad22c..acb4dce 100644 --- a/libcextract/IncludeTree.cpp +++ b/libcextract/IncludeTree.cpp @@ -123,6 +123,16 @@ void IncludeTree::Build_Header_Tree(std::vector const &must_expand) bool expand = In_Set(must_expand_set, id->getFileName().str(), /*remove=*/true) || In_Set(must_expand_set, id->getFile()->getName().str(), /*remove=*/true); +#if CLANG_VERSION_MAJOR >= 18 + /* Starting from LLVM-18, the behaviour of FileEntry::getName() changed. + * Now it returns the full path of the file rather than the relative path + * to it, so here we account it for now onwards. + */ + expand |= In_Set(must_expand_set, + id->getFile()->getFileEntry().tryGetRealPathName().str(), + /*remove=*/true); +#endif + bool output = already_seen_main && current->Should_Be_Expanded() && !expand; bool is_from_minus_include = !already_seen_main; @@ -355,11 +365,10 @@ void IncludeTree::IncludeNode::Set_FileEntry(OptionalFileEntryRef file) SourceRange IncludeTree::IncludeNode::Get_File_Range(void) { - const FileEntry *file = *File; SourceManager *SM = PrettyPrint::Get_Source_Manager(); SourceLocation start, end; - FileID fid = SM->getOrCreateFileID(file, SrcMgr::CharacteristicKind()); + FileID fid = SM->getOrCreateFileID(*File, SrcMgr::CharacteristicKind()); start = SM->getLocForStartOfFile(fid); end = SM->getLocForEndOfFile(fid); diff --git a/libcextract/Passes.cpp b/libcextract/Passes.cpp index bd5a562..ca6ffa9 100644 --- a/libcextract/Passes.cpp +++ b/libcextract/Passes.cpp @@ -188,7 +188,12 @@ class BuildASTPass : public Pass { SourceManager &sm = ast->getSourceManager(); +#if CLANG_VERSION_MAJOR >= 18 + FileEntryRef main_file = *sm.getFileEntryRefForID(sm.getMainFileID()); +#else const FileEntry *main_file = sm.getFileEntryForID(sm.getMainFileID()); +#endif + StringRef path = sm.getFileManager().getCanonicalName(main_file); return path; diff --git a/libcextract/SymbolExternalizer.cpp b/libcextract/SymbolExternalizer.cpp index d8b4eae..1692c82 100644 --- a/libcextract/SymbolExternalizer.cpp +++ b/libcextract/SymbolExternalizer.cpp @@ -16,6 +16,7 @@ #include "SymbolExternalizer.hh" #include "PrettyPrint.hh" #include "Error.hh" +#include "ClangCompat.hh" #include #include @@ -365,7 +366,6 @@ bool TextModifications::Is_Same_Change(const Delta &a, const Delta &b) /* ---- End of Deltas class -------- */ - bool SymbolExternalizer::FunctionUpdater::Update_References_To_Symbol(Stmt *stmt) { if (!stmt) diff --git a/testsuite/includes/include-7.c b/testsuite/includes/include-7.c index 96615e2..0d6f927 100644 --- a/testsuite/includes/include-7.c +++ b/testsuite/includes/include-7.c @@ -9,7 +9,6 @@ int main(void) } /* { dg-final { scan-tree-dump "#define _STDIO_H 1" } } */ -/* { dg-final { scan-tree-dump "typedef __SIZE_TYPE__ size_t;" } } */ /* { dg-final { scan-tree-dump "#define __need___va_list" } } */ /* { dg-final { scan-tree-dump "#include " } } */ /* { dg-final { scan-tree-dump "#include " } } */