Author: Abhina Sree Date: 2026-02-05T08:18:00-05:00 New Revision: f0a4a91f1b49d77fe28d71363eed02dd8b9003e2
URL: https://github.com/llvm/llvm-project/commit/f0a4a91f1b49d77fe28d71363eed02dd8b9003e2 DIFF: https://github.com/llvm/llvm-project/commit/f0a4a91f1b49d77fe28d71363eed02dd8b9003e2.diff LOG: [SystemZ][z/OS] Support both EBCDIC & ASCII form of type_info::name() (#179687) On z/OS, typename is stored as 2 encodings: EBCDIC (default system encoding) followed by ASCII. Added: clang/test/CodeGenCXX/zos-typename.cpp Modified: clang/lib/CodeGen/ItaniumCXXABI.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index a6c80cd083bb8..e3e071d827b92 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -35,6 +35,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/Value.h" +#include "llvm/Support/ConvertEBCDIC.h" #include "llvm/Support/ScopedPrinter.h" #include <optional> @@ -3619,8 +3620,17 @@ llvm::GlobalVariable *ItaniumRTTIBuilder::GetAddrOfTypeName( // We know that the mangled name of the type starts at index 4 of the // mangled name of the typename, so we can just index into it in order to // get the mangled name of the type. - llvm::Constant *Init = llvm::ConstantDataArray::getString(VMContext, - Name.substr(4)); + llvm::Constant *Init; + if (CGM.getTriple().isOSzOS()) { + // On z/OS, typename is stored as 2 encodings: EBCDIC followed by ASCII. + SmallString<256> DualEncodedName; + llvm::ConverterEBCDIC::convertToEBCDIC(Name.substr(4), DualEncodedName); + DualEncodedName += '\0'; + DualEncodedName += Name.substr(4); + Init = llvm::ConstantDataArray::getString(VMContext, DualEncodedName); + } else + Init = llvm::ConstantDataArray::getString(VMContext, Name.substr(4)); + auto Align = CGM.getContext().getTypeAlignInChars(CGM.getContext().CharTy); llvm::GlobalVariable *GV = CGM.CreateOrReplaceCXXRuntimeVariable( diff --git a/clang/test/CodeGenCXX/zos-typename.cpp b/clang/test/CodeGenCXX/zos-typename.cpp new file mode 100644 index 0000000000000..dabb9cc25ae60 --- /dev/null +++ b/clang/test/CodeGenCXX/zos-typename.cpp @@ -0,0 +1,14 @@ +// RUN: %clang -S -emit-llvm -target s390x-none-zos -I%S -fexec-charset=UTF-8 %s -o - | FileCheck %s +// RUN: %clang -S -emit-llvm -target s390x-none-zos -I%S %s -o - | FileCheck %s +// RUN: %clang -S -emit-llvm -target s390x-none-zos -I%S -m32 %s -o - | FileCheck %s + +#include <typeinfo> + +class TestClass {}; +struct TestStruct {}; + +const char *A = typeid(TestClass).name(); +const char *B = typeid(TestStruct).name(); + +// CHECK: @_ZTS9TestClass = {{.*}} c"\F9\E3\85\A2\A3\C3\93\81\A2\A2\009TestClass\00" +// CHECK: @_ZTS10TestStruct = {{.*}} c"\F1\F0\E3\85\A2\A3\E2\A3\99\A4\83\A3\0010TestStruct\00" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
