'objc_arc_inert'
The attribute enables the ARC optimizer to delete ObjC ARC runtime calls
on the annotated globals (see https://reviews.llvm.org/D62433). We
currently only annotate global variables for string literals and global
blocks with the attribute.
rdar://problem/
49839633
Differential Revision: https://reviews.llvm.org/D62831
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363467
91177308-0d34-0410-b5e6-
96231b3b80d8
if (CGM.getContext().getLangOpts().OpenCL)
AddrSpace = CGM.getContext().getTargetAddressSpace(LangAS::opencl_global);
- llvm::Constant *literal = fields.finishAndCreateGlobal(
+ llvm::GlobalVariable *literal = fields.finishAndCreateGlobal(
"__block_literal_global", blockInfo.BlockAlign,
/*constant*/ !IsWindows, llvm::GlobalVariable::InternalLinkage, AddrSpace);
+ literal->addAttribute("objc_arc_inert");
+
// Windows does not allow globals to be initialised to point to globals in
// different DLLs. Any such variables must run code to initialise them.
if (IsWindows) {
GV = Fields.finishAndCreateGlobal("_unnamed_cfstring_", Alignment,
/*isConstant=*/false,
llvm::GlobalVariable::PrivateLinkage);
+ GV->addAttribute("objc_arc_inert");
switch (Triple.getObjectFormat()) {
case llvm::Triple::UnknownObjectFormat:
llvm_unreachable("unknown file format");
// CHECK: load i32, i32* %
// CHECK: ret i32 %
-// CHECK-LABEL: define internal i32* @_ZZZL20block_deduced_returnvEUb_EN1SclEv(%struct.S.6* %this) #0 align 2 {
+// CHECK-LABEL: define internal i32* @_ZZZL20block_deduced_returnvEUb_EN1SclEv(%struct.S.6* %this) #1 align 2 {
// CHECK: ret i32* @_ZZZL20block_deduced_returnvEUb_E1n
inline auto static_local_label(void *p) {
--- /dev/null
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: @{{.*}} = private global %{{.*}} { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @{{.*}}, i32 0, i32 0), i64 3 }, section "__DATA,__cfstring", align 8 #[[ATTRNUM0:[0-9]+]]
+// CHECK: @{{.*}} = internal constant { i8**, i32, i32, i8*, %{{.*}}* } { i8** @_NSConcreteGlobalBlock, i32 1342177280, i32 0, i8* bitcast (i32 (i8*)* @{{.*}} to i8*), %{{.*}}* bitcast ({ i64, i64, i8*, i8* }* @{{.*}} to %{{.*}}*) }, align 8 #[[ATTRNUM0]]
+
+@class NSString;
+
+NSString *testStringLiteral(void) {
+ return @"abc";
+}
+
+int testGlobalBlock(int a) {
+ return ^{ return 123; }();
+}
+
+// CHECK: attributes #[[ATTRNUM0]] = { "objc_arc_inert" }