Skip to content

Commit 6ba9d58

Browse files
Fix some clang-tidy suggested issues
1 parent ba6aabd commit 6ba9d58

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include <sstream>
3939
#include <string>
40+
#include <utility>
4041

4142
// Stream redirect.
4243
#ifdef _WIN32
@@ -3370,40 +3371,50 @@ namespace Cpp {
33703371
}
33713372

33723373
class AutoLoadLibrarySearchGenerator;
3373-
static AutoLoadLibrarySearchGenerator *ALLSG = nullptr;
3374+
3375+
// Last assigned Autoload SearchGenerator
3376+
// TODO: Test for thread safe.
3377+
static AutoLoadLibrarySearchGenerator *AutoSG = nullptr;
33743378

33753379
class AutoLoadLibrarySearchGenerator : public llvm::orc::DefinitionGenerator {
3376-
public:
33773380
bool Enabled = false;
3381+
public:
3382+
bool isEnabled() {
3383+
return Enabled;
3384+
}
3385+
3386+
void setEnabled(bool enabled) {
3387+
Enabled = enabled;
3388+
}
33783389

33793390
// Lazy materialization unit class helper
33803391
class AutoloadLibraryMU : public llvm::orc::MaterializationUnit {
3381-
std::string lib;
3392+
const std::string lib;
33823393
llvm::orc::SymbolNameVector syms;
33833394
public:
3384-
AutoloadLibraryMU(const std::string &Library, const llvm::orc::SymbolNameVector &Symbols)
3395+
AutoloadLibraryMU(const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
33853396
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), lib(Library), syms(Symbols) {}
33863397

3387-
StringRef getName() const override {
3398+
[[nodiscard]] StringRef getName() const override {
33883399
return "<Symbols from Autoloaded Library>";
33893400
}
33903401

33913402
void materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3392-
if (!ALLSG || !ALLSG->Enabled) {
3403+
if (!AutoSG || !AutoSG->isEnabled()) {
33933404
R->failMaterialization();
33943405
return;
33953406
}
33963407

33973408
LLVM_DEBUG(dbgs() << "Materialize " << lib << " syms=" << syms);
33983409

33993410
auto& I = getInterp();
3400-
auto DLM = I.getDynamicLibraryManager();
3411+
auto *DLM = I.getDynamicLibraryManager();
34013412

34023413
llvm::orc::SymbolMap loadedSymbols;
34033414
llvm::orc::SymbolNameSet failedSymbols;
34043415
bool loadedLibrary = false;
34053416

3406-
for (auto symbol : syms) {
3417+
for (const auto &symbol : syms) {
34073418
std::string symbolStr = (*symbol).str();
34083419
std::string nameForDlsym = DemangleNameForDlsym(symbolStr);
34093420

@@ -3455,24 +3466,24 @@ namespace Cpp {
34553466
private:
34563467
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap(const llvm::orc::SymbolNameVector &Symbols) {
34573468
llvm::orc::SymbolFlagsMap map;
3458-
for (auto symbolName : Symbols)
3469+
for (const auto &symbolName : Symbols)
34593470
map[symbolName] = llvm::JITSymbolFlags::Exported;
34603471
return map;
34613472
}
34623473
};
34633474

34643475
llvm::Error tryToGenerate(llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
34653476
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3466-
if (Enabled) {
3477+
if (isEnabled()) {
34673478
LLVM_DEBUG(dbgs() << "tryToGenerate");
34683479

34693480
auto& I = getInterp();
3470-
auto DLM = I.getDynamicLibraryManager();
3481+
auto *DLM = I.getDynamicLibraryManager();
34713482

34723483
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
34733484
llvm::orc::SymbolMap NewSymbols;
3474-
for (auto &KV : Symbols) {
3475-
auto &Name = KV.first;
3485+
for (const auto &KV : Symbols) {
3486+
const auto &Name = KV.first;
34763487
if ((*Name).empty())
34773488
continue;
34783489

@@ -3498,6 +3509,7 @@ namespace Cpp {
34983509

34993510
return llvm::Error::success();
35003511
}
3512+
35013513
};
35023514

35033515
void SetLibrariesAutoload(bool autoload /* = true */) {
@@ -3509,16 +3521,16 @@ namespace Cpp {
35093521
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib().get();
35103522
#endif // CLANG_VERSION_MAJOR
35113523

3512-
if (!ALLSG)
3513-
ALLSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3514-
ALLSG->Enabled = autoload;
3524+
if (!AutoSG)
3525+
AutoSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3526+
AutoSG->setEnabled(autoload);
35153527

3516-
LLVM_DEBUG(dbgs() << "Autoload=" << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3528+
LLVM_DEBUG(dbgs() << "Autoload=" << (AutoSG->isEnabled() ? "ON" : "OFF"));
35173529
}
35183530

35193531
bool GetLibrariesAutoload() {
3520-
LLVM_DEBUG(dbgs() << "Autoload is " << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3521-
return ALLSG && ALLSG->Enabled;
3532+
LLVM_DEBUG(dbgs() << "Autoload is " << (AutoSG && AutoSG->isEnabled() ? "ON" : "OFF"));
3533+
return AutoSG && AutoSG->isEnabled();
35223534
}
35233535

35243536
#undef DEBUG_TYPE

0 commit comments

Comments
 (0)