Fixing most remaining C++ warnings in clang.

This commit is contained in:
Ben Vanik 2016-01-01 18:37:33 +00:00
parent e029c9abdc
commit b02ca62388
11 changed files with 53 additions and 40 deletions

View File

@ -7,17 +7,13 @@ project("xenia-debug-ui")
kind("StaticLib") kind("StaticLib")
language("C++") language("C++")
links({ links({
"glew",
"imgui", "imgui",
"xenia-base", "xenia-base",
"xenia-cpu", "xenia-cpu",
"xenia-debug", "xenia-debug",
"xenia-ui", "xenia-ui",
"xenia-ui-gl",
}) })
defines({ defines({
"GLEW_STATIC=1",
"GLEW_MX=1",
}) })
includedirs({ includedirs({
project_root.."/third_party/gflags/src", project_root.."/third_party/gflags/src",

View File

@ -16,6 +16,7 @@
#include <string> #include <string>
#include "xenia/base/byte_order.h" #include "xenia/base/byte_order.h"
#include "xenia/base/logging.h"
#include "xenia/base/memory.h" #include "xenia/base/memory.h"
#include "xenia/base/string_buffer.h" #include "xenia/base/string_buffer.h"
#include "xenia/cpu/export_resolver.h" #include "xenia/cpu/export_resolver.h"
@ -29,7 +30,7 @@ namespace kernel {
using PPCContext = xe::cpu::ppc::PPCContext; using PPCContext = xe::cpu::ppc::PPCContext;
#define SHIM_CALL void _cdecl #define SHIM_CALL void __cdecl
#define SHIM_SET_MAPPING(library_name, export_name, shim_data) \ #define SHIM_SET_MAPPING(library_name, export_name, shim_data) \
export_resolver->SetFunctionMapping( \ export_resolver->SetFunctionMapping( \
library_name, ordinals::export_name, \ library_name, ordinals::export_name, \
@ -403,7 +404,7 @@ void PrintKernelCall(cpu::Export* export_entry, const Tuple& params) {
string_buffer.Append('('); string_buffer.Append('(');
AppendKernelCallParams(string_buffer, export_entry, params); AppendKernelCallParams(string_buffer, export_entry, params);
string_buffer.Append(')'); string_buffer.Append(')');
if (export_entry->tags & ExportTag::kImportant) { if (export_entry->tags & xe::cpu::ExportTag::kImportant) {
xe::LogLine('i', string_buffer.GetString(), string_buffer.length()); xe::LogLine('i', string_buffer.GetString(), string_buffer.length());
} else { } else {
xe::LogLine('d', string_buffer.GetString(), string_buffer.length()); xe::LogLine('d', string_buffer.GetString(), string_buffer.length());
@ -418,9 +419,9 @@ auto KernelTrampoline(F&& f, Tuple&& t, std::index_sequence<I...>) {
template <KernelModuleId MODULE, uint16_t ORDINAL, typename R, typename... Ps> template <KernelModuleId MODULE, uint16_t ORDINAL, typename R, typename... Ps>
xe::cpu::Export* RegisterExport(R (*fn)(Ps&...), const char* name, xe::cpu::Export* RegisterExport(R (*fn)(Ps&...), const char* name,
xe::cpu::ExportTag::type tags) { xe::cpu::ExportTag::type tags) {
static const auto export_entry = static const auto export_entry = new cpu::Export(
new cpu::Export(ORDINAL, xe::cpu::Export::Type::kFunction, name, ORDINAL, xe::cpu::Export::Type::kFunction, name,
tags | ExportTag::kImplemented | ExportTag::kLog); tags | xe::cpu::ExportTag::kImplemented | xe::cpu::ExportTag::kLog);
static R (*FN)(Ps&...) = fn; static R (*FN)(Ps&...) = fn;
struct X { struct X {
static void Trampoline(PPCContext* ppc_context) { static void Trampoline(PPCContext* ppc_context) {
@ -429,8 +430,8 @@ xe::cpu::Export* RegisterExport(R (*fn)(Ps&...), const char* name,
ppc_context, sizeof...(Ps), 0, ppc_context, sizeof...(Ps), 0,
}; };
auto params = std::make_tuple<Ps...>(Ps(init)...); auto params = std::make_tuple<Ps...>(Ps(init)...);
if (export_entry->tags & ExportTag::kLog && if (export_entry->tags & xe::cpu::ExportTag::kLog &&
(!(export_entry->tags & ExportTag::kHighFrequency) || (!(export_entry->tags & xe::cpu::ExportTag::kHighFrequency) ||
FLAGS_log_high_frequency_kernel_calls)) { FLAGS_log_high_frequency_kernel_calls)) {
PrintKernelCall(export_entry, params); PrintKernelCall(export_entry, params);
} }
@ -438,7 +439,8 @@ xe::cpu::Export* RegisterExport(R (*fn)(Ps&...), const char* name,
KernelTrampoline(FN, std::forward<std::tuple<Ps...>>(params), KernelTrampoline(FN, std::forward<std::tuple<Ps...>>(params),
std::make_index_sequence<sizeof...(Ps)>()); std::make_index_sequence<sizeof...(Ps)>());
result.Store(ppc_context); result.Store(ppc_context);
if (export_entry->tags & (ExportTag::kLog | ExportTag::kLogResult)) { if (export_entry->tags &
(xe::cpu::ExportTag::kLog | xe::cpu::ExportTag::kLogResult)) {
// TODO(benvanik): log result. // TODO(benvanik): log result.
} }
} }
@ -450,9 +452,9 @@ xe::cpu::Export* RegisterExport(R (*fn)(Ps&...), const char* name,
template <KernelModuleId MODULE, uint16_t ORDINAL, typename... Ps> template <KernelModuleId MODULE, uint16_t ORDINAL, typename... Ps>
xe::cpu::Export* RegisterExport(void (*fn)(Ps&...), const char* name, xe::cpu::Export* RegisterExport(void (*fn)(Ps&...), const char* name,
xe::cpu::ExportTag::type tags) { xe::cpu::ExportTag::type tags) {
static const auto export_entry = static const auto export_entry = new cpu::Export(
new cpu::Export(ORDINAL, xe::cpu::Export::Type::kFunction, name, ORDINAL, xe::cpu::Export::Type::kFunction, name,
tags | ExportTag::kImplemented | ExportTag::kLog); tags | xe::cpu::ExportTag::kImplemented | xe::cpu::ExportTag::kLog);
static void (*FN)(Ps&...) = fn; static void (*FN)(Ps&...) = fn;
struct X { struct X {
static void Trampoline(PPCContext* ppc_context) { static void Trampoline(PPCContext* ppc_context) {
@ -461,8 +463,8 @@ xe::cpu::Export* RegisterExport(void (*fn)(Ps&...), const char* name,
ppc_context, sizeof...(Ps), ppc_context, sizeof...(Ps),
}; };
auto params = std::make_tuple<Ps...>(Ps(init)...); auto params = std::make_tuple<Ps...>(Ps(init)...);
if (export_entry->tags & ExportTag::kLog && if (export_entry->tags & xe::cpu::ExportTag::kLog &&
(!(export_entry->tags & ExportTag::kHighFrequency) || (!(export_entry->tags & xe::cpu::ExportTag::kHighFrequency) ||
FLAGS_log_high_frequency_kernel_calls)) { FLAGS_log_high_frequency_kernel_calls)) {
PrintKernelCall(export_entry, params); PrintKernelCall(export_entry, params);
} }

View File

@ -869,9 +869,17 @@ int xe_xex2_load_pe(xe_xex2_ref xex) {
// IAT Import Address Table ptr // IAT Import Address Table ptr
// opthdr->DataDirectory[IMAGE_DIRECTORY_ENTRY_X].VirtualAddress / .Size // opthdr->DataDirectory[IMAGE_DIRECTORY_ENTRY_X].VirtualAddress / .Size
// The macros in pe_image.h don't work with clang, for some reason.
// offsetof seems to be unable to find OptionalHeader.
#define offsetof1(type, member) ((std::size_t) & (((type*)0)->member))
#define IMAGE_FIRST_SECTION1(ntheader) \
((PIMAGE_SECTION_HEADER)( \
(uint8_t*)ntheader + offsetof1(IMAGE_NT_HEADERS, OptionalHeader) + \
((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader))
// Quick scan to determine bounds of sections. // Quick scan to determine bounds of sections.
size_t upper_address = 0; size_t upper_address = 0;
const IMAGE_SECTION_HEADER* sechdr = IMAGE_FIRST_SECTION(nthdr); const IMAGE_SECTION_HEADER* sechdr = IMAGE_FIRST_SECTION1(nthdr);
for (size_t n = 0; n < filehdr->NumberOfSections; n++, sechdr++) { for (size_t n = 0; n < filehdr->NumberOfSections; n++, sechdr++) {
const size_t physical_address = opthdr->ImageBase + sechdr->VirtualAddress; const size_t physical_address = opthdr->ImageBase + sechdr->VirtualAddress;
upper_address = upper_address =
@ -879,7 +887,7 @@ int xe_xex2_load_pe(xe_xex2_ref xex) {
} }
// Setup/load sections. // Setup/load sections.
sechdr = IMAGE_FIRST_SECTION(nthdr); sechdr = IMAGE_FIRST_SECTION1(nthdr);
for (size_t n = 0; n < filehdr->NumberOfSections; n++, sechdr++) { for (size_t n = 0; n < filehdr->NumberOfSections; n++, sechdr++) {
PESection* section = (PESection*)calloc(1, sizeof(PESection)); PESection* section = (PESection*)calloc(1, sizeof(PESection));
memcpy(section->name, sechdr->Name, sizeof(sechdr->Name)); memcpy(section->name, sechdr->Name, sizeof(sechdr->Name));

View File

@ -182,7 +182,9 @@ dword_result_t XamContentCreateEnumerator(dword_t user_index, dword_t device_id,
// Get all content data. // Get all content data.
auto content_datas = kernel_state()->content_manager()->ListContent( auto content_datas = kernel_state()->content_manager()->ListContent(
device_id ? device_id : dummy_device_info_.device_id, content_type); device_id ? static_cast<uint32_t>(device_id)
: dummy_device_info_.device_id,
content_type);
for (auto& content_data : content_datas) { for (auto& content_data : content_datas) {
auto ptr = e->AppendItem(); auto ptr = e->AppendItem();
if (!ptr) { if (!ptr) {

View File

@ -21,7 +21,7 @@ namespace xe {
namespace kernel { namespace kernel {
namespace xam { namespace xam {
std::atomic<int> xam_dialogs_shown_ = 0; std::atomic<int> xam_dialogs_shown_ = {0};
SHIM_CALL XamIsUIActive_shim(PPCContext* ppc_context, SHIM_CALL XamIsUIActive_shim(PPCContext* ppc_context,
KernelState* kernel_state) { KernelState* kernel_state) {
@ -54,7 +54,7 @@ class MessageBoxDialog : public xe::ui::ImGuiDialog {
} }
if (ImGui::BeginPopupModal(title_.c_str(), nullptr, if (ImGui::BeginPopupModal(title_.c_str(), nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) { ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text(description_.c_str()); ImGui::Text("%s", description_.c_str());
if (first_draw) { if (first_draw) {
ImGui::SetKeyboardFocusHere(); ImGui::SetKeyboardFocusHere();
} }
@ -185,7 +185,7 @@ class KeyboardInputDialog : public xe::ui::ImGuiDialog {
} }
if (ImGui::BeginPopupModal(title_.c_str(), nullptr, if (ImGui::BeginPopupModal(title_.c_str(), nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) { ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::TextWrapped(description_.c_str()); ImGui::TextWrapped("%s", description_.c_str());
if (first_draw) { if (first_draw) {
ImGui::SetKeyboardFocusHere(); ImGui::SetKeyboardFocusHere();
} }

View File

@ -196,9 +196,10 @@ dword_result_t NtReadFile(dword_t file_handle, dword_t event_handle,
if (true || file->is_synchronous()) { if (true || file->is_synchronous()) {
// Synchronous. // Synchronous.
size_t bytes_read = 0; size_t bytes_read = 0;
result = file->Read(buffer, buffer_length, result = file->Read(
byte_offset_ptr ? *byte_offset_ptr : -1, &bytes_read, buffer, buffer_length,
apc_context); byte_offset_ptr ? static_cast<uint32_t>(*byte_offset_ptr) : -1u,
&bytes_read, apc_context);
if (io_status_block) { if (io_status_block) {
io_status_block->status = result; io_status_block->status = result;
io_status_block->information = static_cast<uint32_t>(bytes_read); io_status_block->information = static_cast<uint32_t>(bytes_read);
@ -210,8 +211,8 @@ dword_result_t NtReadFile(dword_t file_handle, dword_t event_handle,
if ((uint32_t)apc_routine_ptr & ~1) { if ((uint32_t)apc_routine_ptr & ~1) {
if (apc_context) { if (apc_context) {
auto thread = XThread::GetCurrentThread(); auto thread = XThread::GetCurrentThread();
thread->EnqueueApc((uint32_t)apc_routine_ptr & ~1, apc_context, thread->EnqueueApc(static_cast<uint32_t>(apc_routine_ptr) & ~1u,
io_status_block, 0); apc_context, io_status_block, 0);
} }
} }
@ -286,9 +287,10 @@ dword_result_t NtWriteFile(dword_t file_handle, dword_t event_handle,
if (true || file->is_synchronous()) { if (true || file->is_synchronous()) {
// Synchronous request. // Synchronous request.
size_t bytes_written = 0; size_t bytes_written = 0;
result = file->Write(buffer, buffer_length, result = file->Write(
byte_offset_ptr ? *byte_offset_ptr : -1, buffer, buffer_length,
&bytes_written, apc_context); byte_offset_ptr ? static_cast<uint32_t>(*byte_offset_ptr) : -1u,
&bytes_written, apc_context);
if (XSUCCEEDED(result)) { if (XSUCCEEDED(result)) {
info = (int32_t)bytes_written; info = (int32_t)bytes_written;
} }
@ -356,7 +358,7 @@ dword_result_t NtRemoveIoCompletion(
status = X_STATUS_INVALID_HANDLE; status = X_STATUS_INVALID_HANDLE;
} }
uint64_t timeout_ticks = timeout ? *timeout : 0; uint64_t timeout_ticks = timeout ? static_cast<uint32_t>(*timeout) : 0u;
if (port->WaitForNotification(timeout_ticks)) { if (port->WaitForNotification(timeout_ticks)) {
auto notification = port->DequeueNotification(); auto notification = port->DequeueNotification();
if (key_context) { if (key_context) {

View File

@ -323,7 +323,8 @@ SHIM_CALL XexGetProcedureAddress_shim(PPCContext* ppc_context,
void AppendParam(StringBuffer* string_buffer, void AppendParam(StringBuffer* string_buffer,
pointer_t<X_EX_TITLE_TERMINATE_REGISTRATION> reg) { pointer_t<X_EX_TITLE_TERMINATE_REGISTRATION> reg) {
string_buffer->AppendFormat("%.8X(%.8X, %.8X)", reg.guest_address(), string_buffer->AppendFormat("%.8X(%.8X, %.8X)", reg.guest_address(),
reg->notification_routine, reg->priority); static_cast<uint32_t>(reg->notification_routine),
static_cast<uint32_t>(reg->priority));
} }
void ExRegisterTitleTerminateNotification( void ExRegisterTitleTerminateNotification(

View File

@ -832,7 +832,7 @@ dword_result_t KeWaitForSingleObject(lpvoid_t object_ptr, dword_t wait_reason,
return X_STATUS_ABANDONED_WAIT_0; return X_STATUS_ABANDONED_WAIT_0;
} }
uint64_t timeout = timeout_ptr ? *timeout_ptr : 0; uint64_t timeout = timeout_ptr ? static_cast<uint32_t>(*timeout_ptr) : 0u;
X_STATUS result = object->Wait(wait_reason, processor_mode, alertable, X_STATUS result = object->Wait(wait_reason, processor_mode, alertable,
timeout_ptr ? &timeout : nullptr); timeout_ptr ? &timeout : nullptr);
@ -850,7 +850,7 @@ dword_result_t NtWaitForSingleObjectEx(dword_t object_handle, dword_t wait_mode,
auto object = auto object =
kernel_state()->object_table()->LookupObject<XObject>(object_handle); kernel_state()->object_table()->LookupObject<XObject>(object_handle);
if (object) { if (object) {
uint64_t timeout = timeout_ptr ? *timeout_ptr : 0; uint64_t timeout = timeout_ptr ? static_cast<uint32_t>(*timeout_ptr) : 0u;
result = result =
object->Wait(3, wait_mode, alertable, timeout_ptr ? &timeout : nullptr); object->Wait(3, wait_mode, alertable, timeout_ptr ? &timeout : nullptr);
} else { } else {
@ -885,7 +885,7 @@ dword_result_t KeWaitForMultipleObjects(dword_t count, lpdword_t objects_ptr,
objects.push_back(std::move(object_ref)); objects.push_back(std::move(object_ref));
} }
uint64_t timeout = timeout_ptr ? *timeout_ptr : 0; uint64_t timeout = timeout_ptr ? static_cast<uint32_t>(*timeout_ptr) : 0u;
result = XObject::WaitMultiple(uint32_t(objects.size()), result = XObject::WaitMultiple(uint32_t(objects.size()),
reinterpret_cast<XObject**>(objects.data()), reinterpret_cast<XObject**>(objects.data()),
wait_type, wait_reason, processor_mode, wait_type, wait_reason, processor_mode,
@ -937,7 +937,7 @@ dword_result_t NtSignalAndWaitForSingleObjectEx(dword_t signal_handle,
auto wait_object = auto wait_object =
kernel_state()->object_table()->LookupObject<XObject>(wait_handle); kernel_state()->object_table()->LookupObject<XObject>(wait_handle);
if (signal_object && wait_object) { if (signal_object && wait_object) {
uint64_t timeout = timeout_ptr ? *timeout_ptr : 0; uint64_t timeout = timeout_ptr ? static_cast<uint32_t>(*timeout_ptr) : 0u;
result = result =
XObject::SignalAndWait(signal_object.get(), wait_object.get(), 3, 1, XObject::SignalAndWait(signal_object.get(), wait_object.get(), 3, 1,
alertable, timeout_ptr ? &timeout : nullptr); alertable, timeout_ptr ? &timeout : nullptr);

View File

@ -64,7 +64,7 @@ class XStaticEnumerator : public XEnumerator {
std::memcpy(buffer, buffer_.data(), item_count_ * item_size_); std::memcpy(buffer, buffer_.data(), item_count_ * item_size_);
} }
bool WriteItem(uint8_t* buffer) { bool WriteItem(uint8_t* buffer) override {
if (current_item_ >= item_count_) { if (current_item_ >= item_count_) {
return false; return false;
} }

View File

@ -150,6 +150,8 @@ object_ref<XObject> XObject::Restore(KernelState* kernel_state, Type type,
return XThread::Restore(kernel_state, stream); return XThread::Restore(kernel_state, stream);
case kTypeTimer: case kTypeTimer:
break; break;
case kTypeUndefined:
break;
} }
assert_always("No restore handler exists for this object!"); assert_always("No restore handler exists for this object!");

View File

@ -1145,12 +1145,12 @@ object_ref<XThread> XThread::Restore(KernelState* kernel_state,
thread->kernel_state_ = kernel_state; thread->kernel_state_ = kernel_state;
if (!thread->RestoreObject(stream)) { if (!thread->RestoreObject(stream)) {
return false; return nullptr;
} }
if (stream->Read<uint32_t>() != 'THRD') { if (stream->Read<uint32_t>() != 'THRD') {
XELOGE("Could not restore XThread - invalid magic!"); XELOGE("Could not restore XThread - invalid magic!");
return false; return nullptr;
} }
XELOGD("XThread %.8X", thread->handle()); XELOGD("XThread %.8X", thread->handle());