Make sure, the command line setting for the "Unreachable code" warning is
checked in all cases before outputting such a warning. Fixes #2655.
This commit is contained in:
@@ -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)
|
IntStack* FindWarning (const char* Name)
|
||||||
/* Search for a warning in the WarnMap table and return a pointer to the
|
/* 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.
|
** intstack that holds its state. Return NULL if there is no such warning.
|
||||||
|
|||||||
@@ -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)));
|
void PPWarning (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||||
/* Print a warning message. For use within the preprocessor */
|
/* 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);
|
IntStack* FindWarning (const char* Name);
|
||||||
/* Search for a warning in the WarnMap table and return a pointer to the
|
/* 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.
|
** intstack that holds its state. Return NULL if there is no such warning.
|
||||||
|
|||||||
@@ -188,8 +188,8 @@ static int IfStatement (void)
|
|||||||
/* If the if expression was always true, the code in the else branch
|
/* If the if expression was always true, the code in the else branch
|
||||||
** is never executed. Output a warning if this is the case.
|
** is never executed. Output a warning if this is the case.
|
||||||
*/
|
*/
|
||||||
if (TestResult == TESTEXPR_TRUE && IS_Get (&WarnUnreachableCode)) {
|
if (TestResult == TESTEXPR_TRUE) {
|
||||||
Warning ("Unreachable code");
|
UnreachableCodeWarning ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Define the target for the first test */
|
/* Define the target for the first test */
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ unsigned Test (unsigned Label, int Invert)
|
|||||||
/* Constant rvalue */
|
/* Constant rvalue */
|
||||||
if (!Invert && Expr.IVal == 0) {
|
if (!Invert && Expr.IVal == 0) {
|
||||||
g_jump (Label);
|
g_jump (Label);
|
||||||
Warning ("Unreachable code");
|
UnreachableCodeWarning ();
|
||||||
} else if (Invert && Expr.IVal != 0) {
|
} else if (Invert && Expr.IVal != 0) {
|
||||||
g_jump (Label);
|
g_jump (Label);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,11 @@ $(WORKDIR)/endless.$1.$2.prg: endless.c | $(WORKDIR)
|
|||||||
|
|
||||||
# these need reference data that can't be generated by a host-compiled program,
|
# these need reference data that can't be generated by a host-compiled program,
|
||||||
# in a useful way
|
# in a useful way
|
||||||
|
$(WORKDIR)/bug2655.$1.$2.prg: bug2655.c $(ISEQUAL) | $(WORKDIR)
|
||||||
|
$(if $(QUIET),echo misc/bug2655.$1.$2.prg)
|
||||||
|
$(CC65) -t sim$2 -$1 -o $$@ $$< 2>$(WORKDIR)/bug2655.$1.$2.out
|
||||||
|
$(ISEQUAL) $(WORKDIR)/bug2655.$1.$2.out bug2655.ref
|
||||||
|
|
||||||
$(WORKDIR)/limits.$1.$2.prg: limits.c $(ISEQUAL) | $(WORKDIR)
|
$(WORKDIR)/limits.$1.$2.prg: limits.c $(ISEQUAL) | $(WORKDIR)
|
||||||
$(if $(QUIET),echo misc/limits.$1.$2.prg)
|
$(if $(QUIET),echo misc/limits.$1.$2.prg)
|
||||||
$(CC65) -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLERR)
|
$(CC65) -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLERR)
|
||||||
|
|||||||
18
test/misc/bug2655.c
Normal file
18
test/misc/bug2655.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
void f1(void)
|
||||||
|
{
|
||||||
|
if (1) {
|
||||||
|
f1();
|
||||||
|
} else {
|
||||||
|
f1();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void f2(void)
|
||||||
|
{
|
||||||
|
if (0) {
|
||||||
|
f2();
|
||||||
|
} else {
|
||||||
|
f2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
2
test/misc/bug2655.ref
Normal file
2
test/misc/bug2655.ref
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
bug2655.c:5: Warning: Unreachable code
|
||||||
|
bug2655.c:12: Warning: Unreachable code
|
||||||
Reference in New Issue
Block a user