Skip to content

Commit

Permalink
Add support to llvm-19
Browse files Browse the repository at this point in the history
This commit updates the codebase so that it compiles with llvm-19.

- Replaces uses of FileEntry::getName() with FileEntryRef::getName().
- Update the __attribute__((used)) location on the tests.

Signed-off-by: Giuliano Belinassi <[email protected]>
  • Loading branch information
giulianobelinassi committed Dec 20, 2024
1 parent ec46efd commit 8344124
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
opensuse: [tumbleweed]
compiler: [clang]
build-type: [debug, release]
version: [17, 18]
version: [17, 18, 19]

container:
image: opensuse/${{ matrix.opensuse }}
Expand Down
7 changes: 4 additions & 3 deletions libcextract/IncludeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void IncludeTree::Build_Header_Map(void)

/* For Files. */
OptionalFileEntryRef file = node->Get_FileEntry();
const FileEntry *fentry = &file->getFileEntry();
const FileEntryRef fentry = *file;
if (Map.find(fentry) != Map.end()) {
/* FIXME: Find a way to correcly map the FileEntry to the node instead of
discarding future appearances. */
Expand Down Expand Up @@ -526,8 +526,9 @@ bool IncludeNode::Is_Reachable_From_Main(void)
nullptr);

if (ref.has_value()) {
const FileEntry &entry = (*ref).getFileEntry();
if (Tree.IEP->Must_Expand(entry.tryGetRealPathName(), entry.getName())) {
const FileEntryRef &entry = *ref;
const FileEntry &fentry = ref->getFileEntry();
if (Tree.IEP->Must_Expand(fentry.tryGetRealPathName(), entry.getName())) {
/* Lie telling it is unreachable, which would force an expansion. */
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion libcextract/MacroWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool MacroWalker::Is_Identifier_Macro_Argument(MacroInfo *info, StringRef tok_st
{
for (const IdentifierInfo *arg : info->params()) {
StringRef arg_str = arg->getName();
if (tok_str.equals(arg_str)) {
if (tok_str == arg_str) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion libcextract/PrettyPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void PrettyPrint::Print_Decl_Raw(Decl *decl)
/* If for some reason Get_Source_Text is unable to find the source range
which comes this declaration because it is very complex, then fall back
to AST dump. */
if (decl_source.equals("")) {
if (decl_source == "") {
/* TODO: warn user that we had to fallback to AST dump. */

if (TypedefNameDecl *typedecl = dyn_cast<TypedefNameDecl>(decl)) {
Expand Down
30 changes: 18 additions & 12 deletions libcextract/SymbolExternalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,12 @@ bool TextModifications::Insert_Into_FileEntryMap(const SourceLocation &loc)
FileID begin_id = SM.getFileID(loc);

/* Insert into the list of FileIDs. */
const FileEntry *fentry = SM.getFileEntryForID(begin_id);
OptionalFileEntryRef fentry_ref = SM.getFileEntryRefForID(begin_id);
const FileEntry *fentry = nullptr;

if (fentry_ref.has_value()) {
fentry = &fentry_ref->getFileEntry();
}

/* There are some cases where the fentry is known to return NULL. Check if
those are the cases we already acknownledged. */
Expand All @@ -424,7 +429,7 @@ bool TextModifications::Insert_Into_FileEntryMap(const SourceLocation &loc)
/* Insert the FileEntry if we don't have one. */
if (FileEntryMap.find(fentry) == FileEntryMap.end()) {
/* Insert it. */
FileEntryMap[fentry] = begin_id;
FileEntryMap[fentry] = std::pair(begin_id, fentry_ref->getName());
return true;
}

Expand Down Expand Up @@ -490,7 +495,7 @@ void TextModifications::Dump(unsigned num, const Delta &a)
/*
const FileEntry *fentry = it->first;
*/
FileID id = it->second;
FileID id = it->second.first;

/* Our updated file buffer. */
const RewriteBuffer *rewritebuf = RW.getRewriteBufferFor(id);
Expand Down Expand Up @@ -676,8 +681,8 @@ bool SymbolExternalizer::Commit_Changes_To_Source(
because it may translate to the FileID that do not contain any changed
buffer. Hence we do our own thing here, which is look at our own
FileEntry => FileID that we are sure to have modifications. */
const FileEntry *fentry = it->first;
FileID id = it->second;
FileID id = it->second.first;
StringRef filename = it->second.second;

const RewriteBuffer *rewritebuf = RW.getRewriteBufferFor(id);

Expand All @@ -690,15 +695,14 @@ bool SymbolExternalizer::Commit_Changes_To_Source(
it to the SourceManager. */
std::string modified_str = std::string(rewritebuf->begin(), rewritebuf->end());

if (new_mfs->addFile(fentry->getName(),
if (new_mfs->addFile(filename,
0, MemoryBuffer::getMemBufferCopy(modified_str)) == false) {
llvm::outs() << "Unable to add " << fentry->getName() << " into InMemoryFS.\n";
llvm::outs() << "Unable to add " << filename << " into InMemoryFS.\n";
}

/* In case this is not the main file, we need to mark it for expansion. */
if (id != sm.getMainFileID()) {
StringRef file_name = fentry->getName();
includes_to_expand.push_back(file_name.str());
includes_to_expand.push_back(filename.str());
} else {
main_file_inserted = true;
}
Expand All @@ -710,12 +714,14 @@ bool SymbolExternalizer::Commit_Changes_To_Source(
/* Make sure we inserted the main file. */
if (main_file_inserted == false) {
FileID id = sm.getMainFileID();
const FileEntry *fentry = sm.getFileEntryForID(id);
OptionalFileEntryRef fentry_ref = sm.getFileEntryRefForID(id);
StringRef filename = fentry_ref->getName();

const std::string &main_file_content = Get_Modifications_To_Main_File();
if (new_mfs->addFile(fentry->getName(),
if (new_mfs->addFile(filename,
0,
MemoryBuffer::getMemBufferCopy(main_file_content)) == false) {
llvm::outs() << "Unable to add " << fentry->getName() << " into InMemoryFS.\n";
llvm::outs() << "Unable to add " << filename << " into InMemoryFS.\n";
}
}

Expand Down
7 changes: 5 additions & 2 deletions libcextract/SymbolExternalizer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ class TextModifications
void Commit(void);

/* Get FileEntry map. */
inline const std::unordered_map<const FileEntry *, FileID> &Get_FileEntry_Map(void)
typedef std::unordered_map<const FileEntry *, std::pair<FileID, StringRef>>
FileEntryMapType;

inline const FileEntryMapType &Get_FileEntry_Map(void)
{
return FileEntryMap;
}
Expand Down Expand Up @@ -272,7 +275,7 @@ class TextModifications

/* Our own mapping from FileEntry to FileID to get the modifications to the
files. */
std::unordered_map<const FileEntry *, FileID> FileEntryMap;
FileEntryMapType FileEntryMap;
};

/** Class encapsulating the Symbol externalizer mechanism.
Expand Down
2 changes: 1 addition & 1 deletion testsuite/ccp/ext-obj-5.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ void pu_f(void)
ee_o;
}

/* { dg-final { scan-tree-dump "static char \(\*klpe_ee_o\)\[4\] __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static char \(\*klpe_ee_o\)\[4\] __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static char \(\*klpe_ee_o\)\[4\];" } } */
/* { dg-final { scan-tree-dump "char s\[sizeof\(\(\*klpe_ee_o\)\)\], t\[sizeof\(\(\*klpe_ee_o\)\)\]\[sizeof\(\(\*klpe_ee_o\)\)\];" } } */
2 changes: 1 addition & 1 deletion testsuite/includes/rewrite-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ int g(void)
return f();
}

/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(void\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(void\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_f\)\(void\);" } } */
/* { dg-final { scan-tree-dump "\(\*klpe_f\)\(\)" } } */
/* { dg-final { scan-tree-dump-not "#include \"header-1.h\"" } } */
2 changes: 1 addition & 1 deletion testsuite/includes/rewrite-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ int g(void)
return f();
}

/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(void\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(void\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_f\)\(void\);" } } */
/* { dg-final { scan-tree-dump "\(\*klpe_f\)\(\)" } } */
/* { dg-final { scan-tree-dump-not "#include \"header-1.h\"" } } */
2 changes: 1 addition & 1 deletion testsuite/includes/rewrite-4.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ int g(void)
return f();
}

/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(void\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(void\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_f\)\(void\);" } } */
/* { dg-final { scan-tree-dump "\(\*klpe_f\)\(\)" } } */
2 changes: 1 addition & 1 deletion testsuite/lateext/lateext-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ int h(void)
}

/* { dg-final { scan-tree-dump "#define MACRO\n#include \"lateext-2.h\"\n#undef MACRO\n#include \"lateext-2.h\"" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(void\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(void\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_f\)\(void\);" } } */
/* { dg-final { scan-tree-dump "return \(\*klpe_f\)\(\) \+ g\(\);" } } */
2 changes: 1 addition & 1 deletion testsuite/lateext/lateext-3.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ int f(void)
return inline_func();
}

/* { dg-final { scan-tree-dump "static int \*klpe_var __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \*klpe_var __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \*klpe_var;" } } */
/* { dg-final { scan-tree-dump-not "#include \"lateext-3.h\"" } } */
2 changes: 1 addition & 1 deletion testsuite/lateext/lateext-4.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ MACRO f(void)
}

/* { dg-final { scan-tree-dump "#include \"lateext-4.h\"" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(void\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(void\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_g\)\(void\);" } } */
/* { dg-final { scan-tree-dump "return \(\*klpe_g\)\(\);" } } */
2 changes: 1 addition & 1 deletion testsuite/lateext/lateext-5.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ int f(void)
}

/* { dg-final { scan-tree-dump "#include \"lateext-4.h\"" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(void\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(void\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_g\)\(void\);" } } */
/* { dg-final { scan-tree-dump "return \(\*klpe_g\)\(\);" } } */
2 changes: 1 addition & 1 deletion testsuite/lateext/lateext-6.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ int f(void)
}

/* { dg-final { scan-tree-dump-not "int g\(void\)" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(void\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(void\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_g\)\(void\);" } } */
/* { dg-final { scan-tree-dump "return \(\*klpe_g\)\(\);" } } */
2 changes: 1 addition & 1 deletion testsuite/lateext/lateext-7.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ int f(void)
}

/* { dg-final { scan-tree-dump-not "DEFINE_STATIC_KEY_FALSE\(\*klpe_aaa\)" } } */
/* { dg-final { scan-tree-dump "static struct AA \*klpe_aaa __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static struct AA \*klpe_aaa __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static struct AA \*klpe_aaa;" } } */
2 changes: 1 addition & 1 deletion testsuite/lateext/location-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ int f(void)
return global;
}

/* { dg-final { scan-tree-dump "static int \*klpe_global __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \*klpe_global __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \*klpe_global;" } } */
/* { dg-final { scan-tree-dump "clang-extract: from .*location-1.h:29:1" } } */
2 changes: 1 addition & 1 deletion testsuite/small/rename-10.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ int g()
return f();
}

/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_f\)\(\);" } } */
/* { dg-final { scan-tree-dump "return \(\*klpe_f\)\(\);" } } */
2 changes: 1 addition & 1 deletion testsuite/small/rename-12.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ int f(void)
}

/* { dg-final { scan-tree-dump-not "static int g" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_g\)\(\);" } } */
/* { dg-final { scan-tree-dump "int klpp_f\(void\)\n{\n *return \(\*klpe_g\)\(\)" } } */
2 changes: 1 addition & 1 deletion testsuite/small/rename-15.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ int f(void)
}

/* { dg-final { scan-tree-dump "return \(\*klpe_g\)\(3\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(int\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(int\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_g\)\(int\);" } } */
2 changes: 1 addition & 1 deletion testsuite/small/rename-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ int f(void)
}

/* { dg-final { scan-tree-dump-not "static int g" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_g\)\(\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_g\)\(\);" } } */
/* { dg-final { scan-tree-dump "int f\(void\)\n{\n *return \(\*klpe_g\)\(\)" } } */
2 changes: 1 addition & 1 deletion testsuite/small/rename-3.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ int g(void)
return f();
}

/* { dg-final { scan-tree-dump "static int \(\*\*klpe_f\)\(void\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*\*klpe_f\)\(void\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*\*klpe_f\)\(void\);" } } */
/* { dg-final { scan-tree-dump "int g\(void\)\n{\n *return \(\*klpe_f\)\(\)" } } */
2 changes: 1 addition & 1 deletion testsuite/small/rename-4.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ int g()
return f();
}

/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_f\)\(\)" } } */
/* { dg-final { scan-tree-dump "return \(\*klpe_f\)\(\);" } } */
2 changes: 1 addition & 1 deletion testsuite/small/rename-5.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* { dg-options "-DCE_EXTRACT_FUNCTIONS=g -DCE_EXPORT_SYMBOLS=f" }*/
#include "rename-5.h"

/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \(\*klpe_f\)\(\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \(\*klpe_f\)\(\);" } } */
/* { dg-final { scan-tree-dump "return \(\*klpe_f\)\(\);" } } */
2 changes: 1 addition & 1 deletion testsuite/small/rename-6.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ int g()
return a;
}

/* { dg-final { scan-tree-dump "static int \*klpe_a __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \*klpe_a __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \*klpe_a" } } */
/* { dg-final { scan-tree-dump "\(\*klpe_a\) = x;" } } */
/* { dg-final { scan-tree-dump "return \(\*klpe_a\);" } } */
2 changes: 1 addition & 1 deletion testsuite/small/rename-8.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ int f()
return A + B ;
}

/* { dg-final { scan-tree-dump "static int \*klpe_bbb __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static int \*klpe_bbb __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static int \*klpe_bbb;" } } */
/* { dg-final { scan-tree-dump "#define A \(\*klpe_bbb\)" } } */
/* { dg-final { scan-tree-dump "#define B \(\*klpe_bbb\)" } } */
2 changes: 1 addition & 1 deletion testsuite/small/rename-9.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ int f()
return OPENSSL_strdup("aaa");
}

/* { dg-final { scan-tree-dump "static char \(\*klpe_CRYPTO_strdup\)\(const char \*, const char \*, int\) __attribute__\(\(used\)\);" } } */
/* { dg-final { scan-tree-dump "static char \(\*klpe_CRYPTO_strdup\)\(const char \*, const char \*, int\) __attribute__\(\(used\)\);|__attribute__\(\(used\)\) static char \(\*klpe_CRYPTO_strdup\)\(const char \*, const char \*, int\);" } } */
/* { dg-final { scan-tree-dump "\(\*klpe_CRYPTO_strdup\)\(str," } } */

0 comments on commit 8344124

Please sign in to comment.