Skip to content

Commit dcc9601

Browse files
Fix some clang-tidy suggested issues
1 parent f7471c1 commit dcc9601

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
@@ -3375,40 +3376,50 @@ namespace Cpp {
33753376
}
33763377

33773378
class AutoLoadLibrarySearchGenerator;
3378-
static AutoLoadLibrarySearchGenerator *ALLSG = nullptr;
3379+
3380+
// Last assigned Autoload SearchGenerator
3381+
// TODO: Test for thread safe.
3382+
static AutoLoadLibrarySearchGenerator *AutoSG = nullptr;
33793383

33803384
class AutoLoadLibrarySearchGenerator : public llvm::orc::DefinitionGenerator {
3381-
public:
33823385
bool Enabled = false;
3386+
public:
3387+
bool isEnabled() {
3388+
return Enabled;
3389+
}
3390+
3391+
void setEnabled(bool enabled) {
3392+
Enabled = enabled;
3393+
}
33833394

33843395
// Lazy materialization unit class helper
33853396
class AutoloadLibraryMU : public llvm::orc::MaterializationUnit {
3386-
std::string lib;
3397+
const std::string lib;
33873398
llvm::orc::SymbolNameVector syms;
33883399
public:
3389-
AutoloadLibraryMU(const std::string &Library, const llvm::orc::SymbolNameVector &Symbols)
3400+
AutoloadLibraryMU(const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
33903401
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), lib(Library), syms(Symbols) {}
33913402

3392-
StringRef getName() const override {
3403+
[[nodiscard]] StringRef getName() const override {
33933404
return "<Symbols from Autoloaded Library>";
33943405
}
33953406

33963407
void materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3397-
if (!ALLSG || !ALLSG->Enabled) {
3408+
if (!AutoSG || !AutoSG->isEnabled()) {
33983409
R->failMaterialization();
33993410
return;
34003411
}
34013412

34023413
LLVM_DEBUG(dbgs() << "Materialize " << lib << " syms=" << syms);
34033414

34043415
auto& I = getInterp();
3405-
auto DLM = I.getDynamicLibraryManager();
3416+
auto *DLM = I.getDynamicLibraryManager();
34063417

34073418
llvm::orc::SymbolMap loadedSymbols;
34083419
llvm::orc::SymbolNameSet failedSymbols;
34093420
bool loadedLibrary = false;
34103421

3411-
for (auto symbol : syms) {
3422+
for (const auto &symbol : syms) {
34123423
std::string symbolStr = (*symbol).str();
34133424
std::string nameForDlsym = DemangleNameForDlsym(symbolStr);
34143425

@@ -3460,24 +3471,24 @@ namespace Cpp {
34603471
private:
34613472
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap(const llvm::orc::SymbolNameVector &Symbols) {
34623473
llvm::orc::SymbolFlagsMap map;
3463-
for (auto symbolName : Symbols)
3474+
for (const auto &symbolName : Symbols)
34643475
map[symbolName] = llvm::JITSymbolFlags::Exported;
34653476
return map;
34663477
}
34673478
};
34683479

34693480
llvm::Error tryToGenerate(llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
34703481
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3471-
if (Enabled) {
3482+
if (isEnabled()) {
34723483
LLVM_DEBUG(dbgs() << "tryToGenerate");
34733484

34743485
auto& I = getInterp();
3475-
auto DLM = I.getDynamicLibraryManager();
3486+
auto *DLM = I.getDynamicLibraryManager();
34763487

34773488
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
34783489
llvm::orc::SymbolMap NewSymbols;
3479-
for (auto &KV : Symbols) {
3480-
auto &Name = KV.first;
3490+
for (const auto &KV : Symbols) {
3491+
const auto &Name = KV.first;
34813492
if ((*Name).empty())
34823493
continue;
34833494

@@ -3503,6 +3514,7 @@ namespace Cpp {
35033514

35043515
return llvm::Error::success();
35053516
}
3517+
35063518
};
35073519

35083520
void SetLibrariesAutoload(bool autoload /* = true */) {
@@ -3514,16 +3526,16 @@ namespace Cpp {
35143526
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib().get();
35153527
#endif // CLANG_VERSION_MAJOR
35163528

3517-
if (!ALLSG)
3518-
ALLSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3519-
ALLSG->Enabled = autoload;
3529+
if (!AutoSG)
3530+
AutoSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3531+
AutoSG->setEnabled(autoload);
35203532

3521-
LLVM_DEBUG(dbgs() << "Autoload=" << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3533+
LLVM_DEBUG(dbgs() << "Autoload=" << (AutoSG->isEnabled() ? "ON" : "OFF"));
35223534
}
35233535

35243536
bool GetLibrariesAutoload() {
3525-
LLVM_DEBUG(dbgs() << "Autoload is " << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3526-
return ALLSG && ALLSG->Enabled;
3537+
LLVM_DEBUG(dbgs() << "Autoload is " << (AutoSG && AutoSG->isEnabled() ? "ON" : "OFF"));
3538+
return AutoSG && AutoSG->isEnabled();
35273539
}
35283540

35293541
#undef DEBUG_TYPE

0 commit comments

Comments
 (0)