[cfe-commits] r78536 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp lib/CodeGen/CGExprScalar.cpp lib/CodeGen/CodeGenFunction.cpp test/CodeGenCXX/member-pointers-zero-init.cpp
Anders Carlsson
andersca at mac.com
Sun Aug 9 11:26:28 PDT 2009
Author: andersca
Date: Sun Aug 9 13:26:27 2009
New Revision: 78536
URL: http://llvm.org/viewvc/llvm-project?rev=78536&view=rev
Log:
Improve handling of member pointers.
Added:
cfe/trunk/test/CodeGenCXX/member-pointers-zero-init.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=78536&r1=78535&r2=78536&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sun Aug 9 13:26:27 2009
@@ -773,7 +773,27 @@
}
llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
- // Always return an LLVM null constant for now; this will change when we
- // get support for IRGen of member pointers.
+ if (const ConstantArrayType *CAT = Context.getAsConstantArrayType(T)) {
+
+ QualType ElementTy = CAT->getElementType();
+
+ // FIXME: Handle arrays of structs that contain member pointers.
+ if (Context.getBaseElementType(ElementTy)->isMemberPointerType()) {
+ llvm::Constant *Element = EmitNullConstant(ElementTy);
+ uint64_t NumElements = CAT->getSize().getZExtValue();
+ std::vector<llvm::Constant *> Array(NumElements);
+ for (uint64_t i = 0; i != NumElements; ++i)
+ Array[i] = Element;
+
+ const llvm::ArrayType *ATy =
+ cast<llvm::ArrayType>(getTypes().ConvertTypeForMem(T));
+ return llvm::ConstantArray::get(ATy, Array);
+ }
+ }
+
+ // FIXME: Handle structs that contain member pointers.
+ if (T->isMemberPointerType())
+ return llvm::Constant::getAllOnesValue(getTypes().ConvertTypeForMem(T));
+
return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T));
}
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=78536&r1=78535&r2=78536&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sun Aug 9 13:26:27 2009
@@ -391,6 +391,14 @@
return Builder.CreateFCmpUNE(Src, Zero, "tobool");
}
+ if (SrcType->isMemberPointerType()) {
+ // FIXME: This is ABI specific.
+
+ // Compare against -1.
+ llvm::Value *NegativeOne = llvm::Constant::getAllOnesValue(Src->getType());
+ return Builder.CreateICmpNE(Src, NegativeOne, "tobool");
+ }
+
assert((SrcType->isIntegerType() || isa<llvm::PointerType>(Src->getType())) &&
"Unknown scalar type to convert");
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=78536&r1=78535&r2=78536&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sun Aug 9 13:26:27 2009
@@ -68,9 +68,9 @@
bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
// FIXME: Use positive checks instead of negative ones to be more robust in
// the face of extension.
- return !T->hasPointerRepresentation() &&!T->isRealType() &&
+ return !T->hasPointerRepresentation() && !T->isRealType() &&
!T->isVoidType() && !T->isVectorType() && !T->isFunctionType() &&
- !T->isBlockPointerType();
+ !T->isBlockPointerType() && !T->isMemberPointerType();
}
void CodeGenFunction::EmitReturnBlock() {
Added: cfe/trunk/test/CodeGenCXX/member-pointers-zero-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-pointers-zero-init.cpp?rev=78536&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-pointers-zero-init.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/member-pointers-zero-init.cpp Sun Aug 9 13:26:27 2009
@@ -0,0 +1,24 @@
+// RUN: clang-cc -emit-llvm %s -o %t -triple=x86_64-apple-darwin9 &&
+
+struct A {
+ int i;
+};
+
+// RUN: grep "@a = global i64 -1" %t &&
+int A::* a;
+
+// RUN: grep "@aa = global \[2 x i64\] \[i64 -1, i64 -1\], align 8" %t &&
+int A::* aa[2];
+
+// RUN: grep "@aaa = global \[2 x \[2 x i64\]\] \[\[2 x i64\] \[i64 -1, i64 -1\], \[2 x i64\] \[i64 -1, i64 -1\]\]" %t &&
+int A::* aaa[2][2];
+
+void f() {
+ // RUN: grep "%.obool = icmp ne i64 %.mp, -1" %t
+ if (a) { }
+
+ // FIXME: This doesn't yet work
+// if (a != 0) { }
+
+}
+
More information about the cfe-commits
mailing list