Add more tests for RGBASM code coverage (#1257)

* Add more tests for RGBASM code coverage

* Use C++ unnamed parameters, not `(void)` casting

* Fix crash in `sect_AlignPC` from #1253
This commit is contained in:
Rangi
2023-12-01 10:21:43 -05:00
committed by GitHub
parent cee3d1c859
commit 6132b77c1e
85 changed files with 450 additions and 65 deletions

View File

@@ -130,9 +130,8 @@ void out_RegisterNode(struct FileStackNode *node)
}
}
void out_ReplaceNode(struct FileStackNode *node)
void out_ReplaceNode(struct FileStackNode * /* node */)
{
(void)node;
#if 0
This is code intended to replace a node, which is pretty useless until ref counting is added...
@@ -469,10 +468,8 @@ static void writeFileStackNode(struct FileStackNode const *node, FILE *f)
}
}
static void registerUnregisteredSymbol(struct Symbol *symbol, void *arg)
static void registerUnregisteredSymbol(struct Symbol *symbol, void *)
{
(void)arg; // sym_ForEach requires a void* parameter, but we are not using it.
// Check for symbol->src, to skip any built-in symbol from rgbasm
if (symbol->src && symbol->ID == (uint32_t)-1) {
registerSymbol(symbol);

View File

@@ -1021,6 +1021,7 @@ align : T_OP_ALIGN align_spec { sect_AlignPC($2.alignment, $2.alignOfs); }
align_spec : uconst {
if ($1 > 16) {
error("Alignment must be between 0 and 16, not %u\n", $1);
$$.alignment = $$.alignOfs = 0;
} else {
$$.alignment = $1;
$$.alignOfs = 0;
@@ -1029,10 +1030,12 @@ align_spec : uconst {
| uconst T_COMMA const {
if ($1 > 16) {
error("Alignment must be between 0 and 16, not %u\n", $1);
$$.alignment = $$.alignOfs = 0;
} else if ($3 <= -(1 << $1) || $3 >= 1 << $1) {
error("The absolute alignment offset (%" PRIu32
") must be less than alignment size (%d)\n",
(uint32_t)($3 < 0 ? -$3 : $3), 1 << $1);
$$.alignment = $$.alignOfs = 0;
} else {
$$.alignment = $1;
$$.alignOfs = $3 < 0 ? (1 << $1) + $3 : $3;

View File

@@ -512,10 +512,7 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
if (src2->val < 0)
fatalerror("Exponentiation by negative power\n");
if (src1->val == INT32_MIN && src2->val == -1)
expr->val = 0;
else
expr->val = op_exponent(src1->val, src2->val);
expr->val = op_exponent(src1->val, src2->val);
break;
case RPN_NEG:

View File

@@ -167,10 +167,9 @@ static unsigned int mergeSectUnion(struct Section *sect, enum SectionType type,
return nbSectErrors;
}
static unsigned int mergeFragments(struct Section *sect, enum SectionType type, uint32_t org,
uint8_t alignment, uint16_t alignOffset)
static unsigned int mergeFragments(struct Section *sect, uint32_t org, uint8_t alignment,
uint16_t alignOffset)
{
(void)type;
assert(alignment < 16); // Should be ensured by the caller
unsigned int nbSectErrors = 0;
@@ -183,8 +182,7 @@ static unsigned int mergeFragments(struct Section *sect, enum SectionType type,
// If both are fixed, they must be the same
if (sect->org != (uint32_t)-1 && sect->org != curOrg)
fail("Section already declared as fixed at incompatible address $%04"
PRIx32 " (cur addr = %04" PRIx32 ")\n",
sect->org, sect->org + sect->size);
PRIx32 "\n", sect->org);
else if (sect->align != 0 && (mask(sect->align) & (curOrg - sect->alignOfs)))
fail("Section already declared as aligned to %u bytes (offset %"
PRIu16 ")\n", 1U << sect->align, sect->alignOfs);
@@ -232,8 +230,9 @@ static void mergeSections(struct Section *sect, enum SectionType type, uint32_t
switch (mod) {
case SECTION_UNION:
case SECTION_FRAGMENT:
nbSectErrors += (mod == SECTION_UNION ? mergeSectUnion : mergeFragments)
(sect, type, org, alignment, alignOffset);
nbSectErrors += mod == SECTION_UNION ?
mergeSectUnion(sect, type, org, alignment, alignOffset) :
mergeFragments(sect, org, alignment, alignOffset);
// Common checks
@@ -499,7 +498,7 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset)
return;
struct Section *sect = sect_GetSymbolSection();
uint16_t alignSize = 1 << alignment; // Size of an aligned "block"
uint32_t alignSize = 1 << alignment; // Size of an aligned "block"
if (sect->org != (uint32_t)-1) {
if ((sect->org + curOffset - offset) % alignSize)

View File

@@ -328,9 +328,8 @@ static struct UnassignedSection *sections;
* @param section The section to categorize
* @param arg Callback arg, unused
*/
static void categorizeSection(struct Section *section, void *arg)
static void categorizeSection(struct Section *section, void *)
{
(void)arg;
uint8_t constraints = 0;
if (section->isBankFixed)

View File

@@ -406,7 +406,6 @@ int main(int argc, char *argv[])
break;
case 's':
// TODO: implement "smart linking" with `-s`
(void)musl_optarg;
warning(NULL, 0, "Nobody has any idea what `-s` does");
break;
case 't':

View File

@@ -669,10 +669,8 @@ static void freeNode(struct FileStackNode *node)
free(node->name);
}
static void freeSection(struct Section *section, void *arg)
static void freeSection(struct Section *section, void *)
{
(void)arg;
do {
struct Section *next = section->nextu;

View File

@@ -502,8 +502,8 @@ void patch_CheckAssertions(struct Assertion *assert)
/*
* Applies all of a section's patches
* @param section The section to patch
* @param arg Ignored callback arg
* @param section The section component to patch
* @param dataSection The section to patch
*/
static void applyFilePatches(struct Section *section, struct Section *dataSection)
{
@@ -554,23 +554,17 @@ static void applyFilePatches(struct Section *section, struct Section *dataSectio
}
/*
* Applies all of a section's patches, iterating over "components" of
* unionized sections
* Applies all of a section's patches, iterating over "components" of unionized sections
* @param section The section to patch
* @param arg Ignored callback arg
*/
static void applyPatches(struct Section *section, void *arg)
static void applyPatches(struct Section *section, void *)
{
if (!sect_HasData(section->type))
return;
(void)arg;
struct Section *dataSection = section;
do {
applyFilePatches(section, dataSection);
section = section->nextu;
} while (section);
for (struct Section *component = section; component; component = component->nextu)
applyFilePatches(component, section);
}
void patch_ApplyPatches(void)

View File

@@ -219,10 +219,8 @@ void sect_CleanupSections(void)
hash_EmptyMap(sections);
}
static void doSanityChecks(struct Section *section, void *ptr)
static void doSanityChecks(struct Section *section, void *)
{
(void)ptr;
// Sanity check the section's type
if (section->type < 0 || section->type >= SECTTYPE_INVALID) {