[cfe-commits] r170837 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/cxx0x-initializer-array.cpp test/CodeGenCXX/value-init.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Thu Dec 20 19:17:28 PST 2012
Author: rsmith
Date: Thu Dec 20 21:17:28 2012
New Revision: 170837
URL: http://llvm.org/viewvc/llvm-project?rev=170837&view=rev
Log:
Reinstate r170806, reverted in r170835, with a fix use i1 instead of i8 for a value-initialized bool!
Modified:
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGenCXX/cxx0x-initializer-array.cpp
cfe/trunk/test/CodeGenCXX/value-init.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=170837&r1=170836&r2=170837&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu Dec 20 21:17:28 2012
@@ -931,7 +931,7 @@
// FIXME: Are initializers affected by volatile?
if (Dest.isZeroed() && isSimpleZero(E, CGF)) {
// Storing "i32 0" to a zero'd memory location is a noop.
- } else if (isa<ImplicitValueInitExpr>(E)) {
+ } else if (isa<ImplicitValueInitExpr>(E) || isa<CXXScalarValueInitExpr>(E)) {
EmitNullInitializationToLValue(LV);
} else if (type->isReferenceType()) {
RValue RV = CGF.EmitReferenceBindingToExpr(E, /*InitializedDecl=*/0);
@@ -960,8 +960,8 @@
return;
if (!CGF.hasAggregateLLVMType(type)) {
- // For non-aggregates, we can store zero.
- llvm::Value *null = llvm::Constant::getNullValue(CGF.ConvertType(type));
+ // For non-aggregates, we can store the appropriate null constant.
+ llvm::Value *null = CGF.CGM.EmitNullConstant(type);
// Note that the following is not equivalent to
// EmitStoreThroughBitfieldLValue for ARC types.
if (lv.isBitField()) {
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=170837&r1=170836&r2=170837&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Dec 20 21:17:28 2012
@@ -266,7 +266,7 @@
Value *VisitInitListExpr(InitListExpr *E);
Value *VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
- return CGF.CGM.EmitNullConstant(E->getType());
+ return EmitNullValue(E->getType());
}
Value *VisitExplicitCastExpr(ExplicitCastExpr *E) {
if (E->getType()->isVariablyModifiedType())
@@ -800,10 +800,7 @@
}
Value *ScalarExprEmitter::EmitNullValue(QualType Ty) {
- if (const MemberPointerType *MPT = Ty->getAs<MemberPointerType>())
- return CGF.CGM.getCXXABI().EmitNullMemberPointer(MPT);
-
- return llvm::Constant::getNullValue(ConvertType(Ty));
+ return CGF.EmitFromMemory(CGF.CGM.EmitNullConstant(Ty), Ty);
}
/// \brief Emit a sanitization check for the given "binary" operation (which
Modified: cfe/trunk/test/CodeGenCXX/cxx0x-initializer-array.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx0x-initializer-array.cpp?rev=170837&r1=170836&r2=170837&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx0x-initializer-array.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx0x-initializer-array.cpp Thu Dec 20 21:17:28 2012
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 -S -emit-llvm -o - %s | FileCheck %s
+// CHECK: @[[THREE_NULL_MEMPTRS:.*]] = private constant [3 x i32] [i32 -1, i32 -1, i32 -1]
+
struct A { int a[1]; };
typedef A x[];
int f() {
@@ -7,4 +9,42 @@
// CHECK: define i32 @_Z1fv
// CHECK: store i32 1
// (It's okay if the output changes here, as long as we don't crash.)
+ return 0;
+}
+
+namespace ValueInitArrayOfMemPtr {
+ struct S {};
+ typedef int (S::*p);
+ typedef p a[3];
+ void f(const a &);
+
+ struct Agg1 {
+ int n;
+ p x;
+ };
+
+ struct Agg2 {
+ int n;
+ a x;
+ };
+
+ struct S1 {
+ p x;
+ S1();
+ };
+
+ // CHECK: define void @_ZN22ValueInitArrayOfMemPtr1fEi
+ void f(int n) {
+ Agg1 a = { n };
+ // CHECK: store i32 -1,
+
+ Agg2 b = { n };
+ // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %{{.*}}, i8* bitcast ([3 x i32]* @[[THREE_NULL_MEMPTRS]] to i8*), i32 12, i32 4, i1 false)
+ }
+
+ // CHECK: define void @_ZN22ValueInitArrayOfMemPtr1gEv
+ void g() {
+ // CHECK: store i32 -1,
+ f(a{});
+ }
}
Modified: cfe/trunk/test/CodeGenCXX/value-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/value-init.cpp?rev=170837&r1=170836&r2=170837&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/value-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/value-init.cpp Thu Dec 20 21:17:28 2012
@@ -256,6 +256,12 @@
// CHECK-NEXT: call void @_ZN7PR111242B2C2Ev
}
+// Ensure we produce an i1 here, and don't assert.
+// CHECK: define void @_Z9r170806_bv(
+// CHECK: call void @_Z9r170806_ab(i1 zeroext false)
+void r170806_a(bool b = bool());
+void r170806_b() { r170806_a(); }
+
// CHECK: define linkonce_odr void @_ZN8zeroinit2X3IiEC2Ev(%"struct.zeroinit::X3"* %this) unnamed_addr
// CHECK: call void @llvm.memset.p0i8.i64
// CHECK-NEXT: call void @_ZN8zeroinit2X2IiEC2Ev
More information about the cfe-commits
mailing list