Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unused variable/parameter cleanup #1321

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,14 @@ N64_EMULATOR ?=
INC := -Iinclude -Iinclude/libc -Isrc -I$(BUILD_DIR) -I. -I$(EXTRACTED_DIR)

# Check code syntax with host compiler
CHECK_WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-variable -Wno-missing-braces
CHECK_WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unknown-pragmas -Wno-missing-braces
CHECK_WARNINGS += -Werror=implicit-int -Werror=implicit-function-declaration -Werror=int-conversion -Werror=incompatible-pointer-types

# Actors and effets are mostly callback functions and often don't use all arguments,
# ignore those warnings entirely in these directories.
$(BUILD_DIR)/src/overlays/actors/%.o: CHECK_WARNINGS += -Wno-unused-parameter
$(BUILD_DIR)/src/overlays/effects/%.o: CHECK_WARNINGS += -Wno-unused-parameter

# The `cpp` command behaves differently on macOS (it behaves as if
# `-traditional-cpp` was passed) so we use `gcc -E` instead.
CPP := gcc -E
Expand Down
9 changes: 8 additions & 1 deletion include/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
#define __attribute__(x)
#endif

#define UNUSED __attribute__((unused))
#define FALLTHROUGH __attribute__((fallthrough))
#define NORETURN __attribute__((noreturn))

#define UNUSED __attribute__((unused))
// Unused in non-debug versions only
#if OOT_DEBUG
#define UNUSED_NDEBUG
#else
#define UNUSED_NDEBUG __attribute__((unused))
#endif

#endif
12 changes: 6 additions & 6 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ u8 Actor_ApplyDamage(Actor* actor);
void Actor_SetDropFlag(Actor* actor, ColliderElement* elem, s32 freezeFlag);
void Actor_SetDropFlagJntSph(Actor* actor, ColliderJntSph* jntSph, s32 freezeFlag);
void func_80035844(Vec3f* arg0, Vec3f* arg1, Vec3s* arg2, s32 arg3);
Actor* func_800358DC(Actor* actor, Vec3f* spawnPos, Vec3s* spawnRot, f32* arg3, s32 timer, s16* unused,
Actor* func_800358DC(Actor* actor, Vec3f* spawnPos, Vec3s* spawnRot, f32* arg3, s32 timer, s16* arg5,
PlayState* play, s16 params, Gfx* dList);
void func_800359B8(Actor* actor, s16 arg1, Vec3s* arg2);
s32 Flags_GetEventChkInf(s32 flag);
Expand Down Expand Up @@ -783,7 +783,7 @@ void Font_LoadOrderedFont(Font* font);
s32 Environment_ZBufValToFixedPoint(s32 zBufferVal);
u16 Environment_GetPixelDepth(s32 x, s32 y);
void Environment_GraphCallback(GraphicsContext* gfxCtx, void* param);
void Environment_Init(PlayState* play2, EnvironmentContext* envCtx, s32 unused);
void Environment_Init(PlayState* play2, EnvironmentContext* envCtx, s32 arg2);
u8 Environment_SmoothStepToU8(u8* pvalue, u8 target, u8 scale, u8 step, u8 minStep);
u8 Environment_SmoothStepToS8(s8* pvalue, s8 target, u8 scale, u8 step, u8 minStep);
f32 Environment_LerpWeight(u16 max, u16 min, u16 val);
Expand All @@ -795,15 +795,15 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex
GraphicsContext* gfxCtx);
void Environment_DrawSunAndMoon(PlayState* play);
void Environment_DrawSunLensFlare(PlayState* play, EnvironmentContext* envCtx, View* view,
GraphicsContext* gfxCtx, Vec3f pos, s32 unused);
GraphicsContext* gfxCtx, Vec3f pos, s32 arg5);
void Environment_DrawLensFlare(PlayState* play, EnvironmentContext* envCtx, View* view,
GraphicsContext* gfxCtx, Vec3f pos, s32 unused, s16 scale, f32 colorIntensity,
GraphicsContext* gfxCtx, Vec3f pos, s32 arg5, s16 scale, f32 colorIntensity,
s16 glareStrength, u8 isSun);
void Environment_DrawRain(PlayState* play, View* view, GraphicsContext* gfxCtx);
void Environment_ChangeLightSetting(PlayState* play, u32 lightSetting);
void Environment_UpdateLightningStrike(PlayState* play);
void Environment_AddLightningBolts(PlayState* play, u8 num);
void Environment_DrawLightning(PlayState* play, s32 unused);
void Environment_DrawLightning(PlayState* play, s32 arg1);
void Environment_PlaySceneSequence(PlayState* play);
void Environment_DrawCustomLensFlare(PlayState* play);
void Environment_InitGameOverLights(PlayState* play);
Expand Down Expand Up @@ -1243,7 +1243,7 @@ void Graph_Init(GraphicsContext* gfxCtx);
void Graph_Destroy(GraphicsContext* gfxCtx);
void Graph_TaskSet00(GraphicsContext* gfxCtx);
void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState);
void Graph_ThreadEntry(void*);
void Graph_ThreadEntry(void* arg);
void* Graph_Alloc(GraphicsContext* gfxCtx, size_t size);
void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size);
#if OOT_DEBUG
Expand Down
37 changes: 25 additions & 12 deletions include/macros.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
#ifndef MACROS_H
#define MACROS_H

#ifndef GLUE
#define GLUE(a,b) a##b
#endif
#ifndef GLUE2
#define GLUE2(a,b) GLUE(a,b)
#endif

#ifndef AVOID_UB
#define BAD_RETURN(type) type
#else
#define BAD_RETURN(type) void
#endif

#ifndef NON_MATCHING
#define STACK_PAD(type) UNUSED type GLUE2(__stack_pad_, __LINE__)
#define STACK_PADS(type, n) STACK_PAD(type) [(n)]
#else
#define STACK_PAD(type)
#define STACK_PADS(type, n)
#endif

#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
#define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0]))

Expand Down Expand Up @@ -158,8 +173,6 @@

struct GraphicsContext;

extern struct GraphicsContext* __gfxCtx;

#define WORK_DISP __gfxCtx->work.p
#define POLY_OPA_DISP __gfxCtx->polyOpa.p
#define POLY_XLU_DISP __gfxCtx->polyXlu.p
Expand All @@ -169,12 +182,12 @@ extern struct GraphicsContext* __gfxCtx;

// __gfxCtx shouldn't be used directly.
// Use the DISP macros defined above when writing to display buffers.
#define OPEN_DISPS(gfxCtx, file, line) \
{ \
GraphicsContext* __gfxCtx; \
Gfx* dispRefs[4]; \
__gfxCtx = gfxCtx; \
(void)__gfxCtx; \
#define OPEN_DISPS(gfxCtx, file, line) \
{ \
struct GraphicsContext* __gfxCtx; \
Gfx* dispRefs[4]; \
__gfxCtx = gfxCtx; \
(void)__gfxCtx; \
Graph_OpenDisps(dispRefs, gfxCtx, file, line)

#define CLOSE_DISPS(gfxCtx, file, line) \
Expand Down Expand Up @@ -205,10 +218,10 @@ extern struct GraphicsContext* __gfxCtx;

#else

#define OPEN_DISPS(gfxCtx, file, line) \
{ \
GraphicsContext* __gfxCtx = gfxCtx; \
s32 __dispPad
#define OPEN_DISPS(gfxCtx, file, line) \
{ \
UNUSED GraphicsContext* __gfxCtx = gfxCtx; \
UNUSED s32 __dispPad

#define CLOSE_DISPS(gfxCtx, file, line) \
(void)0; \
Expand Down
2 changes: 1 addition & 1 deletion src/audio/debug.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ char* AudioDebug_ToStringBinary(u32 num, u8 bits) {
}

void AudioDebug_Draw(GfxPrint* printer) {
s32 pad[3];
STACK_PADS(s32, 3);
u8 i;
u8 j;
u8 ctr;
Expand Down
29 changes: 14 additions & 15 deletions src/audio/general.c
Original file line number Diff line number Diff line change
Expand Up @@ -1494,9 +1494,9 @@ void AudioOcarina_CheckIfStartedSong(void) {
*/
void AudioOcarina_CheckSongsWithMusicStaff(void) {
u16 curOcarinaSongFlag;
u16 pad;
STACK_PAD(s16);
u8 noNewValidInput = false;
u16 pad2;
STACK_PAD(s16);
s8 staffOcarinaPlayingPosOffset = 0;
u8 songIndex;
OcarinaNote* curNote;
Expand Down Expand Up @@ -1669,7 +1669,7 @@ void AudioOcarina_CheckSongsWithoutMusicStaff(void) {
}

// This unused argument is used in Majora's Mask as a u8
void AudioOcarina_PlayControllerInput(u8 unused) {
void AudioOcarina_PlayControllerInput(UNUSED u8 arg0) {
u32 ocarinaBtnsHeld;

// Prevents two different ocarina notes from being played on two consecutive frames
Expand Down Expand Up @@ -1939,13 +1939,12 @@ void AudioOcarina_PlaybackSong(void) {

void AudioOcarina_SetRecordingSong(u8 isRecordingComplete) {
u16 i;
u16 i2;
u16 pad;
STACK_PADS(s16, 2);
u8 pitch;
OcarinaNote* note;
STACK_PAD(s32);
u8 j;
u8 k;
s32 t;
STACK_PAD(s32);
OcarinaNote* recordedSong;

if (sRecordingState == OCARINA_RECORD_SCARECROW_LONG) {
Expand Down Expand Up @@ -2321,10 +2320,10 @@ void AudioOcarina_ResetStaffs(void) {
#if OOT_DEBUG
#include "debug.inc.c"
#else
void AudioDebug_Draw(GfxPrint* printer) {
void AudioDebug_Draw(UNUSED GfxPrint* printer) {
}

void AudioDebug_ScrPrt(const char* str, u16 num) {
void AudioDebug_ScrPrt(UNUSED const char* str, UNUSED u16 num) {
}
#endif

Expand Down Expand Up @@ -2369,10 +2368,10 @@ void Audio_Update(void) {
}
}

void func_800F3138(UNK_TYPE arg0) {
void func_800F3138(UNUSED UNK_TYPE arg0) {
}

void func_800F3140(UNK_TYPE arg0, UNK_TYPE arg1) {
void func_800F3140(UNUSED UNK_TYPE arg0, UNUSED UNK_TYPE arg1) {
}

void func_800F314C(s8 seqId) {
Expand Down Expand Up @@ -2457,7 +2456,7 @@ s8 Audio_ComputeSfxReverb(u8 bankId, u8 entryIdx, u8 channelIdx) {
return reverb;
}

s8 Audio_ComputeSfxPanSigned(f32 x, f32 z, u8 token) {
s8 Audio_ComputeSfxPanSigned(f32 x, f32 z, UNUSED u8 token) {
f32 absX;
f32 absZ;
f32 pan;
Expand Down Expand Up @@ -2600,7 +2599,7 @@ u8 func_800F37B8(f32 behindScreenZ, SfxBankEntry* arg1, s8 arg2) {
return (phi_v1 * 0x10) + (u8)((phi_f0 * phi_f12) / (10000.0f / 5.2f));
}

s8 func_800F3990(f32 posY, u16 sfxParams) {
s8 func_800F3990(f32 posY, UNUSED u16 sfxParams) {
s8 combFilterGain = 0;

if (posY >= 0.0f) {
Expand Down Expand Up @@ -3579,7 +3578,7 @@ void Audio_SetBgmEnemyVolume(f32 dist) {
}

void Audio_UpdateMalonSinging(f32 dist, u16 seqId) {
s8 pad;
STACK_PAD(u8);
s8 melodyVolume;
s16 curSeqId;

Expand Down Expand Up @@ -3998,7 +3997,7 @@ void func_800F7170(void) {
AUDIOCMD_GLOBAL_STOP_AUDIOCMDS();
}

void func_800F71BC(s32 arg0) {
void func_800F71BC(UNUSED s32 arg0) {
D_80133418 = 1;
func_800F6C34();
AudioOcarina_ResetStaffs();
Expand Down
2 changes: 1 addition & 1 deletion src/audio/lib/effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void Audio_NotePortamentoInit(Note* note) {
note->playbackState.portamento = note->playbackState.parentLayer->portamento;
}

void Audio_AdsrInit(AdsrState* adsr, EnvelopePoint* envelope, s16* volOut) {
void Audio_AdsrInit(AdsrState* adsr, EnvelopePoint* envelope, UNUSED s16* volOut) {
adsr->action.asByte = 0;
adsr->delay = 0;
adsr->envelope = envelope;
Expand Down
8 changes: 4 additions & 4 deletions src/audio/lib/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ void AudioHeap_LoadFilter(s16* filter, s32 lowPassCutoff, s32 highPassCutoff) {
}
}

void AudioHeap_UpdateReverb(SynthesisReverb* reverb) {
void AudioHeap_UpdateReverb(UNUSED SynthesisReverb* reverb) {
}

void AudioHeap_UpdateReverbs(void) {
Expand Down Expand Up @@ -841,7 +841,7 @@ s32 AudioHeap_ResetStep(void) {
}

void AudioHeap_Init(void) {
s32 pad1[4];
STACK_PADS(s32, 4);
s16* ramAddr;
s32 persistentSize;
s32 temporarySize;
Expand All @@ -850,7 +850,7 @@ void AudioHeap_Init(void) {
OSIntMask intMask;
s32 i;
s32 j;
s32 pad2;
STACK_PAD(s32);
AudioSpec* spec = &gAudioSpecs[gAudioCtx.specId]; // Audio Specifications

gAudioCtx.sampleDmaCount = 0;
Expand Down Expand Up @@ -1389,7 +1389,7 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) {
Instrument* inst;
SoundEffect* soundEffect;
u32* fakematch;
s32 pad[4];
STACK_PADS(s32, 4);

sampleBankTable = gAudioCtx.sampleBankTable;
numFonts = gAudioCtx.soundFontTable->numEntries;
Expand Down
Loading