Clang Warning Fixes (#1131)

Builds prevented on clang-18

[ROCm/rocprofiler-sdk commit: 28a6918b33]
This commit is contained in:
Benjamin Welton
2024-10-15 22:20:38 -07:00
committato da GitHub
parent b610c50913
commit 9ea02403df
2 ha cambiato i file con 30 aggiunte e 27 eliminazioni
@@ -105,15 +105,17 @@ public:
std::map<uint64_t, std::string> line_addrs; std::map<uint64_t, std::string> line_addrs;
while(!dwarf_nextcu( while(
dbg.get(), cu_offset, &next_offset, &header_size, nullptr, nullptr, nullptr)) dwarf_nextcu(
dbg.get(), cu_offset, &next_offset, &header_size, nullptr, nullptr, nullptr) ==
0)
{ {
Dwarf_Die die; Dwarf_Die die;
if(!dwarf_offdie(dbg.get(), cu_offset + header_size, &die)) continue; if(!dwarf_offdie(dbg.get(), cu_offset + header_size, &die)) continue;
Dwarf_Lines* lines; Dwarf_Lines* lines;
size_t line_count; 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) for(size_t i = 0; i < line_count; ++i)
{ {
@@ -121,8 +123,8 @@ public:
int line_number; int line_number;
Dwarf_Line* line = dwarf_onesrcline(lines, i); Dwarf_Line* line = dwarf_onesrcline(lines, i);
if(line && !dwarf_lineaddr(line, &addr) && !dwarf_lineno(line, &line_number) && if(line && dwarf_lineaddr(line, &addr) == 0 &&
line_number) dwarf_lineno(line, &line_number) == 0 && line_number != 0)
{ {
std::string src = dwarf_linesrc(line, nullptr, nullptr); std::string src = dwarf_linesrc(line, nullptr, nullptr);
auto dwarf_line = src + ':' + std::to_string(line_number); auto dwarf_line = src + ':' + std::to_string(line_number);
@@ -162,9 +164,9 @@ public:
} catch(...) } catch(...)
{} {}
} }
~CodeobjDecoderComponent() {} ~CodeobjDecoderComponent() = default;
std::optional<uint64_t> va2fo(uint64_t vaddr) std::optional<uint64_t> va2fo(uint64_t vaddr) const
{ {
if(disassembly) return disassembly->va2fo(vaddr); if(disassembly) return disassembly->va2fo(vaddr);
return {}; return {};
@@ -342,21 +344,21 @@ public:
CodeobjAddressTranslate() = default; CodeobjAddressTranslate() = default;
~CodeobjAddressTranslate() override = default; ~CodeobjAddressTranslate() override = default;
virtual void addDecoder(const char* filepath, void addDecoder(const char* filepath,
marker_id_t id, marker_id_t id,
uint64_t load_addr, uint64_t load_addr,
uint64_t memsize) override uint64_t memsize) override
{ {
this->Super::addDecoder(filepath, id, load_addr, memsize); this->Super::addDecoder(filepath, id, load_addr, memsize);
auto ptr = decoders.at(id); auto ptr = decoders.at(id);
table.insert({ptr->begin(), ptr->size(), id}); table.insert({ptr->begin(), ptr->size(), id});
} }
virtual void addDecoder(const void* data, void addDecoder(const void* data,
size_t memory_size, size_t memory_size,
marker_id_t id, marker_id_t id,
uint64_t load_addr, uint64_t load_addr,
uint64_t memsize) override uint64_t memsize) override
{ {
this->Super::addDecoder(data, memory_size, id, load_addr, memsize); this->Super::addDecoder(data, memory_size, id, load_addr, memsize);
auto ptr = decoders.at(id); auto ptr = decoders.at(id);
@@ -396,7 +398,7 @@ public:
{ {
std::map<uint64_t, SymbolInfo> symbols; std::map<uint64_t, SymbolInfo> symbols;
for(auto& [_, dec] : decoders) for(const auto& [_, dec] : decoders)
{ {
auto& smap = dec->getSymbolMap(); auto& smap = dec->getSymbolMap();
for(auto& [vaddr, sym] : smap) for(auto& [vaddr, sym] : smap)
@@ -47,7 +47,7 @@
const char* reason = ""; \ const char* reason = ""; \
amd_comgr_status_string(status, &reason); \ amd_comgr_status_string(status, &reason); \
std::cerr << __FILE__ << ':' << __LINE__ << " code: " << status << " failed: " << reason \ std::cerr << __FILE__ << ':' << __LINE__ << " code: " << status << " failed: " << reason \
<< std::endl; \ << "\n"; \
throw std::exception(); \ throw std::exception(); \
} }
@@ -57,14 +57,14 @@
const char* reason = ""; \ const char* reason = ""; \
amd_comgr_status_string(status, &reason); \ amd_comgr_status_string(status, &reason); \
std::cerr << __FILE__ << ':' << __LINE__ << " code: " << status << " failed: " << reason \ std::cerr << __FILE__ << ':' << __LINE__ << " code: " << status << " failed: " << reason \
<< std::endl; \ << "\n"; \
return AMD_COMGR_STATUS_ERROR; \ return AMD_COMGR_STATUS_ERROR; \
} }
#define CHECK_VA2FO(x, msg) \ #define CHECK_VA2FO(x, msg) \
if(!(x)) \ if(!(x)) \
{ \ { \
std::cerr << __FILE__ << ' ' << __LINE__ << ' ' << msg << std::endl; \ std::cerr << __FILE__ << ' ' << __LINE__ << ' ' << msg << "\n"; \
return std::nullopt; \ return std::nullopt; \
} }
@@ -79,8 +79,8 @@ namespace disassembly
class CodeObjectBinary class CodeObjectBinary
{ {
public: public:
CodeObjectBinary(const std::string& _uri) CodeObjectBinary(std::string _uri)
: m_uri(_uri) : m_uri(std::move(_uri))
{ {
const std::string protocol_delim{"://"}; const std::string protocol_delim{"://"};
@@ -108,9 +108,9 @@ public:
decoded_path.reserve(path.length()); decoded_path.reserve(path.length());
for(size_t i = 0; i < path.length(); ++i) 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; i += 2;
} }
else else
@@ -153,7 +153,7 @@ public:
if(auto size_it = params.find("size"); size_it != params.end()) 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!"); 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); 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(!file || !file.is_open()) throw std::runtime_error("could not open " + decoded_path);
if(!size) if(size == 0)
{ {
file.ignore(std::numeric_limits<std::streamsize>::max()); file.ignore(std::numeric_limits<std::streamsize>::max());
size_t bytes = file.gcount(); size_t bytes = file.gcount();
@@ -174,7 +174,7 @@ public:
file.seekg(offset, std::ios_base::beg); file.seekg(offset, std::ios_base::beg);
buffer.resize(size); buffer.resize(size);
file.read(&buffer[0], size); file.read(buffer.data(), size);
} }
std::string m_uri; std::string m_uri;
@@ -269,6 +269,7 @@ public:
int64_t copysize = reinterpret_cast<int64_t>(instance.buffer.data()) + int64_t copysize = reinterpret_cast<int64_t>(instance.buffer.data()) +
instance.buffer.size() - static_cast<int64_t>(from); instance.buffer.size() - static_cast<int64_t>(from);
copysize = std::min<int64_t>(size, copysize); copysize = std::min<int64_t>(size, copysize);
// NOLINTNEXTLINE(performance-no-int-to-ptr)
std::memcpy(to, (char*) from, copysize); std::memcpy(to, (char*) from, copysize);
return copysize; return copysize;
} }