Skip to content

Commit

Permalink
Big, big oops: we must flush *before* we form the argstring, otherwis…
Browse files Browse the repository at this point in the history
…e the struct spreading in the calls will cause multiple eval of calls in unflushed values.

This issue cost me 16 hours of debugging.
  • Loading branch information
FeepingCreature committed Jan 5, 2024
1 parent f4ba38c commit 4cd2569
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/backend/c.nt
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,9 @@ class CBackendFunction : BackendFunction {
}
(:callInstr, BackendType retType, string name, int[] args): {
auto fpType = mod.globals.type(name).instanceOf(BackendFunctionPointerType)? else die;
auto argstr = createArgString(fpType, args);
// Note: this *must* come first to ensure that the argstring doesn't double eval struct values.
flushRegs;
auto argstr = createArgString(fpType, args);
if (retType.size == 0) {
return Value("", name ~ "(" ~ argstr ~ ")", exactType=true);
}
Expand All @@ -748,9 +749,10 @@ class CBackendFunction : BackendFunction {
(:callFuncPtr, BackendType type, int regId, int[] args): {
auto backendFpType = type.instanceOf(BackendFunctionPointerType)? else die;
auto retType = backendFpType.ret;
// Note: this *must* come first to ensure that the argstring doesn't double eval struct values.
flushRegs;
auto argstr = createArgString(backendFpType, args);
string target = reg(regId);
flushRegs;
if (retType.size == 0) {
return Value("", "(" ~ target ~ ")(" ~ argstr ~ ")", exactType=true);
}
Expand Down

0 comments on commit 4cd2569

Please sign in to comment.