diff options
author | Reid Kleckner <rnk@google.com> | 2016-08-25 22:16:30 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2016-08-25 22:16:30 +0000 |
commit | d8b0466e19df2be3d635ca4e23c92c3d28d1b935 (patch) | |
tree | 7dfacb1c5140f07f54c06f7fec1bf451d223fbc1 | |
parent | 6e271f4ce8c438f1cff01a40fadb24d52b3d47fa (diff) | |
download | llvm-d8b0466e19df2be3d635ca4e23c92c3d28d1b935.zip llvm-d8b0466e19df2be3d635ca4e23c92c3d28d1b935.tar.gz llvm-d8b0466e19df2be3d635ca4e23c92c3d28d1b935.tar.bz2 |
Widen type of __offset_flags in RTTI on Mingw64
Otherwise we can't handle secondary base classes at offsets greater than
2**24. This agrees with libstdc++abi.
We could extend this change to other LLP64 platforms, but then we would
want to update libc++abi and it would require additional review.
Fixes PR29116
llvm-svn: 279786
-rw-r--r-- | clang/lib/CodeGen/ItaniumCXXABI.cpp | 18 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/rtti-mingw64.cpp | 13 |
2 files changed, 27 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index 2492c82..ecf4d04 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -3217,9 +3217,6 @@ void ItaniumRTTIBuilder::BuildVMIClassTypeInfo(const CXXRecordDecl *RD) { if (!RD->getNumBases()) return; - llvm::Type *LongLTy = - CGM.getTypes().ConvertType(CGM.getContext().LongTy); - // Now add the base class descriptions. // Itanium C++ ABI 2.9.5p6c: @@ -3237,6 +3234,19 @@ void ItaniumRTTIBuilder::BuildVMIClassTypeInfo(const CXXRecordDecl *RD) { // __offset_shift = 8 // }; // }; + + // If we're in mingw and 'long' isn't wide enough for a pointer, use 'long + // long' instead of 'long' for __offset_flags. libstdc++abi uses long long on + // LLP64 platforms. + // FIXME: Consider updating libc++abi to match, and extend this logic to all + // LLP64 platforms. + QualType OffsetFlagsTy = CGM.getContext().LongTy; + const TargetInfo &TI = CGM.getContext().getTargetInfo(); + if (TI.getTriple().isOSCygMing() && TI.getPointerWidth(0) > TI.getLongWidth()) + OffsetFlagsTy = CGM.getContext().LongLongTy; + llvm::Type *OffsetFlagsLTy = + CGM.getTypes().ConvertType(OffsetFlagsTy); + for (const auto &Base : RD->bases()) { // The __base_type member points to the RTTI for the base type. Fields.push_back(ItaniumRTTIBuilder(CXXABI).BuildTypeInfo(Base.getType())); @@ -3268,7 +3278,7 @@ void ItaniumRTTIBuilder::BuildVMIClassTypeInfo(const CXXRecordDecl *RD) { if (Base.getAccessSpecifier() == AS_public) OffsetFlags |= BCTI_Public; - Fields.push_back(llvm::ConstantInt::get(LongLTy, OffsetFlags)); + Fields.push_back(llvm::ConstantInt::get(OffsetFlagsLTy, OffsetFlags)); } } diff --git a/clang/test/CodeGenCXX/rtti-mingw64.cpp b/clang/test/CodeGenCXX/rtti-mingw64.cpp new file mode 100644 index 0000000..818b11b --- /dev/null +++ b/clang/test/CodeGenCXX/rtti-mingw64.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -emit-llvm -o - | FileCheck %s +struct A { int a; }; +struct B : virtual A { int b; }; +B b; + +// CHECK: @_ZTI1B = linkonce_odr constant { i8*, i8*, i32, i32, i8*, i64 } +// CHECK-SAME: i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv121__vmi_class_type_infoE, i64 2) to i8*), +// CHECK-SAME: i8* getelementptr inbounds ([3 x i8], [3 x i8]* @_ZTS1B, i32 0, i32 0), +// CHECK-SAME: i32 0, +// CHECK-SAME: i32 1, +// CHECK-SAME: i8* bitcast ({ i8*, i8* }* @_ZTI1A to i8*), +// This i64 is important, it should be an i64, not an i32. +// CHECK-SAME: i64 -6141 }, comdat |