Skip to content

Commit 290d7f5

Browse files
alexander-penevmcbarton
authored andcommitted
Fix some clang-tidy suggested issues
1 parent d698b4e commit 290d7f5

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
@@ -3396,40 +3397,50 @@ namespace Cpp {
33963397
}
33973398

33983399
class AutoLoadLibrarySearchGenerator;
3399-
static AutoLoadLibrarySearchGenerator *ALLSG = nullptr;
3400+
3401+
// Last assigned Autoload SearchGenerator
3402+
// TODO: Test for thread safe.
3403+
static AutoLoadLibrarySearchGenerator *AutoSG = nullptr;
34003404

34013405
class AutoLoadLibrarySearchGenerator : public llvm::orc::DefinitionGenerator {
3402-
public:
34033406
bool Enabled = false;
3407+
public:
3408+
bool isEnabled() {
3409+
return Enabled;
3410+
}
3411+
3412+
void setEnabled(bool enabled) {
3413+
Enabled = enabled;
3414+
}
34043415

34053416
// Lazy materialization unit class helper
34063417
class AutoloadLibraryMU : public llvm::orc::MaterializationUnit {
3407-
std::string lib;
3418+
const std::string lib;
34083419
llvm::orc::SymbolNameVector syms;
34093420
public:
3410-
AutoloadLibraryMU(const std::string &Library, const llvm::orc::SymbolNameVector &Symbols)
3421+
AutoloadLibraryMU(const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
34113422
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), lib(Library), syms(Symbols) {}
34123423

3413-
StringRef getName() const override {
3424+
[[nodiscard]] StringRef getName() const override {
34143425
return "<Symbols from Autoloaded Library>";
34153426
}
34163427

34173428
void materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3418-
if (!ALLSG || !ALLSG->Enabled) {
3429+
if (!AutoSG || !AutoSG->isEnabled()) {
34193430
R->failMaterialization();
34203431
return;
34213432
}
34223433

34233434
LLVM_DEBUG(dbgs() << "Materialize " << lib << " syms=" << syms);
34243435

34253436
auto& I = getInterp();
3426-
auto DLM = I.getDynamicLibraryManager();
3437+
auto *DLM = I.getDynamicLibraryManager();
34273438

34283439
llvm::orc::SymbolMap loadedSymbols;
34293440
llvm::orc::SymbolNameSet failedSymbols;
34303441
bool loadedLibrary = false;
34313442

3432-
for (auto symbol : syms) {
3443+
for (const auto &symbol : syms) {
34333444
std::string symbolStr = (*symbol).str();
34343445
std::string nameForDlsym = DemangleNameForDlsym(symbolStr);
34353446

@@ -3481,24 +3492,24 @@ namespace Cpp {
34813492
private:
34823493
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap(const llvm::orc::SymbolNameVector &Symbols) {
34833494
llvm::orc::SymbolFlagsMap map;
3484-
for (auto symbolName : Symbols)
3495+
for (const auto &symbolName : Symbols)
34853496
map[symbolName] = llvm::JITSymbolFlags::Exported;
34863497
return map;
34873498
}
34883499
};
34893500

34903501
llvm::Error tryToGenerate(llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
34913502
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3492-
if (Enabled) {
3503+
if (isEnabled()) {
34933504
LLVM_DEBUG(dbgs() << "tryToGenerate");
34943505

34953506
auto& I = getInterp();
3496-
auto DLM = I.getDynamicLibraryManager();
3507+
auto *DLM = I.getDynamicLibraryManager();
34973508

34983509
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
34993510
llvm::orc::SymbolMap NewSymbols;
3500-
for (auto &KV : Symbols) {
3501-
auto &Name = KV.first;
3511+
for (const auto &KV : Symbols) {
3512+
const auto &Name = KV.first;
35023513
if ((*Name).empty())
35033514
continue;
35043515

@@ -3524,6 +3535,7 @@ namespace Cpp {
35243535

35253536
return llvm::Error::success();
35263537
}
3538+
35273539
};
35283540

35293541
void SetLibrariesAutoload(bool autoload /* = true */) {
@@ -3535,16 +3547,16 @@ namespace Cpp {
35353547
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib().get();
35363548
#endif // CLANG_VERSION_MAJOR
35373549

3538-
if (!ALLSG)
3539-
ALLSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3540-
ALLSG->Enabled = autoload;
3550+
if (!AutoSG)
3551+
AutoSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3552+
AutoSG->setEnabled(autoload);
35413553

3542-
LLVM_DEBUG(dbgs() << "Autoload=" << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3554+
LLVM_DEBUG(dbgs() << "Autoload=" << (AutoSG->isEnabled() ? "ON" : "OFF"));
35433555
}
35443556

35453557
bool GetLibrariesAutoload() {
3546-
LLVM_DEBUG(dbgs() << "Autoload is " << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3547-
return ALLSG && ALLSG->Enabled;
3558+
LLVM_DEBUG(dbgs() << "Autoload is " << (AutoSG && AutoSG->isEnabled() ? "ON" : "OFF"));
3559+
return AutoSG && AutoSG->isEnabled();
35483560
}
35493561

35503562
#undef DEBUG_TYPE

0 commit comments

Comments
 (0)