Skip to content

Commit aae272b

Browse files
Fix some clang-tidy suggested issues
1 parent a4242e9 commit aae272b

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
@@ -41,6 +41,7 @@
4141
#include <set>
4242
#include <sstream>
4343
#include <string>
44+
#include <utility>
4445

4546
// Stream redirect.
4647
#ifdef _WIN32
@@ -3565,40 +3566,50 @@ namespace Cpp {
35653566
}
35663567

35673568
class AutoLoadLibrarySearchGenerator;
3568-
static AutoLoadLibrarySearchGenerator *ALLSG = nullptr;
3569+
3570+
// Last assigned Autoload SearchGenerator
3571+
// TODO: Test for thread safe.
3572+
static AutoLoadLibrarySearchGenerator *AutoSG = nullptr;
35693573

35703574
class AutoLoadLibrarySearchGenerator : public llvm::orc::DefinitionGenerator {
3571-
public:
35723575
bool Enabled = false;
3576+
public:
3577+
bool isEnabled() {
3578+
return Enabled;
3579+
}
3580+
3581+
void setEnabled(bool enabled) {
3582+
Enabled = enabled;
3583+
}
35733584

35743585
// Lazy materialization unit class helper
35753586
class AutoloadLibraryMU : public llvm::orc::MaterializationUnit {
3576-
std::string lib;
3587+
const std::string lib;
35773588
llvm::orc::SymbolNameVector syms;
35783589
public:
3579-
AutoloadLibraryMU(const std::string &Library, const llvm::orc::SymbolNameVector &Symbols)
3590+
AutoloadLibraryMU(const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
35803591
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), lib(Library), syms(Symbols) {}
35813592

3582-
StringRef getName() const override {
3593+
[[nodiscard]] StringRef getName() const override {
35833594
return "<Symbols from Autoloaded Library>";
35843595
}
35853596

35863597
void materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3587-
if (!ALLSG || !ALLSG->Enabled) {
3598+
if (!AutoSG || !AutoSG->isEnabled()) {
35883599
R->failMaterialization();
35893600
return;
35903601
}
35913602

35923603
LLVM_DEBUG(dbgs() << "Materialize " << lib << " syms=" << syms);
35933604

35943605
auto& I = getInterp();
3595-
auto DLM = I.getDynamicLibraryManager();
3606+
auto *DLM = I.getDynamicLibraryManager();
35963607

35973608
llvm::orc::SymbolMap loadedSymbols;
35983609
llvm::orc::SymbolNameSet failedSymbols;
35993610
bool loadedLibrary = false;
36003611

3601-
for (auto symbol : syms) {
3612+
for (const auto &symbol : syms) {
36023613
std::string symbolStr = (*symbol).str();
36033614
std::string nameForDlsym = DemangleNameForDlsym(symbolStr);
36043615

@@ -3650,24 +3661,24 @@ namespace Cpp {
36503661
private:
36513662
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap(const llvm::orc::SymbolNameVector &Symbols) {
36523663
llvm::orc::SymbolFlagsMap map;
3653-
for (auto symbolName : Symbols)
3664+
for (const auto &symbolName : Symbols)
36543665
map[symbolName] = llvm::JITSymbolFlags::Exported;
36553666
return map;
36563667
}
36573668
};
36583669

36593670
llvm::Error tryToGenerate(llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
36603671
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3661-
if (Enabled) {
3672+
if (isEnabled()) {
36623673
LLVM_DEBUG(dbgs() << "tryToGenerate");
36633674

36643675
auto& I = getInterp();
3665-
auto DLM = I.getDynamicLibraryManager();
3676+
auto *DLM = I.getDynamicLibraryManager();
36663677

36673678
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
36683679
llvm::orc::SymbolMap NewSymbols;
3669-
for (auto &KV : Symbols) {
3670-
auto &Name = KV.first;
3680+
for (const auto &KV : Symbols) {
3681+
const auto &Name = KV.first;
36713682
if ((*Name).empty())
36723683
continue;
36733684

@@ -3693,6 +3704,7 @@ namespace Cpp {
36933704

36943705
return llvm::Error::success();
36953706
}
3707+
36963708
};
36973709

36983710
void SetLibrariesAutoload(bool autoload /* = true */) {
@@ -3704,16 +3716,16 @@ namespace Cpp {
37043716
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib().get();
37053717
#endif // CLANG_VERSION_MAJOR
37063718

3707-
if (!ALLSG)
3708-
ALLSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3709-
ALLSG->Enabled = autoload;
3719+
if (!AutoSG)
3720+
AutoSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
3721+
AutoSG->setEnabled(autoload);
37103722

3711-
LLVM_DEBUG(dbgs() << "Autoload=" << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3723+
LLVM_DEBUG(dbgs() << "Autoload=" << (AutoSG->isEnabled() ? "ON" : "OFF"));
37123724
}
37133725

37143726
bool GetLibrariesAutoload() {
3715-
LLVM_DEBUG(dbgs() << "Autoload is " << (ALLSG && ALLSG->Enabled ? "ON" : "OFF"));
3716-
return ALLSG && ALLSG->Enabled;
3727+
LLVM_DEBUG(dbgs() << "Autoload is " << (AutoSG && AutoSG->isEnabled() ? "ON" : "OFF"));
3728+
return AutoSG && AutoSG->isEnabled();
37173729
}
37183730

37193731
#undef DEBUG_TYPE

0 commit comments

Comments
 (0)