Skip to content

Commit 4ba5027

Browse files
Fix some clang-tidy suggested issues
1 parent ee81802 commit 4ba5027

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
@@ -40,6 +40,7 @@
4040
#include <set>
4141
#include <sstream>
4242
#include <string>
43+
#include <utility>
4344

4445
// Stream redirect.
4546
#ifdef _WIN32
@@ -3533,40 +3534,50 @@ namespace Cpp {
35333534
}
35343535

35353536
class AutoLoadLibrarySearchGenerator;
3536-
static AutoLoadLibrarySearchGenerator *ALLSG = nullptr;
3537+
3538+
// Last assigned Autoload SearchGenerator
3539+
// TODO: Test for thread safe.
3540+
static AutoLoadLibrarySearchGenerator *AutoSG = nullptr;
35373541

35383542
class AutoLoadLibrarySearchGenerator : public llvm::orc::DefinitionGenerator {
3539-
public:
35403543
bool Enabled = false;
3544+
public:
3545+
bool isEnabled() {
3546+
return Enabled;
3547+
}
3548+
3549+
void setEnabled(bool enabled) {
3550+
Enabled = enabled;
3551+
}
35413552

35423553
// Lazy materialization unit class helper
35433554
class AutoloadLibraryMU : public llvm::orc::MaterializationUnit {
3544-
std::string lib;
3555+
const std::string lib;
35453556
llvm::orc::SymbolNameVector syms;
35463557
public:
3547-
AutoloadLibraryMU(const std::string &Library, const llvm::orc::SymbolNameVector &Symbols)
3558+
AutoloadLibraryMU(const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
35483559
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), lib(Library), syms(Symbols) {}
35493560

3550-
StringRef getName() const override {
3561+
[[nodiscard]] StringRef getName() const override {
35513562
return "<Symbols from Autoloaded Library>";
35523563
}
35533564

35543565
void materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3555-
if (!ALLSG || !ALLSG->Enabled) {
3566+
if (!AutoSG || !AutoSG->isEnabled()) {
35563567
R->failMaterialization();
35573568
return;
35583569
}
35593570

35603571
LLVM_DEBUG(dbgs() << "Materialize " << lib << " syms=" << syms);
35613572

35623573
auto& I = getInterp();
3563-
auto DLM = I.getDynamicLibraryManager();
3574+
auto *DLM = I.getDynamicLibraryManager();
35643575

35653576
llvm::orc::SymbolMap loadedSymbols;
35663577
llvm::orc::SymbolNameSet failedSymbols;
35673578
bool loadedLibrary = false;
35683579

3569-
for (auto symbol : syms) {
3580+
for (const auto &symbol : syms) {
35703581
std::string symbolStr = (*symbol).str();
35713582
std::string nameForDlsym = DemangleNameForDlsym(symbolStr);
35723583

@@ -3618,24 +3629,24 @@ namespace Cpp {
36183629
private:
36193630
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap(const llvm::orc::SymbolNameVector &Symbols) {
36203631
llvm::orc::SymbolFlagsMap map;
3621-
for (auto symbolName : Symbols)
3632+
for (const auto &symbolName : Symbols)
36223633
map[symbolName] = llvm::JITSymbolFlags::Exported;
36233634
return map;
36243635
}
36253636
};
36263637

36273638
llvm::Error tryToGenerate(llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
36283639
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3629-
if (Enabled) {
3640+
if (isEnabled()) {
36303641
LLVM_DEBUG(dbgs() << "tryToGenerate");
36313642

36323643
auto& I = getInterp();
3633-
auto DLM = I.getDynamicLibraryManager();
3644+
auto *DLM = I.getDynamicLibraryManager();
36343645

36353646
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
36363647
llvm::orc::SymbolMap NewSymbols;
3637-
for (auto &KV : Symbols) {
3638-
auto &Name = KV.first;
3648+
for (const auto &KV : Symbols) {
3649+
const auto &Name = KV.first;
36393650
if ((*Name).empty())
36403651
continue;
36413652

@@ -3661,6 +3672,7 @@ namespace Cpp {
36613672

36623673
return llvm::Error::success();
36633674
}
3675+
36643676
};
36653677

36663678
void SetLibrariesAutoload(bool autoload /* = true */) {
@@ -3672,16 +3684,16 @@ namespace Cpp {
36723684
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib().get();
36733685
#endif // CLANG_VERSION_MAJOR
36743686

3675-
if (!ALLSG)
3676-
ALLSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3677-
ALLSG->Enabled = autoload;
3687+
if (!AutoSG)
3688+
AutoSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3689+
AutoSG->setEnabled(autoload);
36783690

3679-
LLVM_DEBUG(dbgs() << "Autoload=" << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3691+
LLVM_DEBUG(dbgs() << "Autoload=" << (AutoSG->isEnabled() ? "ON" : "OFF"));
36803692
}
36813693

36823694
bool GetLibrariesAutoload() {
3683-
LLVM_DEBUG(dbgs() << "Autoload is " << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3684-
return ALLSG && ALLSG->Enabled;
3695+
LLVM_DEBUG(dbgs() << "Autoload is " << (AutoSG && AutoSG->isEnabled() ? "ON" : "OFF"));
3696+
return AutoSG && AutoSG->isEnabled();
36853697
}
36863698

36873699
#undef DEBUG_TYPE

0 commit comments

Comments
 (0)