validation: Address -Wclobbered warnings

Use functions with const parameters and const local variables
to silence -Wclobbered warnings.

Updates #5364.
This commit is contained in:
Sebastian Huber
2025-10-17 08:32:42 +02:00
committed by Gedare Bloom
parent c49cfbf9a9
commit e66a33fd7a
4 changed files with 59 additions and 58 deletions

View File

@@ -675,6 +675,15 @@ static void ResumeThreadDispatch(
longjmp( ctx->thread_dispatch_context, 1 );
}
static void DeleteAndJumpBack( Context * const ctx )
{
if ( setjmp( ctx->thread_dispatch_context ) == 0 ) {
ctx->status = rtems_task_delete( ctx->id );
} else {
_Thread_Dispatch_unnest( _Per_CPU_Get() );
}
}
static void Delete( void *arg )
{
Context *ctx;
@@ -716,12 +725,7 @@ static void Delete( void *arg )
log = T_scheduler_record_10( &ctx->scheduler_log );
T_null( log );
if ( setjmp( ctx->thread_dispatch_context ) == 0 ) {
ctx->status = rtems_task_delete( ctx->id );
} else {
_Thread_Dispatch_unnest( _Per_CPU_Get() );
}
DeleteAndJumpBack( ctx );
CaptureWorkerState( ctx );
if ( ctx->dispatch_disabled ) {
@@ -763,6 +767,18 @@ static void BlockDone( Context *ctx )
}
}
static void BlockAndJumpBack(
Context * const ctx,
Per_CPU_Control * const cpu_self
)
{
if ( setjmp( ctx->thread_dispatch_context ) == 0 ) {
Block( ctx );
} else {
_Thread_Dispatch_unnest( cpu_self );
}
}
static void Signal( rtems_signal_set signals )
{
Context *ctx;
@@ -780,12 +796,7 @@ static void Signal( rtems_signal_set signals )
SetFatalHandler( ResumeThreadDispatch, ctx );
cpu_self = _Thread_Dispatch_disable();
if ( setjmp( ctx->thread_dispatch_context ) == 0 ) {
Block( ctx );
} else {
_Thread_Dispatch_unnest( cpu_self );
}
BlockAndJumpBack( ctx, cpu_self );
CallWithinISR( Delete, ctx );
_Thread_Dispatch_direct( cpu_self );

View File

@@ -744,8 +744,8 @@ static void ResumeThreadDispatch(
}
static void TriggerNestedRequestViaSelfRestart(
Context *ctx,
Per_CPU_Control *cpu_self
Context * const ctx,
Per_CPU_Control * const cpu_self
)
{
WrapThreadQueueExtract( &ctx->wrap_tq_ctx, ctx->worker_tcb );
@@ -761,6 +761,18 @@ static void TriggerNestedRequestViaSelfRestart(
}
}
static void BlockAndJumpBack(
Context * const ctx,
Per_CPU_Control * const cpu_self
)
{
if ( setjmp( ctx->thread_dispatch_context ) == 0 ) {
Block( ctx );
} else {
_Thread_Dispatch_unnest( cpu_self );
}
}
static void Signal( rtems_signal_set signals )
{
Context *ctx;
@@ -777,15 +789,9 @@ static void Signal( rtems_signal_set signals )
if ( ctx->interrupt || ctx->nested_request ) {
if ( ctx->blocked ) {
SetFatalHandler( ResumeThreadDispatch, ctx );
(void) _Thread_Dispatch_disable();
cpu_self = _Thread_Dispatch_disable();
BlockAndJumpBack( ctx, cpu_self );
if ( setjmp( ctx->thread_dispatch_context ) == 0 ) {
Block( ctx );
} else {
_Thread_Dispatch_unnest( _Per_CPU_Get() );
}
cpu_self = _Per_CPU_Get();
if ( ctx->interrupt ) {
CallWithinISR( Restart, ctx );
} else {

View File

@@ -210,10 +210,9 @@ static void ScoreSmpValFatal_Action_0( ScoreSmpValFatal_Context *ctx )
*/
static void ScoreSmpValFatal_Action_1( ScoreSmpValFatal_Context *ctx )
{
Per_CPU_Control *cpu;
Per_CPU_Control * const cpu = _Per_CPU_Get_by_index( 0 );
SetFatalHandler( FatalRecordAndJump, ctx );
cpu = _Per_CPU_Get_by_index( 0 );
_Per_CPU_Submit_job( cpu, &job );
if ( setjmp( fatal_before ) == 0 ) {
@@ -240,16 +239,14 @@ static void ScoreSmpValFatal_Action_1( ScoreSmpValFatal_Context *ctx )
*/
static void ScoreSmpValFatal_Action_2( ScoreSmpValFatal_Context *ctx )
{
Per_CPU_Control *cpu;
SetFatalHandler( FatalRecordAndJump, ctx );
/*
* This element is outside the array. This is not an issue since
* _SMP_Start_multitasking_on_secondary_processor() does not access the
* structure.
*/
cpu = _Per_CPU_Get_by_index( 3 );
Per_CPU_Control * const cpu = _Per_CPU_Get_by_index( 3 );
SetFatalHandler( FatalRecordAndJump, ctx );
if ( setjmp( fatal_before ) == 0 ) {
_SMP_Start_multitasking_on_secondary_processor( cpu );
@@ -275,10 +272,9 @@ static void ScoreSmpValFatal_Action_2( ScoreSmpValFatal_Context *ctx )
*/
static void ScoreSmpValFatal_Action_3( ScoreSmpValFatal_Context *ctx )
{
Per_CPU_Control *cpu;
Per_CPU_Control * const cpu = _Per_CPU_Get_by_index( 2 );
SetFatalHandler( FatalRecordAndJump, ctx );
cpu = _Per_CPU_Get_by_index( 2 );
if ( setjmp( fatal_before ) == 0 ) {
_SMP_Start_multitasking_on_secondary_processor( cpu );

View File

@@ -285,20 +285,22 @@ static void ThreadQueueDeadlock(
longjmp( ctx->before_enqueue, 1 );
}
/*
* This warning flags when the caller of setjmp() is assuming a local
* variable survives the longjmp() back. In this specific case, this
* assumption is OK because it never returns from the thread body and
* the variable "events" is preserved.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclobbered"
static void EnqueueFatal( TQContext * const ctx, TQWorkerKind const worker )
{
SetFatalHandler( ThreadQueueDeadlock, ctx );
if ( setjmp( ctx->before_enqueue ) == 0 ) {
ctx->status[ worker ] = STATUS_MINUS_ONE;
Enqueue( ctx, worker, ctx->wait );
} else {
ctx->status[ worker ] = STATUS_DEADLOCK;
}
}
static void Worker( rtems_task_argument arg, TQWorkerKind worker )
{
TQContext *ctx;
ctx = (TQContext *) arg;
while ( true ) {
@@ -332,14 +334,7 @@ static void Worker( rtems_task_argument arg, TQWorkerKind worker )
}
if ( ( events & TQ_EVENT_ENQUEUE_FATAL ) != 0 ) {
SetFatalHandler( ThreadQueueDeadlock, ctx );
if ( setjmp( ctx->before_enqueue ) == 0 ) {
ctx->status[ worker ] = STATUS_MINUS_ONE;
Enqueue( ctx, worker, ctx->wait );
} else {
ctx->status[ worker ] = STATUS_DEADLOCK;
}
EnqueueFatal( ctx, worker );
}
if ( ( events & TQ_EVENT_TIMEOUT ) != 0 ) {
@@ -455,8 +450,6 @@ static void Worker( rtems_task_argument arg, TQWorkerKind worker )
}
}
#pragma GCC diagnostic pop
static void BlockerA( rtems_task_argument arg )
{
Worker( arg, TQ_BLOCKER_A );
@@ -644,20 +637,15 @@ Status_Control TQEnqueue( TQContext *ctx, TQWait wait )
return ( *ctx->enqueue )( ctx, wait );
}
Status_Control TQEnqueueFatal( TQContext *ctx )
Status_Control TQEnqueueFatal( TQContext * const ctx )
{
Status_Control status;
SetFatalHandler( ThreadQueueDeadlock, ctx );
status = STATUS_MINUS_ONE;
if ( setjmp( ctx->before_enqueue ) == 0 ) {
status = TQEnqueue( ctx, ctx->wait );
} else {
status = STATUS_DEADLOCK;
return TQEnqueue( ctx, ctx->wait );
}
return status;
return STATUS_DEADLOCK;
}
void TQEnqueueDone( TQContext *ctx )