Skip to content

Commit

Permalink
fix Issue 16400 - naked variadic C function emits broken prologue
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright authored and dlang-bot committed Aug 12, 2020
1 parent 3125bb1 commit 07e354a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dmd/backend/cgelem.d
Original file line number Diff line number Diff line change
Expand Up @@ -5063,6 +5063,13 @@ private elem * elvalist(elem *e, goal_t goal)
{
assert(e.Eoper == OPva_start);

if (funcsym_p.ty() & mTYnaked)
{ // do not generate prolog
el_free(e);
e = el_long(TYint, 0);
return e;
}

if (I32)
{
// (OPva_start &va)
Expand Down
16 changes: 16 additions & 0 deletions test/runnable/iasm.d
Original file line number Diff line number Diff line change
Expand Up @@ -4828,6 +4828,21 @@ L1: pop EAX;
}

/****************************************************/
// https://issues.dlang.org/show_bug.cgi?id=16400

extern(C) void f16400(int, ...)
{
asm {naked; ret;}
}

void test16400()
{
assert(*(cast(ubyte*) &f16400) == 0xc3); // fails
f16400(0); // corrupts the stack
}

/****************************************************/

int main()
{
printf("Testing iasm.d\n");
Expand Down Expand Up @@ -4902,6 +4917,7 @@ int main()
test60();
test9866();
test17027();
test16400();
}
printf("Success\n");
return 0;
Expand Down

0 comments on commit 07e354a

Please sign in to comment.