mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Optional warning for implicit constant conversion overflow
This commit is contained in:
parent
bf5b37a3b2
commit
409235aee6
@ -754,6 +754,8 @@ Here is a description of all the command line options:
|
||||
Warn about unused function parameters.
|
||||
<tag><tt/unused-var/</tag>
|
||||
Warn about unused variables.
|
||||
<tag><tt/const-overflow/</tag>
|
||||
Warn if numerical constant conversion implies overflow. (Disabled by default.)
|
||||
</descrip>
|
||||
|
||||
The full list of available warning names can be retrieved by using the
|
||||
|
@ -79,6 +79,7 @@ IntStack WarnUnusedLabel = INTSTACK(1); /* - unused labels */
|
||||
IntStack WarnUnusedParam = INTSTACK(1); /* - unused parameters */
|
||||
IntStack WarnUnusedVar = INTSTACK(1); /* - unused variables */
|
||||
IntStack WarnUnusedFunc = INTSTACK(1); /* - unused functions */
|
||||
IntStack WarnConstOverflow = INTSTACK(0); /* - overflow conversion of numerical constants */
|
||||
|
||||
/* Map the name of a warning to the intstack that holds its state */
|
||||
typedef struct WarnMapEntry WarnMapEntry;
|
||||
@ -102,6 +103,7 @@ static WarnMapEntry WarnMap[] = {
|
||||
{ &WarnUnusedLabel, "unused-label" },
|
||||
{ &WarnUnusedParam, "unused-param" },
|
||||
{ &WarnUnusedVar, "unused-var" },
|
||||
{ &WarnConstOverflow, "const-overflow" },
|
||||
};
|
||||
|
||||
Collection DiagnosticStrBufs;
|
||||
|
@ -76,6 +76,7 @@ extern IntStack WarnUnusedLabel; /* - unused labels */
|
||||
extern IntStack WarnUnusedParam; /* - unused parameters */
|
||||
extern IntStack WarnUnusedVar; /* - unused variables */
|
||||
extern IntStack WarnUnusedFunc; /* - unused functions */
|
||||
extern IntStack WarnConstOverflow; /* - overflow conversion of numerical constants */
|
||||
|
||||
/* Forward */
|
||||
struct StrBuf;
|
||||
|
@ -128,6 +128,7 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
||||
** internally already represented by a long.
|
||||
*/
|
||||
if (NewBits <= OldBits) {
|
||||
unsigned long OldVal = Expr->IVal;
|
||||
|
||||
/* Cut the value to the new size */
|
||||
Expr->IVal &= (0xFFFFFFFFUL >> (32 - NewBits));
|
||||
@ -139,6 +140,10 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
||||
Expr->IVal |= shl_l (~0UL, NewBits);
|
||||
}
|
||||
}
|
||||
|
||||
if ((OldVal != Expr->IVal) && IS_Get (&WarnConstOverflow)) {
|
||||
Warning ("Implicit conversion of constant overflows %d-bit destination", NewBits);
|
||||
}
|
||||
}
|
||||
|
||||
/* Do the integer constant <-> absolute address conversion if necessary */
|
||||
|
Loading…
x
Reference in New Issue
Block a user