fix Issue 23347 - ImportC: pragma pack causes asm label to set symbol name to be ignored (#14481)

This commit is contained in:
Walter Bright 2022-09-25 19:15:21 -07:00 committed by GitHub
parent f382f39582
commit 27a952e316
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 9 deletions

View file

@ -1886,15 +1886,6 @@ final class CParser(AST) : Parser!AST
}
if (s !is null)
{
s = applySpecifier(s, specifier);
if (level == LVL.local)
{
// Wrap the declaration in `extern (C) { declaration }`
// Necessary for function pointers, but harmless to apply to all.
auto decls = new AST.Dsymbols(1);
(*decls)[0] = s;
s = new AST.LinkDeclaration(s.loc, linkage, decls);
}
// Saw `asm("name")` in the function, type, or variable definition.
// This is equivalent to `pragma(mangle, "name")` in D
if (asmName)
@ -1917,6 +1908,15 @@ final class CParser(AST) : Parser!AST
p.mangleOverride = str;
}
}
s = applySpecifier(s, specifier);
if (level == LVL.local)
{
// Wrap the declaration in `extern (C) { declaration }`
// Necessary for function pointers, but harmless to apply to all.
auto decls = new AST.Dsymbols(1);
(*decls)[0] = s;
s = new AST.LinkDeclaration(s.loc, linkage, decls);
}
symbols.push(s);
}
first = false;

View file

@ -0,0 +1,19 @@
/* DISABLED: osx32 osx64 win32 win64
* TEST_OUTPUT:
---
---
*/
// https://issues.dlang.org/show_bug.cgi?id=23347
void fork() { }
#pragma pack(push, 4)
void spoon() asm("fork");
#pragma pack(pop);
int main()
{
spoon();
return 0;
}