Add -Wlarge-constant to RGBLINK as it is for RGBASM

This commit is contained in:
Rangi42
2026-04-28 14:45:22 +02:00
committed by Rangi
parent 998f636495
commit f72a4d53e2
10 changed files with 67 additions and 16 deletions
+1
View File
@@ -142,6 +142,7 @@ _rgblink_completions() {
mapfile -t COMPREPLY < <(compgen -W "
assert
div
large-constant
obsolete
shift
shift-amount
+1
View File
@@ -9,6 +9,7 @@ _rgblink_warnings() {
'assert:Warn when WARN-type asserts fail'
'div:Warn when dividing the smallest int by -1'
'large-constant:Warn on constants too large for a signed 32-bit int'
'obsolete:Warn when using deprecated features'
'shift:Warn when shifting negative values'
'shift-amount:Warn when a shift'\''s operand is negative or \> 32'
+8 -5
View File
@@ -22,11 +22,12 @@ enum WarningLevel {
};
enum WarningID {
WARNING_ASSERT, // Assertions
WARNING_DIV, // Undefined division behavior
WARNING_OBSOLETE, // Obsolete/deprecated things
WARNING_SHIFT, // Undefined `SHIFT` behavior
WARNING_SHIFT_AMOUNT, // Strange `SHIFT` amount
WARNING_ASSERT, // Assertions
WARNING_DIV, // Undefined division behavior
WARNING_LARGE_CONSTANT, // Constants too large
WARNING_OBSOLETE, // Obsolete/deprecated things
WARNING_SHIFT, // Undefined `SHIFT` behavior
WARNING_SHIFT_AMOUNT, // Strange `SHIFT` amount
NB_PLAIN_WARNINGS,
@@ -47,6 +48,8 @@ void warning(FileStackNode const *src, uint32_t lineNo, WarningID id, char const
void warning(FileStackNode const *src, uint32_t lineNo, char const *fmt, ...);
[[gnu::format(printf, 1, 2)]]
void warning(char const *fmt, ...);
[[gnu::format(printf, 2, 3)]]
void scriptWarning(WarningID id, char const *fmt, ...);
[[gnu::format(printf, 3, 4)]]
void error(FileStackNode const *src, uint32_t lineNo, char const *fmt, ...);
+2
View File
@@ -369,6 +369,8 @@ for
Warn when dividing the smallest negative integer (-2**31) by -1, which yields itself due to integer overflow.
This warning is enabled by
.Fl Wall .
.It Fl Wno-large-constant
Warn when a constant too large to fit in a signed 32-bit integer is encountered.
.It Fl Wno-obsolete
Warn when obsolete features are encountered, which have been deprecated and may later be removed.
.It Fl Wshift
+11 -2
View File
@@ -113,9 +113,18 @@ static yy::parser::symbol_type readNumber(int initial, char const *prefix, char
context.file.sbumpc();
}
for (int c = context.file.sgetc(); isDigit<Base>(c) || c == '_'; c = context.file.snextc()) {
if (c != '_') {
number = number * Base + parseDigit<Base>(c);
if (c == '_') {
continue;
}
uint32_t digit = parseDigit<Base>(c);
if (number > (UINT32_MAX - digit) / Base) {
scriptWarning(WARNING_LARGE_CONSTANT, "Integer constant is too large");
// Discard any additional digits
for (c = context.file.snextc(); isDigit<Base>(c) || c == '_';
c = context.file.snextc()) {}
return yy::parser::make_number(0);
}
number = number * Base + digit;
}
return yy::parser::make_number(number);
}
+36 -9
View File
@@ -17,18 +17,19 @@
// clang-format off: nested initializers
Diagnostics<WarningLevel, WarningID> warnings = {
.metaWarnings = {
{"all", LEVEL_ALL },
{"everything", LEVEL_EVERYTHING},
{"all", LEVEL_ALL },
{"everything", LEVEL_EVERYTHING},
},
.warningFlags = {
{"assert", LEVEL_DEFAULT },
{"div", LEVEL_ALL },
{"obsolete", LEVEL_DEFAULT },
{"shift", LEVEL_ALL },
{"shift-amount", LEVEL_ALL },
{"assert", LEVEL_DEFAULT },
{"div", LEVEL_ALL },
{"large-constant", LEVEL_DEFAULT },
{"obsolete", LEVEL_DEFAULT },
{"shift", LEVEL_ALL },
{"shift-amount", LEVEL_ALL },
// Parametric warnings
{"truncation", LEVEL_DEFAULT },
{"truncation", LEVEL_EVERYTHING},
{"truncation", LEVEL_DEFAULT },
{"truncation", LEVEL_EVERYTHING},
},
.paramWarnings = {
{WARNING_TRUNCATION_1, WARNING_TRUNCATION_2, 1},
@@ -198,3 +199,29 @@ void warning(FileStackNode const *src, uint32_t lineNo, WarningID id, char const
va_end(args);
}
void scriptWarning(WarningID id, char const *fmt, ...) {
char const *flag = warnings.warningFlags[id].name;
va_list args;
va_start(args, fmt);
switch (warnings.getWarningBehavior(id)) {
case WarningBehavior::DISABLED:
break;
case WarningBehavior::ENABLED:
printDiag(nullptr, 0, fmt, args, "warning", STYLE_YELLOW, "[-W%s]", flag);
break;
case WarningBehavior::ERROR:
printDiag(nullptr, 0, fmt, args, "error", STYLE_RED, "[-Werror=%s]", flag);
warnings.incrementErrors();
break;
}
va_end(args);
lexer_TraceCurrent();
}
+2
View File
@@ -0,0 +1,2 @@
section "test", rom0
label:: dw label
+1
View File
@@ -0,0 +1 @@
org $1_ffff_ffff
+3
View File
@@ -0,0 +1,3 @@
ROM0
INCLUDE "large-constant.inc"
"test"
+2
View File
@@ -0,0 +1,2 @@
warning: Integer constant is too large [-Wlarge-constant]
at large-constant.inc(1) <- large-constant.link(3)