From 9ea02403df488fc8eab0c68f052cf2bee9e68784 Mon Sep 17 00:00:00 2001 From: Benjamin Welton Date: Tue, 15 Oct 2024 22:20:38 -0700 Subject: [PATCH] Clang Warning Fixes (#1131) Builds prevented on clang-18 [ROCm/rocprofiler-sdk commit: 28a6918b331077b4427bbd8354d3373785d2972b] --- .../cxx/codeobj/code_printing.hpp | 36 ++++++++++--------- .../cxx/codeobj/disassembly.hpp | 21 +++++------ 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/codeobj/code_printing.hpp b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/codeobj/code_printing.hpp index 575544d65b..0418c7eb8c 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/codeobj/code_printing.hpp +++ b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/codeobj/code_printing.hpp @@ -105,15 +105,17 @@ public: std::map line_addrs; - while(!dwarf_nextcu( - dbg.get(), cu_offset, &next_offset, &header_size, nullptr, nullptr, nullptr)) + while( + dwarf_nextcu( + dbg.get(), cu_offset, &next_offset, &header_size, nullptr, nullptr, nullptr) == + 0) { Dwarf_Die die; if(!dwarf_offdie(dbg.get(), cu_offset + header_size, &die)) continue; Dwarf_Lines* lines; size_t line_count; - if(dwarf_getsrclines(&die, &lines, &line_count)) continue; + if(dwarf_getsrclines(&die, &lines, &line_count) != 0) continue; for(size_t i = 0; i < line_count; ++i) { @@ -121,8 +123,8 @@ public: int line_number; Dwarf_Line* line = dwarf_onesrcline(lines, i); - if(line && !dwarf_lineaddr(line, &addr) && !dwarf_lineno(line, &line_number) && - line_number) + if(line && dwarf_lineaddr(line, &addr) == 0 && + dwarf_lineno(line, &line_number) == 0 && line_number != 0) { std::string src = dwarf_linesrc(line, nullptr, nullptr); auto dwarf_line = src + ':' + std::to_string(line_number); @@ -162,9 +164,9 @@ public: } catch(...) {} } - ~CodeobjDecoderComponent() {} + ~CodeobjDecoderComponent() = default; - std::optional va2fo(uint64_t vaddr) + std::optional va2fo(uint64_t vaddr) const { if(disassembly) return disassembly->va2fo(vaddr); return {}; @@ -342,21 +344,21 @@ public: CodeobjAddressTranslate() = default; ~CodeobjAddressTranslate() override = default; - virtual void addDecoder(const char* filepath, - marker_id_t id, - uint64_t load_addr, - uint64_t memsize) override + void addDecoder(const char* filepath, + marker_id_t id, + uint64_t load_addr, + uint64_t memsize) override { this->Super::addDecoder(filepath, id, load_addr, memsize); auto ptr = decoders.at(id); table.insert({ptr->begin(), ptr->size(), id}); } - virtual void addDecoder(const void* data, - size_t memory_size, - marker_id_t id, - uint64_t load_addr, - uint64_t memsize) override + void addDecoder(const void* data, + size_t memory_size, + marker_id_t id, + uint64_t load_addr, + uint64_t memsize) override { this->Super::addDecoder(data, memory_size, id, load_addr, memsize); auto ptr = decoders.at(id); @@ -396,7 +398,7 @@ public: { std::map symbols; - for(auto& [_, dec] : decoders) + for(const auto& [_, dec] : decoders) { auto& smap = dec->getSymbolMap(); for(auto& [vaddr, sym] : smap) diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/codeobj/disassembly.hpp b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/codeobj/disassembly.hpp index ea7f9a632e..ea48cd9e8e 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/codeobj/disassembly.hpp +++ b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/codeobj/disassembly.hpp @@ -47,7 +47,7 @@ const char* reason = ""; \ amd_comgr_status_string(status, &reason); \ std::cerr << __FILE__ << ':' << __LINE__ << " code: " << status << " failed: " << reason \ - << std::endl; \ + << "\n"; \ throw std::exception(); \ } @@ -57,14 +57,14 @@ const char* reason = ""; \ amd_comgr_status_string(status, &reason); \ std::cerr << __FILE__ << ':' << __LINE__ << " code: " << status << " failed: " << reason \ - << std::endl; \ + << "\n"; \ return AMD_COMGR_STATUS_ERROR; \ } #define CHECK_VA2FO(x, msg) \ if(!(x)) \ { \ - std::cerr << __FILE__ << ' ' << __LINE__ << ' ' << msg << std::endl; \ + std::cerr << __FILE__ << ' ' << __LINE__ << ' ' << msg << "\n"; \ return std::nullopt; \ } @@ -79,8 +79,8 @@ namespace disassembly class CodeObjectBinary { public: - CodeObjectBinary(const std::string& _uri) - : m_uri(_uri) + CodeObjectBinary(std::string _uri) + : m_uri(std::move(_uri)) { const std::string protocol_delim{"://"}; @@ -108,9 +108,9 @@ public: decoded_path.reserve(path.length()); for(size_t i = 0; i < path.length(); ++i) { - if(path[i] == '%' && std::isxdigit(path[i + 1]) && std::isxdigit(path[i + 2])) + if(path[i] == '%' && std::isxdigit(path[i + 1]) != 0 && std::isxdigit(path[i + 2]) != 0) { - decoded_path += std::stoi(path.substr(i + 1, 2), 0, 16); + decoded_path += std::stoi(path.substr(i + 1, 2), nullptr, 16); i += 2; } else @@ -153,7 +153,7 @@ public: if(auto size_it = params.find("size"); size_it != params.end()) { - if(!(size = std::stoul(size_it->second, nullptr, 0))) return; + if((size = std::stoul(size_it->second, nullptr, 0)) == 0) return; } if(protocol == "memory") throw std::runtime_error(protocol + " protocol not supported!"); @@ -161,7 +161,7 @@ public: std::ifstream file(decoded_path, std::ios::in | std::ios::binary); if(!file || !file.is_open()) throw std::runtime_error("could not open " + decoded_path); - if(!size) + if(size == 0) { file.ignore(std::numeric_limits::max()); size_t bytes = file.gcount(); @@ -174,7 +174,7 @@ public: file.seekg(offset, std::ios_base::beg); buffer.resize(size); - file.read(&buffer[0], size); + file.read(buffer.data(), size); } std::string m_uri; @@ -269,6 +269,7 @@ public: int64_t copysize = reinterpret_cast(instance.buffer.data()) + instance.buffer.size() - static_cast(from); copysize = std::min(size, copysize); + // NOLINTNEXTLINE(performance-no-int-to-ptr) std::memcpy(to, (char*) from, copysize); return copysize; }