summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2014-02-08 03:26:05 +0000
committerJohn McCall <rjmccall@apple.com>2014-02-08 03:26:05 +0000
commit57420b320cd989b49e6a458b129b3262834ad589 (patch)
treefeb8a523ecdae34b8c09cfecd276abcc8520e7b5 /clang/lib
parent42063b0b1cc6dfb91fca302ac1a1e3432287ba32 (diff)
downloadbcm5719-llvm-57420b320cd989b49e6a458b129b3262834ad589.tar.gz
bcm5719-llvm-57420b320cd989b49e6a458b129b3262834ad589.zip
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 llvm-svn: 201020
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGRTTI.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CGRTTI.cpp b/clang/lib/CodeGen/CGRTTI.cpp
index 351b9fc4e27..455ee972f5c 100644
--- a/clang/lib/CodeGen/CGRTTI.cpp
+++ b/clang/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);
}
OpenPOWER on IntegriCloud