Apply the NORETURN attribute to functions that do not return (#1768)

* Apply the NORETURN attribute to functions that do not return

* Add NORETURN to debug.c functions
This commit is contained in:
Tharo 2024-12-22 23:24:47 +00:00 committed by GitHub
parent 16d8f4870d
commit 2a152a9676
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 24 additions and 10 deletions

View File

@ -14,4 +14,10 @@
#define NO_REORDER __attribute__((no_reorder))
#define SECTION_DATA __attribute__((section(".data")))
#ifdef __GNUC__
#define UNREACHABLE() __builtin_unreachable()
#else
#define UNREACHABLE()
#endif
#endif

View File

@ -2,6 +2,7 @@
#define FAULT_H
#include "ultra64.h"
#include "attributes.h"
#include "stdarg.h"
#include "stdint.h"
@ -60,8 +61,8 @@ void Fault_Init(void);
// Fatal Errors
void Fault_AddHungupAndCrashImpl(const char* exp1, const char* exp2);
void Fault_AddHungupAndCrash(const char* file, s32 line);
NORETURN void Fault_AddHungupAndCrashImpl(const char* exp1, const char* exp2);
NORETURN void Fault_AddHungupAndCrash(const char* file, s32 line);
// Client Registration

View File

@ -25,7 +25,7 @@ void Room_Draw(PlayState* play, Room* room, u32 flags);
void Room_FinishRoomChange(PlayState* play, RoomContext* roomCtx);
void func_80183070(void);
NORETURN void func_80183070(void);
AudioTask* AudioThread_Update(void);
void AudioThread_QueueCmdF32(u32 opArgs, f32 data);

View File

@ -1,7 +1,9 @@
#ifndef LIBU64_DEBUG_H
#define LIBU64_DEBUG_H
void _dbg_hungup(const char* file, int lineNum);
void Reset(void);
#include "../attributes.h"
NORETURN void _dbg_hungup(const char* file, int lineNum);
NORETURN void Reset(void);
#endif

View File

@ -1114,19 +1114,23 @@ void Fault_HangupFaultClient(const char* exp1, const char* exp2) {
* error occurs. The parameters specify two messages detailing the error, one
* or both may be NULL.
*/
void Fault_AddHungupAndCrashImpl(const char* exp1, const char* exp2) {
NORETURN void Fault_AddHungupAndCrashImpl(const char* exp1, const char* exp2) {
FaultClient client;
s32 pad;
Fault_AddClient(&client, (void*)Fault_HangupFaultClient, (void*)exp1, (void*)exp2);
*(u32*)0x11111111 = 0; // trigger an exception via unaligned memory access
// Since the above line triggers an exception and transfers execution to the fault handler
// this function does not return and the rest of the function is unreachable.
UNREACHABLE();
}
/**
* Like `Fault_AddHungupAndCrashImpl`, however provides a fixed message containing
* file and line number
*/
void Fault_AddHungupAndCrash(const char* file, s32 line) {
NORETURN void Fault_AddHungupAndCrash(const char* file, s32 line) {
char msg[0x100];
sprintf(msg, "HungUp %s:%d", file, line);

View File

@ -1,11 +1,11 @@
#include "global.h"
#include "fault.h"
void _dbg_hungup(const char* file, int lineNum) {
NORETURN void _dbg_hungup(const char* file, int lineNum) {
osGetThreadId(NULL);
Fault_AddHungupAndCrash(file, lineNum);
}
void Reset(void) {
NORETURN void Reset(void) {
Fault_AddHungupAndCrash("Reset", 0);
}

View File

@ -1,6 +1,7 @@
#include "libc64/sleep.h"
#include "attributes.h"
void func_80183070(void) {
NORETURN void func_80183070(void) {
for (;;) {
msleep(1000);
}