From 9e22b70cff5e7533bae87aed2b938cf43ede3051 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Mon, 19 Dec 2022 09:18:08 -0800 Subject: [PATCH] Ensure unique names in ParameterList::clone() IRGenDebugInfo assumes that all argument names within the same scope are unique as it uses them as a key in a hash table. rdar://102367872 --- lib/AST/Parameter.cpp | 8 ++++++-- test/ModuleInterface/inherited-generic-parameters.swift | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/AST/Parameter.cpp b/lib/AST/Parameter.cpp index b4918f0d5b9..52ec46fe7cd 100644 --- a/lib/AST/Parameter.cpp +++ b/lib/AST/Parameter.cpp @@ -60,6 +60,7 @@ ParameterList *ParameterList::clone(const ASTContext &C, SmallVector params(begin(), end()); // Remap the ParamDecls inside of the ParameterList. + unsigned i = 0; for (auto &decl : params) { auto defaultArgKind = decl->getDefaultArgumentKind(); @@ -69,8 +70,11 @@ ParameterList *ParameterList::clone(const ASTContext &C, // If the argument isn't named, give the parameter a name so that // silgen will produce a value for it. - if (decl->getName().empty() && (options & NamedArguments)) - decl->setName(C.getIdentifier("argument")); + if (decl->getName().empty() && (options & NamedArguments)) { + llvm::SmallString<16> s; + { llvm::raw_svector_ostream(s) << "__argument" << ++i; } + decl->setName(C.getIdentifier(s)); + } // If we're inheriting a default argument, mark it as such. // FIXME: Figure out how to clone default arguments as well. diff --git a/test/ModuleInterface/inherited-generic-parameters.swift b/test/ModuleInterface/inherited-generic-parameters.swift index 1974d92452f..a64203d7f47 100644 --- a/test/ModuleInterface/inherited-generic-parameters.swift +++ b/test/ModuleInterface/inherited-generic-parameters.swift @@ -30,7 +30,7 @@ public class Base { public class Derived : Base { // CHECK-NEXT: override public init(x: @escaping (T) -> T) // CHECK-NEXT: override public init(_ a1: A, _ a2: A) -// CHECK-NEXT: override public init(_ argument: C) where C : main.Base +// CHECK-NEXT: override public init(_ __argument1: C) where C : main.Base // CHECK-NEXT: {{(@objc )?}}deinit // CHECK-NEXT: } }