ahatanak updated this revision to Diff 74760.
ahatanak added a comment.
Fold EmitScalarInit into EmitStoreThroughLValue and remove EmitScalarInit.
I don't think ElementType in EmitObjCCollectionLiteral has a lifetime
qualifier, so it should be safe to call EmitStoreThroughLValue instead of
EmitScalarInit in that function.
https://reviews.llvm.org/D25547
Files:
lib/CodeGen/CGDecl.cpp
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGObjC.cpp
lib/CodeGen/CGStmtOpenMP.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGenObjCXX/arc-constexpr.mm
Index: test/CodeGenObjCXX/arc-constexpr.mm
===================================================================
--- /dev/null
+++ test/CodeGenObjCXX/arc-constexpr.mm
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -o - -std=c++11 %s | FileCheck %s
+
+// CHECK: %[[TYPE:[a-z0-9]+]] = type opaque
+// CHECK: @[[CFSTRING:[a-z0-9_]+]] = private global %struct.__NSConstantString_tag
+
+// CHECK: define void @_Z5test1v
+// CHECK: %[[ALLOCA:[A-Z]+]] = alloca %[[TYPE]]*
+// CHECK: %[[V0:[0-9]+]] = call i8* @objc_retain(i8* bitcast (%struct.__NSConstantString_tag* @[[CFSTRING]]
+// CHECK: %[[V1:[0-9]+]] = bitcast i8* %[[V0]] to %[[TYPE]]*
+// CHECK: store %[[TYPE]]* %[[V1]], %[[TYPE]]** %[[ALLOCA]]
+// CHECK: %[[V2:[0-9]+]] = bitcast %[[TYPE]]** %[[ALLOCA]]
+// CHECK: call void @objc_storeStrong(i8** %[[V2]], i8* null)
+
+@class NSString;
+
+void test1() {
+ constexpr NSString *S = @"abc";
+}
Index: lib/CodeGen/CodeGenFunction.h
===================================================================
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -2118,7 +2118,6 @@
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue,
bool capturedByInit);
- void EmitScalarInit(llvm::Value *init, LValue lvalue);
typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D,
llvm::Value *Address);
Index: lib/CodeGen/CGStmtOpenMP.cpp
===================================================================
--- lib/CodeGen/CGStmtOpenMP.cpp
+++ lib/CodeGen/CGStmtOpenMP.cpp
@@ -188,7 +188,7 @@
auto *RefVal = TmpAddr.getPointer();
TmpAddr = CGF.CreateMemTemp(RefType, Twine(Name) + ".ref");
auto TmpLVal = CGF.MakeAddrLValue(TmpAddr, RefType);
- CGF.EmitScalarInit(RefVal, TmpLVal);
+ CGF.EmitStoreThroughLValue(RValue::get(RefVal), TmpLVal, true);
}
return TmpAddr;
@@ -2179,7 +2179,7 @@
llvm::Value *Init = nullptr) {
auto LVal = CGF.MakeAddrLValue(CGF.CreateMemTemp(Ty, Name), Ty);
if (Init)
- CGF.EmitScalarInit(Init, LVal);
+ CGF.EmitStoreThroughLValue(RValue::get(Init), LVal, true);
return LVal;
}
Index: lib/CodeGen/CGObjC.cpp
===================================================================
--- lib/CodeGen/CGObjC.cpp
+++ lib/CodeGen/CGObjC.cpp
@@ -1662,7 +1662,7 @@
elementLValue = EmitLValue(cast<Expr>(S.getElement()));
EmitStoreThroughLValue(RValue::get(CurrentItem), elementLValue);
} else {
- EmitScalarInit(CurrentItem, elementLValue);
+ EmitStoreThroughLValue(RValue::get(CurrentItem), elementLValue, true);
}
// If we do have an element variable, this assignment is the end of
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1620,6 +1620,34 @@
// There's special magic for assigning into an ARC-qualified l-value.
if (Qualifiers::ObjCLifetime Lifetime = Dst.getQuals().getObjCLifetime()) {
+ if (isInit) {
+ llvm::Value *Init = Src.getScalarVal();
+ switch (Lifetime) {
+ case Qualifiers::OCL_None:
+ llvm_unreachable("present but none");
+
+ case Qualifiers::OCL_ExplicitNone:
+ // nothing to do
+ break;
+
+ case Qualifiers::OCL_Strong:
+ Init = EmitARCRetain(Dst.getType(), Src.getScalarVal());
+ break;
+
+ case Qualifiers::OCL_Weak:
+ // Initialize and then skip the primitive store.
+ EmitARCInitWeak(Dst.getAddress(), Src.getScalarVal());
+ return;
+
+ case Qualifiers::OCL_Autoreleasing:
+ Init = EmitARCRetainAutorelease(Dst.getType(), Src.getScalarVal());
+ break;
+ }
+
+ EmitStoreOfScalar(Init, Dst, /* isInitialization */ true);
+ return;
+ }
+
switch (Lifetime) {
case Qualifiers::OCL_None:
llvm_unreachable("present but none");
Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -774,37 +774,6 @@
EmitStoreOfScalar(value, lvalue, /* isInitialization */ true);
}
-/// EmitScalarInit - Initialize the given lvalue with the given object.
-void CodeGenFunction::EmitScalarInit(llvm::Value *init, LValue lvalue) {
- Qualifiers::ObjCLifetime lifetime = lvalue.getObjCLifetime();
- if (!lifetime)
- return EmitStoreThroughLValue(RValue::get(init), lvalue, true);
-
- switch (lifetime) {
- case Qualifiers::OCL_None:
- llvm_unreachable("present but none");
-
- case Qualifiers::OCL_ExplicitNone:
- // nothing to do
- break;
-
- case Qualifiers::OCL_Strong:
- init = EmitARCRetain(lvalue.getType(), init);
- break;
-
- case Qualifiers::OCL_Weak:
- // Initialize and then skip the primitive store.
- EmitARCInitWeak(lvalue.getAddress(), init);
- return;
-
- case Qualifiers::OCL_Autoreleasing:
- init = EmitARCRetainAutorelease(lvalue.getType(), init);
- break;
- }
-
- EmitStoreOfScalar(init, lvalue, /* isInitialization */ true);
-}
-
/// canEmitInitWithFewStoresAfterMemset - Decide whether we can emit the
/// non-zero parts of the specified initializer with equal or fewer than
/// NumStores scalar stores.
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits