Skip to content

Fix vaarg_006/007/008/009 tests: prototype doesn't match actual parameters#167

Open
jorgsowa wants to merge 2 commits into
dstogov:masterfrom
jorgsowa:fix/vaarg-param-count-mismatch
Open

Fix vaarg_006/007/008/009 tests: prototype doesn't match actual parameters#167
jorgsowa wants to merge 2 commits into
dstogov:masterfrom
jorgsowa:fix/vaarg-param-count-mismatch

Conversation

@jorgsowa

@jorgsowa jorgsowa commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fix 4 failing tests for IR for MACOS aarch64.

I'm not sure whether only tests should be fixed, the check should be added (current PR), or the check should be more general.

The exact failures:
https://github.com/dstogov/ir/actions/runs/29170932167/job/86753268624?pr=135#step:5:2317

TEST: VA_ARG 006: va_arg(int) [./tests/run/vaarg_006.irt]
--- ./tests/run/vaarg_006.exp	2026-07-13 06:56:55
+++ ./tests/run/vaarg_006.out	2026-07-13 06:56:55
@@ -1 +1 @@
-sum 45
+sum 46

FAIL: VA_ARG 006: va_arg(int) [./tests/run/vaarg_006.irt]
TEST: VA_ARG 007: va_arg(double) [./tests/run/vaarg_007.irt]
--- ./tests/run/vaarg_007.exp	2026-07-13 06:56:55
+++ ./tests/run/vaarg_007.out	2026-07-13 06:56:55
@@ -1 +1 @@
-sum 55
+sum 36

FAIL: VA_ARG 007: va_arg(double) [./tests/run/vaarg_007.irt]
TEST: VA_ARG 008: va_arg(int) [./tests/run/vaarg_008.irt]
--- ./tests/run/vaarg_008.exp	2026-07-13 06:56:56
+++ ./tests/run/vaarg_008.out	2026-07-13 06:56:56
@@ -1 +1 @@
-sum 45
+sum 66

FAIL: VA_ARG 008: va_arg(int) [./tests/run/vaarg_008.irt]
TEST: VA_ARG 009: va_arg(double) [./tests/run/vaarg_009.irt]
--- ./tests/run/vaarg_009.exp	2026-07-13 06:56:56
+++ ./tests/run/vaarg_009.out	2026-07-13 06:56:56
@@ -1 +1 @@
-sum 55
+sum 6

FAIL: VA_ARG 009: va_arg(double) [./tests/run/vaarg_009.irt]

jorgsowa added 2 commits July 13, 2026 20:38
…eters

Each sum() function declared only 1 named int32_t parameter in its
signature but its body read 3 (or 9) fixed arguments directly via
PARAM before ever calling va_arg. Under SysV this drift is harmless
since register/stack placement doesn't depend on the named/variadic
boundary, so it went unnoticed for two years. Apple's aarch64 ABI
does care: it only register-passes the parameters actually declared
in the prototype, forcing everything else onto the stack. Since the
prototype under-declared its named parameters, va_start ended up
pointing at the wrong stack offset, corrupting every va_arg read on
the new macos-15-arm64 CI runner.

Correcting each prototype to declare all the parameters the body
actually reads (matching what the compiler's own --save
re-serialization already believed the real signature to be) resolves
the mismatch with no compiler changes.
…type

Nothing previously verified that a function's declared prototype
(the count of named parameters before "...") actually matched the
number of PARAM instructions in its body. That drift is exactly what
caused the vaarg_006/007/008/009 test failures: harmless under SysV,
but silently wrong on Apple's aarch64 ABI, which places named vs.
variadic arguments differently.

Reject the mismatch immediately at load time, on any platform,
before any codegen happens, instead of relying on a specific ABI to
happen to expose it at runtime.

@dstogov dstogov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is right or not. I'll need to think about this.

@dstogov dstogov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this is right.
Please, answer the question and make the minor change.

Comment thread tests/run/vaarg_006.irt
int32_t c_9 = 5;
int32_t c_10 = 6;
uintptr_t c_11 = func sum(int32_t, ...): int32_t;
uintptr_t c_11 = func sum(int32_t, int32_t, int32_t, ...): int32_t;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you plase show the difference in generated assembler code. Just in comments.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this. I already understood the difference.

Comment thread ir_load.c
ir_free(&ctx);
yy_error_str("parameter count doesn't match function signature", name);
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this check into ir_check() (or make a copy).
This way we will able to check this, with big test suites through LLVM and RCC front-ends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants