diff --git a/amd/comgr/src/comgr-env.cpp b/amd/comgr/src/comgr-env.cpp index b22a9b3e65e28b..0019aa1db1d3ee 100644 --- a/amd/comgr/src/comgr-env.cpp +++ b/amd/comgr/src/comgr-env.cpp @@ -38,6 +38,7 @@ #include "llvm/Support/VirtualFileSystem.h" #include +#include #include using namespace llvm; @@ -245,18 +246,18 @@ class SpackInstallationDetector : public InstallationDetector { } }; -InstallationDetector *CreatePathDetector(StringRef Path, - bool isComgrPath = false) { +std::shared_ptr +CreatePathDetector(StringRef Path, bool isComgrPath = false) { StringRef DirName = llvm::sys::path::filename(Path); if ((!isComgrPath && DirName.starts_with("rocm-cmake-")) || (isComgrPath && DirName.starts_with("comgr-"))) { - return new SpackInstallationDetector(Path, isComgrPath); + return std::make_shared(Path, isComgrPath); } - return new InstallationDetector(Path, isComgrPath); + return std::make_shared(Path, isComgrPath); } -InstallationDetector *getDetectorImpl() { +std::shared_ptr getDetectorImpl() { SmallString<128> ROCmInstallPath; static const char *EnvROCMPath = std::getenv("ROCM_PATH"); @@ -264,21 +265,16 @@ InstallationDetector *getDetectorImpl() { ROCmInstallPath = EnvROCMPath; } - InstallationDetector *Detector; if (ROCmInstallPath == "") { std::string ComgrInstallationPath = getComgrInstallPathFromExecutable(); - Detector = - CreatePathDetector(ComgrInstallationPath, true /* isComgrPath */); - } else { - Detector = CreatePathDetector(ROCmInstallPath); + return CreatePathDetector(ComgrInstallationPath, true /* isComgrPath */); } - - return Detector; + return CreatePathDetector(ROCmInstallPath); } InstallationDetector *getDetector() { - static InstallationDetector *Detector = getDetectorImpl(); - return Detector; + static auto Detector = getDetectorImpl(); + return Detector.get(); } llvm::StringRef getROCMPath() { return getDetector()->getROCmPath(); }