Skip to content

Commit 2c91834

Browse files
Fix some clang-tidy suggested issues
1 parent 7bda1c3 commit 2c91834

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
@@ -34,6 +34,7 @@
3434

3535
#include <sstream>
3636
#include <string>
37+
#include <utility>
3738

3839
// Stream redirect.
3940
#ifdef _WIN32
@@ -3286,40 +3287,50 @@ namespace Cpp {
32863287
}
32873288

32883289
class AutoLoadLibrarySearchGenerator;
3289-
static AutoLoadLibrarySearchGenerator *ALLSG = nullptr;
3290+
3291+
// Last assigned Autoload SearchGenerator
3292+
// TODO: Test for thread safe.
3293+
static AutoLoadLibrarySearchGenerator *AutoSG = nullptr;
32903294

32913295
class AutoLoadLibrarySearchGenerator : public llvm::orc::DefinitionGenerator {
3292-
public:
32933296
bool Enabled = false;
3297+
public:
3298+
bool isEnabled() {
3299+
return Enabled;
3300+
}
3301+
3302+
void setEnabled(bool enabled) {
3303+
Enabled = enabled;
3304+
}
32943305

32953306
// Lazy materialization unit class helper
32963307
class AutoloadLibraryMU : public llvm::orc::MaterializationUnit {
3297-
std::string lib;
3308+
const std::string lib;
32983309
llvm::orc::SymbolNameVector syms;
32993310
public:
3300-
AutoloadLibraryMU(const std::string &Library, const llvm::orc::SymbolNameVector &Symbols)
3311+
AutoloadLibraryMU(const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
33013312
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), lib(Library), syms(Symbols) {}
33023313

3303-
StringRef getName() const override {
3314+
[[nodiscard]] StringRef getName() const override {
33043315
return "<Symbols from Autoloaded Library>";
33053316
}
33063317

33073318
void materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3308-
if (!ALLSG || !ALLSG->Enabled) {
3319+
if (!AutoSG || !AutoSG->isEnabled()) {
33093320
R->failMaterialization();
33103321
return;
33113322
}
33123323

33133324
LLVM_DEBUG(dbgs() << "Materialize " << lib << " syms=" << syms);
33143325

33153326
auto& I = getInterp();
3316-
auto DLM = I.getDynamicLibraryManager();
3327+
auto *DLM = I.getDynamicLibraryManager();
33173328

33183329
llvm::orc::SymbolMap loadedSymbols;
33193330
llvm::orc::SymbolNameSet failedSymbols;
33203331
bool loadedLibrary = false;
33213332

3322-
for (auto symbol : syms) {
3333+
for (const auto &symbol : syms) {
33233334
std::string symbolStr = (*symbol).str();
33243335
std::string nameForDlsym = DemangleNameForDlsym(symbolStr);
33253336

@@ -3371,24 +3382,24 @@ namespace Cpp {
33713382
private:
33723383
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap(const llvm::orc::SymbolNameVector &Symbols) {
33733384
llvm::orc::SymbolFlagsMap map;
3374-
for (auto symbolName : Symbols)
3385+
for (const auto &symbolName : Symbols)
33753386
map[symbolName] = llvm::JITSymbolFlags::Exported;
33763387
return map;
33773388
}
33783389
};
33793390

33803391
llvm::Error tryToGenerate(llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
33813392
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3382-
if (Enabled) {
3393+
if (isEnabled()) {
33833394
LLVM_DEBUG(dbgs() << "tryToGenerate");
33843395

33853396
auto& I = getInterp();
3386-
auto DLM = I.getDynamicLibraryManager();
3397+
auto *DLM = I.getDynamicLibraryManager();
33873398

33883399
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
33893400
llvm::orc::SymbolMap NewSymbols;
3390-
for (auto &KV : Symbols) {
3391-
auto &Name = KV.first;
3401+
for (const auto &KV : Symbols) {
3402+
const auto &Name = KV.first;
33923403
if ((*Name).empty())
33933404
continue;
33943405

@@ -3414,6 +3425,7 @@ namespace Cpp {
34143425

34153426
return llvm::Error::success();
34163427
}
3428+
34173429
};
34183430

34193431
void SetLibrariesAutoload(bool autoload /* = true */) {
@@ -3425,16 +3437,16 @@ namespace Cpp {
34253437
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib().get();
34263438
#endif // CLANG_VERSION_MAJOR
34273439

3428-
if (!ALLSG)
3429-
ALLSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3430-
ALLSG->Enabled = autoload;
3440+
if (!AutoSG)
3441+
AutoSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3442+
AutoSG->setEnabled(autoload);
34313443

3432-
LLVM_DEBUG(dbgs() << "Autoload=" << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3444+
LLVM_DEBUG(dbgs() << "Autoload=" << (AutoSG->isEnabled() ? "ON" : "OFF"));
34333445
}
34343446

34353447
bool GetLibrariesAutoload() {
3436-
LLVM_DEBUG(dbgs() << "Autoload is " << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3437-
return ALLSG && ALLSG->Enabled;
3448+
LLVM_DEBUG(dbgs() << "Autoload is " << (AutoSG && AutoSG->isEnabled() ? "ON" : "OFF"));
3449+
return AutoSG && AutoSG->isEnabled();
34383450
}
34393451

34403452
#undef DEBUG_TYPE

0 commit comments

Comments
 (0)