[cfe-commits] r89028 - in /cfe/trunk: lib/CodeGen/CGCXXExpr.cpp lib/CodeGen/CGRtti.cpp lib/CodeGen/CodeGenModule.h test/CodeGenCXX/rtti.cpp
Mike Stump
mrs at apple.com
Mon Nov 16 18:16:22 PST 2009
Author: mrs
Date: Mon Nov 16 20:16:21 2009
New Revision: 89028
URL: http://llvm.org/viewvc/llvm-project?rev=89028&view=rev
Log:
Add typeid for the builtin types. WIP.
Modified:
cfe/trunk/lib/CodeGen/CGCXXExpr.cpp
cfe/trunk/lib/CodeGen/CGRtti.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/test/CodeGenCXX/rtti.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXXExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXExpr.cpp?rev=89028&r1=89027&r2=89028&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXXExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXXExpr.cpp Mon Nov 16 20:16:21 2009
@@ -347,7 +347,7 @@
QualType Ty = E->getType();
const llvm::Type *LTy = ConvertType(Ty)->getPointerTo();
if (E->isTypeOperand()) {
- QualType Ty = E->getTypeOperand();
+ Ty = E->getTypeOperand();
CanQualType CanTy = CGM.getContext().getCanonicalType(Ty);
Ty = CanTy.getUnqualifiedType().getNonReferenceType();
if (const RecordType *RT = Ty->getAs<RecordType>()) {
@@ -356,9 +356,7 @@
return Builder.CreateBitCast(CGM.GenerateRttiRef(RD), LTy);
return Builder.CreateBitCast(CGM.GenerateRtti(RD), LTy);
}
- // FIXME: return the rtti for the non-class static type.
- ErrorUnsupported(E, "typeid expression");
- return 0;
+ return Builder.CreateBitCast(CGM.GenerateRttiNonClass(Ty), LTy);
}
Expr *subE = E->getExprOperand();
if (const RecordType *RT = Ty->getAs<RecordType>()) {
@@ -397,11 +395,12 @@
V = Builder.CreateLoad(V);
return V;
}
- return CGM.GenerateRtti(RD);
+ return Builder.CreateBitCast(CGM.GenerateRtti(RD), LTy);
}
- // FIXME: return rtti for the non-class static type.
- ErrorUnsupported(E, "typeid expression");
- return 0;
+ Ty = subE->getType();
+ CanQualType CanTy = CGM.getContext().getCanonicalType(Ty);
+ Ty = CanTy.getUnqualifiedType().getNonReferenceType();
+ return Builder.CreateBitCast(CGM.GenerateRttiNonClass(Ty), LTy);
}
llvm::Value *CodeGenFunction::EmitDynamicCast(llvm::Value *V,
Modified: cfe/trunk/lib/CodeGen/CGRtti.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRtti.cpp?rev=89028&r1=89027&r2=89028&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRtti.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRtti.cpp Mon Nov 16 20:16:21 2009
@@ -76,7 +76,7 @@
return llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), c);
}
- llvm::Constant *Buildclass_type_infoRef(const CXXRecordDecl *RD) {
+ llvm::Constant *BuildTypeRef(QualType Ty) {
const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext);
llvm::Constant *C;
@@ -85,8 +85,7 @@
llvm::SmallString<256> OutName;
llvm::raw_svector_ostream Out(OutName);
- mangleCXXRtti(CGM.getMangleContext(), CGM.getContext().getTagDeclType(RD),
- Out);
+ mangleCXXRtti(CGM.getMangleContext(), Ty, Out);
C = CGM.getModule().getGlobalVariable(Out.str());
if (C)
@@ -100,6 +99,10 @@
return llvm::ConstantExpr::getBitCast(C, Int8PtrTy);
}
+ llvm::Constant *Buildclass_type_infoRef(const CXXRecordDecl *RD) {
+ return BuildTypeRef(CGM.getContext().getTagDeclType(RD));
+ }
+
/// CalculateFlags - Calculate the flags for the __vmi_class_type_info
/// datastructure. 1 for non-diamond repeated inheritance, 2 for a dimond
/// shaped class.
@@ -234,6 +237,24 @@
return Rtti;
#endif
}
+
+ llvm::Constant *BuildType(QualType Ty) {
+ const clang::Type &Type
+ = *CGM.getContext().getCanonicalType(Ty).getTypePtr();
+ switch (Type.getTypeClass()) {
+ default: {
+ // FIXME: Add all the missing types, such as pointer, array...
+ assert(0 && "typeid expression");
+ const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext);
+ return llvm::Constant::getNullValue(Int8PtrTy);
+ }
+
+ case Type::Builtin: {
+ // We expect all type_info objects for builtin types to be in the library.
+ return BuildTypeRef(Ty);
+ }
+ }
+ }
};
llvm::Constant *CodeGenModule::GenerateRttiRef(const CXXRecordDecl *RD) {
@@ -247,3 +268,9 @@
return b.Buildclass_type_info(RD);
}
+
+llvm::Constant *CodeGenModule::GenerateRttiNonClass(QualType Ty) {
+ RttiBuilder b(*this);
+
+ return b.BuildType(Ty);
+}
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=89028&r1=89027&r2=89028&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Nov 16 20:16:21 2009
@@ -229,6 +229,9 @@
/// GenerateRttiRef - Generate a reference to the rtti information for the
/// given type.
llvm::Constant *GenerateRttiRef(const CXXRecordDecl *RD);
+ /// GenerateRttiNonClass - Generate the rtti information for the given
+ /// non-class type.
+ llvm::Constant *GenerateRttiNonClass(QualType Ty);
/// BuildThunk - Build a thunk for the given method
llvm::Constant *BuildThunk(const CXXMethodDecl *MD, bool Extern, int64_t nv,
Modified: cfe/trunk/test/CodeGenCXX/rtti.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/rtti.cpp?rev=89028&r1=89027&r2=89028&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/rtti.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/rtti.cpp Mon Nov 16 20:16:21 2009
@@ -104,6 +104,8 @@
test2_1();
if (typeid(((*(dp)))) == typeid(test1_D))
test2_1();
+ if (typeid(int) == typeid(float))
+ test2_1();
}
// CHECK-LL:define void @_Z7test2_2P7test1_D(%class.test1_B7* %dp) nounwind {
@@ -127,3 +129,5 @@
// CHECK-LL-NEXT: %7 = getelementptr inbounds %"class.std::type_info"** %vtable6, i64 -1
// CHECK-LL-NEXT: %8 = load %"class.std::type_info"** %7
// CHECK-LL-NEXT: %call7 = call zeroext i1 @_ZNKSt9type_infoeqERKS_(%"class.std::type_info"* %8, %"class.std::type_info"* bitcast (%1* @_ZTI7test1_D to %"class.std::type_info"*))
+
+// CHECK-LL: %call10 = call zeroext i1 @_ZNKSt9type_infoeqERKS_(%"class.std::type_info"* bitcast (i8** @_ZTIi to %"class.std::type_info"*), %"class.std::type_info"* bitcast (i8** @_ZTIf to %"class.std::type_info"*)) ; <i1> [#uses=1]
More information about the cfe-commits
mailing list