diff options
author | John McCall <rjmccall@apple.com> | 2014-02-08 03:26:05 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2014-02-08 03:26:05 +0000 |
commit | c174fe5f125f749eaf5ea7cc41f3cbf049bc5ada (patch) | |
tree | 9d086cbc77218e1c495517c49852eeedfe230477 /lib/CodeGen/CGRTTI.cpp | |
parent | da8b957aca16ce42731cc3e7d16abc63d8b77b95 (diff) | |
download | clang-c174fe5f125f749eaf5ea7cc41f3cbf049bc5ada.tar.gz clang-c174fe5f125f749eaf5ea7cc41f3cbf049bc5ada.tar.bz2 clang-c174fe5f125f749eaf5ea7cc41f3cbf049bc5ada.tar.xz |
type_info objects are not unnamed_addr: the ABI requires us to
unique them and permits the implementation of dynamic_cast (and
anything else which knows it's working with a complete class
type) to compare their addresses directly.
rdar://16005328
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201020 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGRTTI.cpp')
-rw-r--r-- | lib/CodeGen/CGRTTI.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/CodeGen/CGRTTI.cpp b/lib/CodeGen/CGRTTI.cpp index 351b9fc4e2..455ee972f5 100644 --- a/lib/CodeGen/CGRTTI.cpp +++ b/lib/CodeGen/CGRTTI.cpp @@ -644,6 +644,21 @@ llvm::Constant *RTTIBuilder::BuildTypeInfo(QualType Ty, bool Force) { OldGV->eraseFromParent(); } + // The Itanium ABI specifies that type_info objects must be globally + // unique, with one exception: if the type is an incomplete class + // type or a (possibly indirect) pointer to one. That exception + // affects the general case of comparing type_info objects produced + // by the typeid operator, which is why the comparison operators on + // std::type_info generally use the type_info name pointers instead + // of the object addresses. However, the language's built-in uses + // of RTTI generally require class types to be complete, even when + // manipulating pointers to those class types. This allows the + // implementation of dynamic_cast to rely on address equality tests, + // which is much faster. + + // All of this is to say that it's important that both the type_info + // object and the type_info name be uniqued when weakly emitted. + // Give the type_info object and name the formal visibility of the // type itself. Visibility formalVisibility = Ty->getVisibility(); @@ -652,14 +667,6 @@ llvm::Constant *RTTIBuilder::BuildTypeInfo(QualType Ty, bool Force) { TypeName->setVisibility(llvmVisibility); GV->setVisibility(llvmVisibility); - // Contra the Itanium ABI, we do not rely or guarantee strict - // address-equivalence of type_info objects. - // - // The main effect of setting this flag is that LLVM will - // automatically decrease the visibility of linkonce_odr type_info - // objects. - GV->setUnnamedAddr(true); - return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy); } |