@@ -291,39 +291,40 @@ void llvm::emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV,
291
291
}
292
292
293
293
std::optional<std::string> llvm::getArm64ECMangledFunctionName (StringRef Name) {
294
- bool IsCppFn = Name[0 ] == ' ?' ;
295
- if (IsCppFn && Name.contains (" $$h" ))
296
- return std::nullopt;
297
- if (!IsCppFn && Name[0 ] == ' #' )
298
- return std::nullopt;
294
+ if (Name[0 ] != ' ?' ) {
295
+ // For non-C++ symbols, prefix the name with "#" unless it's already
296
+ // mangled.
297
+ if (Name[0 ] == ' #' )
298
+ return std::nullopt;
299
+ return std::optional<std::string>((" #" + Name).str ());
300
+ }
299
301
300
- StringRef Prefix = " $$h" ;
301
- size_t InsertIdx = 0 ;
302
- if (IsCppFn) {
303
- InsertIdx = Name.find (" @@" );
304
- size_t ThreeAtSignsIdx = Name.find (" @@@" );
305
- if (InsertIdx != std::string::npos && InsertIdx != ThreeAtSignsIdx) {
306
- InsertIdx += 2 ;
307
- } else {
308
- InsertIdx = Name.find (" @" );
309
- if (InsertIdx != std::string::npos)
310
- InsertIdx++;
311
- }
302
+ // Insert the ARM64EC "$$h" tag after the mangled function name.
303
+ if (Name.contains (" $$h" ))
304
+ return std::nullopt;
305
+ size_t InsertIdx = Name.find (" @@" );
306
+ size_t ThreeAtSignsIdx = Name.find (" @@@" );
307
+ if (InsertIdx != std::string::npos && InsertIdx != ThreeAtSignsIdx) {
308
+ InsertIdx += 2 ;
312
309
} else {
313
- Prefix = " #" ;
310
+ InsertIdx = Name.find (" @" );
311
+ if (InsertIdx != std::string::npos)
312
+ InsertIdx++;
314
313
}
315
314
316
315
return std::optional<std::string>(
317
- (Name.substr (0 , InsertIdx) + Prefix + Name.substr (InsertIdx)).str ());
316
+ (Name.substr (0 , InsertIdx) + " $$h " + Name.substr (InsertIdx)).str ());
318
317
}
319
318
320
319
std::optional<std::string>
321
320
llvm::getArm64ECDemangledFunctionName (StringRef Name) {
321
+ // For non-C++ names, drop the "#" prefix.
322
322
if (Name[0 ] == ' #' )
323
323
return std::optional<std::string>(Name.substr (1 ));
324
324
if (Name[0 ] != ' ?' )
325
325
return std::nullopt;
326
326
327
+ // Drop the ARM64EC "$$h" tag.
327
328
std::pair<StringRef, StringRef> Pair = Name.split (" $$h" );
328
329
if (Pair.second .empty ())
329
330
return std::nullopt;
0 commit comments