Skip to content

Commit e0a11b3

Browse files
committed
Support 'raw mangles' via leading "\1" in pragma(mangle) strings
Such mangled names aren't affected by a target-specific default (C) prefix, such as `_` on Mac.
1 parent c79a9ee commit e0a11b3

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

dmd/dsymbolsem.d

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,15 @@ version (IN_LLVM)
15261526
dchar c = slice[i];
15271527
if (c < 0x80)
15281528
{
1529+
version (IN_LLVM)
1530+
{
1531+
// LDC: allow leading "\1" to prevent target-specific prefix
1532+
if (i == 0 && c == '\1')
1533+
{
1534+
++i;
1535+
continue;
1536+
}
1537+
}
15291538
if (c.isValidMangling)
15301539
{
15311540
++i;

gen/mangling.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,15 @@ std::string getIRMangledName(VarDeclaration *vd) {
125125
}
126126

127127
std::string getIRMangledFuncName(std::string baseMangle, LINK link) {
128-
return gABI->mangleFunctionForLLVM(std::move(baseMangle), link);
128+
return baseMangle[0] == '\1'
129+
? baseMangle
130+
: gABI->mangleFunctionForLLVM(std::move(baseMangle), link);
129131
}
130132

131133
std::string getIRMangledVarName(std::string baseMangle, LINK link) {
132-
return gABI->mangleVariableForLLVM(std::move(baseMangle), link);
134+
return baseMangle[0] == '\1'
135+
? baseMangle
136+
: gABI->mangleVariableForLLVM(std::move(baseMangle), link);
133137
}
134138

135139
std::string getIRMangledAggregateName(AggregateDeclaration *ad,

tests/codegen/mangling_raw.d

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Tests that 'raw mangles' starting with "\1" are correctly propagated to IR.
2+
3+
// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll
4+
5+
// CHECK: @"\01myGlobal" = global i32
6+
pragma(mangle, "\1myGlobal")
7+
__gshared int myGlobal;
8+
9+
// CHECK: define {{.*}} @"\01myFunction"()
10+
pragma(mangle, "\1myFunction")
11+
void myFunction() {}

0 commit comments

Comments
 (0)