Skip to content

Commit a6007db

Browse files
Fix some clang-tidy suggested issues
1 parent b842c5d commit a6007db

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
@@ -39,6 +39,7 @@
3939
#include <set>
4040
#include <sstream>
4141
#include <string>
42+
#include <utility>
4243

4344
// Stream redirect.
4445
#ifdef _WIN32
@@ -3454,40 +3455,50 @@ namespace Cpp {
34543455
}
34553456

34563457
class AutoLoadLibrarySearchGenerator;
3457-
static AutoLoadLibrarySearchGenerator *ALLSG = nullptr;
3458+
3459+
// Last assigned Autoload SearchGenerator
3460+
// TODO: Test for thread safe.
3461+
static AutoLoadLibrarySearchGenerator *AutoSG = nullptr;
34583462

34593463
class AutoLoadLibrarySearchGenerator : public llvm::orc::DefinitionGenerator {
3460-
public:
34613464
bool Enabled = false;
3465+
public:
3466+
bool isEnabled() {
3467+
return Enabled;
3468+
}
3469+
3470+
void setEnabled(bool enabled) {
3471+
Enabled = enabled;
3472+
}
34623473

34633474
// Lazy materialization unit class helper
34643475
class AutoloadLibraryMU : public llvm::orc::MaterializationUnit {
3465-
std::string lib;
3476+
const std::string lib;
34663477
llvm::orc::SymbolNameVector syms;
34673478
public:
3468-
AutoloadLibraryMU(const std::string &Library, const llvm::orc::SymbolNameVector &Symbols)
3479+
AutoloadLibraryMU(const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
34693480
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), lib(Library), syms(Symbols) {}
34703481

3471-
StringRef getName() const override {
3482+
[[nodiscard]] StringRef getName() const override {
34723483
return "<Symbols from Autoloaded Library>";
34733484
}
34743485

34753486
void materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3476-
if (!ALLSG || !ALLSG->Enabled) {
3487+
if (!AutoSG || !AutoSG->isEnabled()) {
34773488
R->failMaterialization();
34783489
return;
34793490
}
34803491

34813492
LLVM_DEBUG(dbgs() << "Materialize " << lib << " syms=" << syms);
34823493

34833494
auto& I = getInterp();
3484-
auto DLM = I.getDynamicLibraryManager();
3495+
auto *DLM = I.getDynamicLibraryManager();
34853496

34863497
llvm::orc::SymbolMap loadedSymbols;
34873498
llvm::orc::SymbolNameSet failedSymbols;
34883499
bool loadedLibrary = false;
34893500

3490-
for (auto symbol : syms) {
3501+
for (const auto &symbol : syms) {
34913502
std::string symbolStr = (*symbol).str();
34923503
std::string nameForDlsym = DemangleNameForDlsym(symbolStr);
34933504

@@ -3539,24 +3550,24 @@ namespace Cpp {
35393550
private:
35403551
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap(const llvm::orc::SymbolNameVector &Symbols) {
35413552
llvm::orc::SymbolFlagsMap map;
3542-
for (auto symbolName : Symbols)
3553+
for (const auto &symbolName : Symbols)
35433554
map[symbolName] = llvm::JITSymbolFlags::Exported;
35443555
return map;
35453556
}
35463557
};
35473558

35483559
llvm::Error tryToGenerate(llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
35493560
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3550-
if (Enabled) {
3561+
if (isEnabled()) {
35513562
LLVM_DEBUG(dbgs() << "tryToGenerate");
35523563

35533564
auto& I = getInterp();
3554-
auto DLM = I.getDynamicLibraryManager();
3565+
auto *DLM = I.getDynamicLibraryManager();
35553566

35563567
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
35573568
llvm::orc::SymbolMap NewSymbols;
3558-
for (auto &KV : Symbols) {
3559-
auto &Name = KV.first;
3569+
for (const auto &KV : Symbols) {
3570+
const auto &Name = KV.first;
35603571
if ((*Name).empty())
35613572
continue;
35623573

@@ -3582,6 +3593,7 @@ namespace Cpp {
35823593

35833594
return llvm::Error::success();
35843595
}
3596+
35853597
};
35863598

35873599
void SetLibrariesAutoload(bool autoload /* = true */) {
@@ -3593,16 +3605,16 @@ namespace Cpp {
35933605
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib().get();
35943606
#endif // CLANG_VERSION_MAJOR
35953607

3596-
if (!ALLSG)
3597-
ALLSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3598-
ALLSG->Enabled = autoload;
3608+
if (!AutoSG)
3609+
AutoSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3610+
AutoSG->setEnabled(autoload);
35993611

3600-
LLVM_DEBUG(dbgs() << "Autoload=" << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3612+
LLVM_DEBUG(dbgs() << "Autoload=" << (AutoSG->isEnabled() ? "ON" : "OFF"));
36013613
}
36023614

36033615
bool GetLibrariesAutoload() {
3604-
LLVM_DEBUG(dbgs() << "Autoload is " << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3605-
return ALLSG && ALLSG->Enabled;
3616+
LLVM_DEBUG(dbgs() << "Autoload is " << (AutoSG && AutoSG->isEnabled() ? "ON" : "OFF"));
3617+
return AutoSG && AutoSG->isEnabled();
36063618
}
36073619

36083620
#undef DEBUG_TYPE

0 commit comments

Comments
 (0)