@@ -338,10 +338,11 @@ static const llvm::GlobalValue *getAliasedGlobal(const llvm::GlobalValue *GV) {
338
338
return FinalGV;
339
339
}
340
340
341
- static bool checkAliasedGlobal (DiagnosticsEngine &Diags,
342
- SourceLocation Location, bool IsIFunc,
343
- const llvm::GlobalValue *Alias,
344
- const llvm::GlobalValue *&GV) {
341
+ static bool checkAliasedGlobal (
342
+ DiagnosticsEngine &Diags, SourceLocation Location, bool IsIFunc,
343
+ const llvm::GlobalValue *Alias, const llvm::GlobalValue *&GV,
344
+ const llvm::MapVector<GlobalDecl, StringRef> &MangledDeclNames,
345
+ SourceRange AliasRange) {
345
346
GV = getAliasedGlobal (Alias);
346
347
if (!GV) {
347
348
Diags.Report (Location, diag::err_cyclic_alias) << IsIFunc;
@@ -350,6 +351,22 @@ static bool checkAliasedGlobal(DiagnosticsEngine &Diags,
350
351
351
352
if (GV->isDeclaration ()) {
352
353
Diags.Report (Location, diag::err_alias_to_undefined) << IsIFunc << IsIFunc;
354
+ Diags.Report (Location, diag::note_alias_requires_mangled_name)
355
+ << IsIFunc << IsIFunc;
356
+ // Provide a note if the given function is not found and exists as a
357
+ // mangled name.
358
+ for (const auto &[Decl, Name] : MangledDeclNames) {
359
+ if (const auto *ND = dyn_cast<NamedDecl>(Decl.getDecl ())) {
360
+ if (ND->getName () == GV->getName ()) {
361
+ Diags.Report (Location, diag::note_alias_mangled_name_alternative)
362
+ << Name
363
+ << FixItHint::CreateReplacement (
364
+ AliasRange,
365
+ (Twine (IsIFunc ? " ifunc" : " alias" ) + " (\" " + Name + " \" )" )
366
+ .str ());
367
+ }
368
+ }
369
+ }
353
370
return false ;
354
371
}
355
372
@@ -381,16 +398,19 @@ void CodeGenModule::checkAliases() {
381
398
for (const GlobalDecl &GD : Aliases) {
382
399
const auto *D = cast<ValueDecl>(GD.getDecl ());
383
400
SourceLocation Location;
401
+ SourceRange Range;
384
402
bool IsIFunc = D->hasAttr <IFuncAttr>();
385
- if (const Attr *A = D->getDefiningAttr ())
403
+ if (const Attr *A = D->getDefiningAttr ()) {
386
404
Location = A->getLocation ();
387
- else
405
+ Range = A->getRange ();
406
+ } else
388
407
llvm_unreachable (" Not an alias or ifunc?" );
389
408
390
409
StringRef MangledName = getMangledName (GD);
391
410
llvm::GlobalValue *Alias = GetGlobalValue (MangledName);
392
411
const llvm::GlobalValue *GV = nullptr ;
393
- if (!checkAliasedGlobal (Diags, Location, IsIFunc, Alias, GV)) {
412
+ if (!checkAliasedGlobal (Diags, Location, IsIFunc, Alias, GV,
413
+ MangledDeclNames, Range)) {
394
414
Error = true ;
395
415
continue ;
396
416
}
0 commit comments