Skip to content

Commit

Permalink
Merge pull request #5729 from WalterWaldron/fix13147
Browse files Browse the repository at this point in the history
Fix Issue 13147 - invariant code added to functions with naked inline assembly
  • Loading branch information
AndrejMitrovic committed May 6, 2016
2 parents 9903aba + b5a5976 commit a084003
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,12 @@ public:
if (!fbody)
fbody = new CompoundStatement(Loc(), new Statements());

if (naked)
{
fpreinv = null; // can't accommodate with no stack frame
fpostinv = null;
}

assert(type == f || (type.ty == Tfunction && f.purity == PUREimpure && (cast(TypeFunction)type).purity >= PUREfwdref));
f = cast(TypeFunction)type;

Expand Down
39 changes: 39 additions & 0 deletions test/runnable/testinvariant.d
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,50 @@ void test13113()
assert(S13113.count == 4);
}

/***************************************************/
// 13147

version (D_InlineAsm_X86)
enum x86iasm = true;
else version (D_InlineAsm_X86_64)
enum x86iasm = true;
else
enum x86iasm = false;

class C13147
{
extern (C++) C13147 test()
{
static if (x86iasm)
asm { naked; ret; }
return this;
}
}

struct S13147
{
void test()
{
static if (x86iasm)
asm { naked; ret; }
}
}

void test13147()
{
auto c = new C13147();
c.test();
S13147 s;
s.test();
}


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

void main()
{
testinvariant();
test6453();
test13113();
test13147();
}

0 comments on commit a084003

Please sign in to comment.