Skip to content

Commit 88f8478

Browse files
authored
Merge pull request #26167 from eeckstein/driver-update
Driver: Don't imply -enable-anonymous-context-mangled-names with optimizations enabled, even if -g is used.
2 parents 9ff887b + 321d340 commit 88f8478

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

lib/Driver/ToolChains.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
261261
// -g implies -enable-anonymous-context-mangled-names, because the extra
262262
// metadata aids debugging.
263263
if (inputArgs.hasArg(options::OPT_g)) {
264-
arguments.push_back("-enable-anonymous-context-mangled-names");
264+
// But don't add the option in optimized builds: it would prevent dead code
265+
// stripping of unused metadata.
266+
auto OptArg = inputArgs.getLastArgNoClaim(options::OPT_O_Group);
267+
if (!OptArg || OptArg->getOption().matches(options::OPT_Onone))
268+
arguments.push_back("-enable-anonymous-context-mangled-names");
265269
}
266270

267271
// Pass through any subsystem flags.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// RUN: %target-swiftc_driver -### -g %s 2>&1 | %FileCheck %s
2+
// RUN: %target-swiftc_driver -### -g -Onone %s 2>&1 | %FileCheck -check-prefix=CHECK-ONONE %s
3+
// RUN: %target-swiftc_driver -### -g -O %s 2>&1 | %FileCheck -check-prefix=CHECK-O %s
4+
// RUN: %target-swiftc_driver -### -g -Osize %s 2>&1 | %FileCheck -check-prefix=CHECK-OSIZE %s
25

36
// CHECK: -enable-anonymous-context-mangled-names
7+
// CHECK-ONONE: -enable-anonymous-context-mangled-names
8+
// CHECK-O-NOT: -enable-anonymous-context-mangled-names
9+
// CHECK-OSIZE-NOT: -enable-anonymous-context-mangled-names
410

test/IRGen/lazy_metadata_with-g.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-swiftc_driver -parse-as-library -module-name=test -target x86_64-apple-macosx10.15 -wmo -O -g -emit-ir %s | %FileCheck %s
2+
// REQUIRES: OS=macosx
3+
4+
// Check that the compiler does not emit any metadata for Mystruct and
5+
// Teststruct, even with -g.
6+
// This is also a driver issue, so we are testing with %target-swiftc_driver
7+
// and not just with %target-swift-frontend.
8+
9+
// CHECK: ModuleID
10+
11+
// CHECK-NOT: Mystruct
12+
// CHECK-NOT: Teststruct
13+
// CHECK-NOT: define
14+
15+
// CHECK: DICompileUnit
16+
17+
protocol P {
18+
}
19+
20+
struct Mystruct : P {
21+
}
22+
23+
24+
struct Teststruct {
25+
26+
static var testvar: some P {
27+
return Mystruct()
28+
}
29+
}
30+

0 commit comments

Comments
 (0)