Merge pull request #2658 from kugelfuhr/kugelfuhr/fix-2655

Fix -W -unreachable-code not working in all cases
This commit is contained in:
Bob Andrews
2025-05-24 17:17:36 +02:00
committed by GitHub
7 changed files with 45 additions and 3 deletions

View File

@@ -379,6 +379,18 @@ void PPWarning (const char* Format, ...)
void UnreachableCodeWarning (void)
/* Print a warning about unreachable code at the current location if these
** warnings are enabled.
*/
{
if (IS_Get (&WarnUnreachableCode)) {
Warning ("Unreachable code");
}
}
IntStack* FindWarning (const char* Name)
/* Search for a warning in the WarnMap table and return a pointer to the
** intstack that holds its state. Return NULL if there is no such warning.

View File

@@ -127,6 +127,11 @@ void LIWarning (errcat_t EC, LineInfo* LI, const char* Format, ...) attribute ((
void PPWarning (const char* Format, ...) attribute ((format (printf, 1, 2)));
/* Print a warning message. For use within the preprocessor */
void UnreachableCodeWarning (void);
/* Print a warning about unreachable code at the current location if these
** warnings are enabled.
*/
IntStack* FindWarning (const char* Name);
/* Search for a warning in the WarnMap table and return a pointer to the
** intstack that holds its state. Return NULL if there is no such warning.

View File

@@ -188,8 +188,8 @@ static int IfStatement (void)
/* If the if expression was always true, the code in the else branch
** is never executed. Output a warning if this is the case.
*/
if (TestResult == TESTEXPR_TRUE && IS_Get (&WarnUnreachableCode)) {
Warning ("Unreachable code");
if (TestResult == TESTEXPR_TRUE) {
UnreachableCodeWarning ();
}
/* Define the target for the first test */

View File

@@ -76,7 +76,7 @@ unsigned Test (unsigned Label, int Invert)
/* Constant rvalue */
if (!Invert && Expr.IVal == 0) {
g_jump (Label);
Warning ("Unreachable code");
UnreachableCodeWarning ();
} else if (Invert && Expr.IVal != 0) {
g_jump (Label);
}