[PATCH] Remove more stray returns and gcc_unreachable ()s

Martin Sebor msebor@gmail.com
Mon Nov 29 19:04:38 GMT 2021


On 11/29/21 11:53 AM, Martin Sebor wrote:
> On 11/29/21 6:09 AM, Richard Biener via Gcc-patches wrote:
>> This removes more cases that appear when bootstrap with
>> -Wunreachable-code-return progresses.
>>
> ...
>> diff --git a/gcc/sel-sched-ir.h b/gcc/sel-sched-ir.h
>> index 8ee0529d5a8..18e03c4cb96 100644
>> --- a/gcc/sel-sched-ir.h
>> +++ b/gcc/sel-sched-ir.h
>> @@ -1493,8 +1493,6 @@ bb_next_bb (basic_block bb)
>>       default:
>>         return bb->next_bb;
>>       }
>> -
>> -  gcc_unreachable ();
>>   }
> 
> Just skiming the changes out of curiosity, this one makes me
> wonder if the warning shouldn't be taught to avoid triggering
> on calls to __builtin_unreachable().  They can help make code
> more readable (e.g., after a case and switch statement that
> handles all values).

I see someone else raised the same question in a patch I hadn't
gotten to yet:

https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585431.html

If you do end up removing the gcc_unreachable() calls, I would
suggest to replace them with a comment so as not to lose
the readability benefit.

But I still wonder if it might make sense to teach the warning
not just about __builtin_unreachable() but also about noreturn
calls like abort() that (as you explained in the thread above)
gcc_unreachable() expands to.  Is there a benefit to warning
on such calls?

> 
> Martin



More information about the Gcc-patches mailing list