Skip to content

Commit

Permalink
Resolve or silence some warnings (#1905)
Browse files Browse the repository at this point in the history
* Resolve some warnings

- Their frequent appearance in the build logs is driving me nuts

* Silence warnings about `offsetof`

* Don't apply `-Wno-invalid-offset` to C, only to C++
  • Loading branch information
JesseTG authored Dec 28, 2023
1 parent 6d0de50 commit a4b2b0c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/ARMJIT_A64/ARMJIT_Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct Op2
bool IsSimpleReg()
{ return !IsImm && !Reg.ShiftAmount && Reg.ShiftType == Arm64Gen::ST_LSL; }
bool ImmFits12Bit()
{ return IsImm && (Imm & 0xFFF == Imm); }
{ return IsImm && ((Imm & 0xFFF) == Imm); }
bool IsZero()
{ return IsImm && !Imm; }

Expand Down
9 changes: 9 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ add_subdirectory(teakra EXCLUDE_FROM_ALL)
target_compile_options(teakra PRIVATE "$<$<CONFIG:DEBUG>:-Og>")
target_link_libraries(core PRIVATE teakra)

if (NOT MSVC)
# MSVC has its own compiler flag syntax; if we ever support it,
# be sure to silence any equivalent warnings there.

target_compile_options(core PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:-Wno-invalid-offsetof>")
# These warnings are excessive, and are only triggered in the ARMJIT code
# (which is fundamentally non-portable, so this is fine)
endif()

find_library(m MATH_LIBRARY)

if (MATH_LIBRARY)
Expand Down
2 changes: 1 addition & 1 deletion src/GPU3D_OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace melonDS
bool GLRenderer::BuildRenderShader(u32 flags, const char* vs, const char* fs)
{
char shadername[32];
sprintf(shadername, "RenderShader%02X", flags);
snprintf(shadername, sizeof(shadername), "RenderShader%02X", flags);

int headerlen = strlen(kShaderHeader);

Expand Down
4 changes: 2 additions & 2 deletions src/GPU3D_Soft.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class SoftRenderer : public Renderer3D
{
// Z-buffering: linear interpolation
// still doesn't quite match hardware...
s32 base, disp, factor;
s32 base = 0, disp = 0, factor = 0;

if (z0 < z1)
{
Expand Down Expand Up @@ -337,7 +337,7 @@ class SoftRenderer : public Renderer3D

constexpr s32 XVal() const
{
s32 ret;
s32 ret = 0;
if (Negative) ret = x0 - (dx >> 18);
else ret = x0 + (dx >> 18);

Expand Down
50 changes: 25 additions & 25 deletions src/NDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,40 +1497,40 @@ void NDS::NocashPrint(u32 ncpu, u32 addr)

if (cmd[0] == 'r')
{
if (!strcmp(cmd, "r0")) sprintf(subs, "%08X", cpu->R[0]);
else if (!strcmp(cmd, "r1")) sprintf(subs, "%08X", cpu->R[1]);
else if (!strcmp(cmd, "r2")) sprintf(subs, "%08X", cpu->R[2]);
else if (!strcmp(cmd, "r3")) sprintf(subs, "%08X", cpu->R[3]);
else if (!strcmp(cmd, "r4")) sprintf(subs, "%08X", cpu->R[4]);
else if (!strcmp(cmd, "r5")) sprintf(subs, "%08X", cpu->R[5]);
else if (!strcmp(cmd, "r6")) sprintf(subs, "%08X", cpu->R[6]);
else if (!strcmp(cmd, "r7")) sprintf(subs, "%08X", cpu->R[7]);
else if (!strcmp(cmd, "r8")) sprintf(subs, "%08X", cpu->R[8]);
else if (!strcmp(cmd, "r9")) sprintf(subs, "%08X", cpu->R[9]);
else if (!strcmp(cmd, "r10")) sprintf(subs, "%08X", cpu->R[10]);
else if (!strcmp(cmd, "r11")) sprintf(subs, "%08X", cpu->R[11]);
else if (!strcmp(cmd, "r12")) sprintf(subs, "%08X", cpu->R[12]);
else if (!strcmp(cmd, "r13")) sprintf(subs, "%08X", cpu->R[13]);
else if (!strcmp(cmd, "r14")) sprintf(subs, "%08X", cpu->R[14]);
else if (!strcmp(cmd, "r15")) sprintf(subs, "%08X", cpu->R[15]);
if (!strcmp(cmd, "r0")) snprintf(subs, sizeof(subs), "%08X", cpu->R[0]);
else if (!strcmp(cmd, "r1")) snprintf(subs, sizeof(subs), "%08X", cpu->R[1]);
else if (!strcmp(cmd, "r2")) snprintf(subs, sizeof(subs), "%08X", cpu->R[2]);
else if (!strcmp(cmd, "r3")) snprintf(subs, sizeof(subs), "%08X", cpu->R[3]);
else if (!strcmp(cmd, "r4")) snprintf(subs, sizeof(subs), "%08X", cpu->R[4]);
else if (!strcmp(cmd, "r5")) snprintf(subs, sizeof(subs), "%08X", cpu->R[5]);
else if (!strcmp(cmd, "r6")) snprintf(subs, sizeof(subs), "%08X", cpu->R[6]);
else if (!strcmp(cmd, "r7")) snprintf(subs, sizeof(subs), "%08X", cpu->R[7]);
else if (!strcmp(cmd, "r8")) snprintf(subs, sizeof(subs), "%08X", cpu->R[8]);
else if (!strcmp(cmd, "r9")) snprintf(subs, sizeof(subs), "%08X", cpu->R[9]);
else if (!strcmp(cmd, "r10")) snprintf(subs, sizeof(subs), "%08X", cpu->R[10]);
else if (!strcmp(cmd, "r11")) snprintf(subs, sizeof(subs), "%08X", cpu->R[11]);
else if (!strcmp(cmd, "r12")) snprintf(subs, sizeof(subs), "%08X", cpu->R[12]);
else if (!strcmp(cmd, "r13")) snprintf(subs, sizeof(subs), "%08X", cpu->R[13]);
else if (!strcmp(cmd, "r14")) snprintf(subs, sizeof(subs), "%08X", cpu->R[14]);
else if (!strcmp(cmd, "r15")) snprintf(subs, sizeof(subs), "%08X", cpu->R[15]);
}
else
{
if (!strcmp(cmd, "sp")) sprintf(subs, "%08X", cpu->R[13]);
else if (!strcmp(cmd, "lr")) sprintf(subs, "%08X", cpu->R[14]);
else if (!strcmp(cmd, "pc")) sprintf(subs, "%08X", cpu->R[15]);
else if (!strcmp(cmd, "frame")) sprintf(subs, "%u", NumFrames);
else if (!strcmp(cmd, "scanline")) sprintf(subs, "%u", GPU.VCount);
else if (!strcmp(cmd, "totalclks")) sprintf(subs, "%" PRIu64, GetSysClockCycles(0));
else if (!strcmp(cmd, "lastclks")) sprintf(subs, "%" PRIu64, GetSysClockCycles(1));
if (!strcmp(cmd, "sp")) snprintf(subs, sizeof(subs), "%08X", cpu->R[13]);
else if (!strcmp(cmd, "lr")) snprintf(subs, sizeof(subs), "%08X", cpu->R[14]);
else if (!strcmp(cmd, "pc")) snprintf(subs, sizeof(subs), "%08X", cpu->R[15]);
else if (!strcmp(cmd, "frame")) snprintf(subs, sizeof(subs), "%u", NumFrames);
else if (!strcmp(cmd, "scanline")) snprintf(subs, sizeof(subs), "%u", GPU.VCount);
else if (!strcmp(cmd, "totalclks")) snprintf(subs, sizeof(subs), "%" PRIu64, GetSysClockCycles(0));
else if (!strcmp(cmd, "lastclks")) snprintf(subs, sizeof(subs), "%" PRIu64, GetSysClockCycles(1));
else if (!strcmp(cmd, "zeroclks"))
{
sprintf(subs, "%s", "");
snprintf(subs, sizeof(subs), "%s", "");
GetSysClockCycles(1);
}
}

int slen = strlen(subs);
int slen = strnlen(subs, sizeof(subs));
if ((ptr+slen) > 1023) slen = 1023-ptr;
strncpy(&output[ptr], subs, slen);
ptr += slen;
Expand Down
2 changes: 2 additions & 0 deletions src/SPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ s32 SPUChannel::Run()
(PrevSample[0] * InterpCubic[samplepos][2]) +
(val * InterpCubic[samplepos][3])) >> 14;
break;
default:
break;
}
}

Expand Down

0 comments on commit a4b2b0c

Please sign in to comment.