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
This commit is contained in:
Adrian Prantl
2022-12-19 09:18:08 -08:00
parent 244ca4e242
commit 9e22b70cff
2 changed files with 7 additions and 3 deletions

View File

@@ -60,6 +60,7 @@ ParameterList *ParameterList::clone(const ASTContext &C,
SmallVector<ParamDecl*, 8> 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.

View File

@@ -30,7 +30,7 @@ public class Base<In, Out> {
public class Derived<T> : Base<T, T> {
// CHECK-NEXT: override public init(x: @escaping (T) -> T)
// CHECK-NEXT: override public init<A>(_ a1: A, _ a2: A)
// CHECK-NEXT: override public init<C>(_ argument: C) where C : main.Base<T, T>
// CHECK-NEXT: override public init<C>(_ __argument1: C) where C : main.Base<T, T>
// CHECK-NEXT: {{(@objc )?}}deinit
// CHECK-NEXT: }
}