Skip to content

Commit c85c905

Browse files
authored
Merge pull request swiftlang#63352 from DougGregor/macro-fixes
2 parents ff71907 + c24d262 commit c85c905

File tree

7 files changed

+26
-13
lines changed

7 files changed

+26
-13
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Mangling
99
::
1010

1111
mangled-name ::= '$s' global // Swift stable mangling
12+
mangled-name ::= '@__swiftmacro_' global // Swift mangling for filenames
1213
mangled-name ::= '_T0' global // Swift 4.0
1314
mangled-name ::= '$S' global // Swift 4.2
1415

lib/AST/ASTVerifier.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class Verifier : public ASTWalker {
232232
ClosureDiscriminators;
233233
DeclContext *CanonicalTopLevelSubcontext = nullptr;
234234

235-
typedef DeclContext * MacroExpansionDiscriminatorKey;
235+
typedef std::pair<DeclContext *, Identifier> MacroExpansionDiscriminatorKey;
236236
llvm::DenseMap<MacroExpansionDiscriminatorKey, SmallBitVector>
237237
MacroExpansionDiscriminators;
238238

@@ -2378,7 +2378,10 @@ class Verifier : public ASTWalker {
23782378

23792379
void verifyChecked(MacroExpansionExpr *expansion) {
23802380
auto dc = getCanonicalDeclContext(expansion->getDeclContext());
2381-
MacroExpansionDiscriminatorKey key{dc};
2381+
MacroExpansionDiscriminatorKey key{
2382+
dc,
2383+
expansion->getMacroName().getBaseName().getIdentifier()
2384+
};
23822385
auto &discriminatorSet = MacroExpansionDiscriminators[key];
23832386
unsigned discriminator = expansion->getDiscriminator();
23842387

@@ -2398,7 +2401,10 @@ class Verifier : public ASTWalker {
23982401

23992402
void verifyChecked(MacroExpansionDecl *expansion) {
24002403
auto dc = getCanonicalDeclContext(expansion->getDeclContext());
2401-
MacroExpansionDiscriminatorKey key{dc};
2404+
MacroExpansionDiscriminatorKey key{
2405+
dc,
2406+
expansion->getMacro().getBaseName().getIdentifier()
2407+
};
24022408
auto &discriminatorSet = MacroExpansionDiscriminators[key];
24032409
unsigned discriminator = expansion->getDiscriminator();
24042410

lib/ClangImporter/ClangImporter.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,6 @@ importer::getNormalInvocationArguments(
502502
"-fmodules",
503503
"-Xclang", "-fmodule-feature", "-Xclang", "swift"
504504
});
505-
// Don't enforce strict rules when inside the debugger to work around search
506-
// path problems caused by a module existing in both the build/install
507-
// directory and the source directory.
508-
if (!importerOpts.DebuggerSupport)
509-
invocationArgStrs.push_back(
510-
"-Werror=non-modular-include-in-framework-module");
511505

512506
bool EnableCXXInterop = LangOpts.EnableCXXInterop;
513507

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ int swift::Demangle::getManglingPrefixLength(llvm::StringRef mangledName) {
177177
llvm::StringRef prefixes[] = {
178178
/*Swift 4*/ "_T0",
179179
/*Swift 4.x*/ "$S", "_$S",
180-
/*Swift 5+*/ "$s", "_$s"};
180+
/*Swift 5+*/ "$s", "_$s",
181+
/*Swift 5+ for filenames*/ "@__swiftmacro_",
182+
};
181183

182184
// Look for any of the known prefixes
183185
for (auto prefix : prefixes) {

test/ClangImporter/non-modular-include.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: not %target-swift-frontend -enable-objc-interop -typecheck %/s -I %S/Inputs/non-modular -F %S/Inputs/non-modular 2>&1 | %FileCheck --check-prefix=CHECK -check-prefix CHECK-objc %s
3-
// RUN: not %target-swift-frontend -disable-objc-interop -typecheck %/s -I %S/Inputs/non-modular -F %S/Inputs/non-modular 2>&1 | %FileCheck --check-prefix=CHECK -check-prefix CHECK-native %s
2+
3+
// Enable -Werror=non-modular-include-in-framework-module
4+
// RUN: not %target-swift-frontend -enable-objc-interop -typecheck %/s -I %S/Inputs/non-modular -F %S/Inputs/non-modular -Xcc -Werror=non-modular-include-in-framework-module 2>&1 | %FileCheck --check-prefix=CHECK -check-prefix CHECK-objc %s
5+
// RUN: not %target-swift-frontend -disable-objc-interop -typecheck -Xcc -Werror=non-modular-include-in-framework-module %/s -I %S/Inputs/non-modular -F %S/Inputs/non-modular 2>&1 | %FileCheck --check-prefix=CHECK -check-prefix CHECK-native %s
46

57
// CHECK: {{.+}}{{/|\\}}non-modular{{/|\\}}Foo.framework{{/|\\}}Headers{{/|\\}}Foo.h:1:10: error: include of non-modular header inside framework module 'Foo'
68
// CHECK-objc: error: could not build Objective-C module 'Foo'
79
// CHECK-native: error: could not build C module 'Foo'
810
// CHECK-NOT: error
911

1012
// RUN: %target-swift-frontend -debugger-support -typecheck %s -I %S/Inputs/non-modular -F %S/Inputs/non-modular 2>&1 | %FileCheck --allow-empty --check-prefix=CHECK-DEBUGGER %s
13+
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/non-modular -F %S/Inputs/non-modular 2>&1 | %FileCheck --allow-empty --check-prefix=CHECK-DEBUGGER %s
1114

1215
// CHECK-DEBUGGER-NOT: error:
1316

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,4 @@ $s4main4TestV1xSivpfaAA4Flag ---> runtime attribute generator of main.Test.x : S
452452
$s4main4TestAaBVmvpfaAA9OtherFlag ---> runtime attribute generator of main.Test : main.Test.Type for attribute = main.OtherFlag
453453
$s9MacroUser13testStringify1a1bySi_SitF9stringifyfMf1_ ---> freestanding macro expansion #3 of stringify in MacroUser.testStringify(a: Swift.Int, b: Swift.Int) -> ()
454454
$s9MacroUser016testFreestandingA9ExpansionyyF4Foo3L_V23bitwidthNumberedStructsfMf_6methodfMu0_ ---> unique name #2 of method in freestanding macro expansion #1 of bitwidthNumberedStructs in Foo3 #1 in MacroUser.testFreestandingMacroExpansion() -> ()
455+
@__swiftmacro_1a13testStringifyAA1bySi_SitF9stringifyfMf_ ---> freestanding macro expansion #1 of stringify in a.testStringify(a: Swift.Int, b: Swift.Int) -> ()

tools/swift-demangle/swift-demangle.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static bool findMaybeMangled(llvm::StringRef input, llvm::StringRef &match) {
271271
} state = Start;
272272
const char *matchStart = nullptr;
273273

274-
// Find _T, $S, $s, _$S, _$s followed by a valid mangled string
274+
// Find _T, $S, $s, _$S, _$s, @__swift_ followed by a valid mangled string
275275
while (ptr < end) {
276276
switch (state) {
277277
case Start:
@@ -286,6 +286,12 @@ static bool findMaybeMangled(llvm::StringRef input, llvm::StringRef &match) {
286286
state = SeenDollar;
287287
matchStart = ptr - 1;
288288
break;
289+
} else if (ch == '@' &&
290+
llvm::StringRef(ptr, end - ptr).startswith("__swiftmacro_")){
291+
matchStart = ptr - 1;
292+
ptr = ptr + strlen("__swift_");
293+
state = FoundPrefix;
294+
break;
289295
}
290296
}
291297
break;

0 commit comments

Comments
 (0)