Index: lib/IR/Mangler.cpp =================================================================== --- lib/IR/Mangler.cpp +++ lib/IR/Mangler.cpp @@ -115,6 +115,13 @@ StringRef Name = GV->getName(); char Prefix = DL->getGlobalPrefix(); + // Exit early if this is a Microsoft C++ name starting with '?'. In this + // mangling mode, we never apply prefixes or suffixes to these names. + if (DL->hasMicrosoftFastStdCallMangling() && Name.startswith("?")) { + OS << Name; + return; + } + // Mangle functions with Microsoft calling conventions specially. Only do // this mangling for x86_64 vectorcall and 32-bit x86. const Function *MSFunc = dyn_cast(GV); Index: test/MC/COFF/symbol-mangling.ll =================================================================== --- test/MC/COFF/symbol-mangling.ll +++ test/MC/COFF/symbol-mangling.ll @@ -4,14 +4,14 @@ ; RUN: llc -filetype=asm -mtriple i686-pc-win32 %s -o - | FileCheck %s -; CHECK: ?sayhi@A@@QBEXXZ +; CHECK: "?sayhi@A@@QBEXXZ" %struct.A = type {} define i32 @main() { entry: - tail call void @"\01?sayhi@A@@QBEXXZ"(%struct.A* null) + tail call void @"?sayhi@A@@QBEXXZ"(%struct.A* null) ret i32 0 } -declare void @"\01?sayhi@A@@QBEXXZ"(%struct.A*) +declare void @"?sayhi@A@@QBEXXZ"(%struct.A*) Index: test/MC/COFF/tricky-names.ll =================================================================== --- test/MC/COFF/tricky-names.ll +++ test/MC/COFF/tricky-names.ll @@ -4,13 +4,14 @@ ; Check that we can roundtrip these names through our assembler. ; RUN: llc -mtriple=i686-pc-win32 %s -o - | llvm-mc -triple i686-pc-win32 -filetype=obj | llvm-readobj -t | FileCheck %s --check-prefix=READOBJ +; We don't need the \01 prefix for MSVC symbols using ?. -@"\01??__E_Generic_object@?$_Error_objects@H@std@@YAXXZ" = global i32 0 +@"??__E_Generic_object@?$_Error_objects@H@std@@YAXXZ" = global i32 0 @"\01__ZL16ExceptionHandlerP19_EXCEPTION_POINTERS@4" = global i32 0 @"\01@foo.bar" = global i32 0 -define weak i32 @"\01??_B?$num_put@_WV?$back_insert_iterator@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@std@@@std@@51"() section ".text" { - %a = load i32* @"\01??__E_Generic_object@?$_Error_objects@H@std@@YAXXZ" +define weak i32 @"??_B?$num_put@_WV?$back_insert_iterator@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@std@@@std@@51"() section ".text" { + %a = load i32* @"??__E_Generic_object@?$_Error_objects@H@std@@YAXXZ" %b = load i32* @"\01__ZL16ExceptionHandlerP19_EXCEPTION_POINTERS@4" %c = load i32* @"\01@foo.bar" %x = add i32 %a, %b