[PATCH] D70284: Constant strings emitted when `-fno-constant-cfstrings` is passed should allow dead stripping
Ben D. Jones via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 14 20:47:50 PST 2019
bendjones updated this revision to Diff 229441.
bendjones added a comment.
Added `"objc_arc_inert"` and updated `clang/test/CodeGenObjC/ns-constant-strings.m` tests to make sure the section is emitted as we want.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D70284/new/
https://reviews.llvm.org/D70284
Files:
clang/lib/CodeGen/CGObjCMac.cpp
clang/test/CodeGenObjC/ns-constant-strings.m
Index: clang/test/CodeGenObjC/ns-constant-strings.m
===================================================================
--- clang/test/CodeGenObjC/ns-constant-strings.m
+++ clang/test/CodeGenObjC/ns-constant-strings.m
@@ -33,7 +33,14 @@
// CHECK-NONFRAGILE: @"OBJC_CLASS_$_NSConstantString" = external global
// CHECK-FRAGILE: @.str = private unnamed_addr constant [6 x i8] c"MyApp\00"
+// CHECK-FRAGILE: @_unnamed_nsstring_ = private constant %struct.__builtin_NSString { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_NSConstantStringClassReference, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i32 5 }, section "__OBJC,__cstring_object,regular"
// CHECK-FRAGILE: @.str.1 = private unnamed_addr constant [7 x i8] c"MyApp1\00"
+// CHECK-FRAGILE: @_unnamed_nsstring_.2 = private constant %struct.__builtin_NSString { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_NSConstantStringClassReference, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i32 6 }, section "__OBJC,__cstring_object,regular"
// CHECK-NONFRAGILE: @.str = private unnamed_addr constant [6 x i8] c"MyApp\00"
+// CHECK-NONFRAGILE: @_unnamed_nsstring_ = private constant %struct.__builtin_NSString { i32* bitcast (%struct._class_t* @"OBJC_CLASS_$_NSConstantString" to i32*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i32 5 }, section "__DATA,__objc_stringobj,regular"
// CHECK-NONFRAGILE: @.str.1 = private unnamed_addr constant [7 x i8] c"MyApp1\00"
+// CHECK-NONFRAGILE: @_unnamed_nsstring_.2 = private constant %struct.__builtin_NSString { i32* bitcast (%struct._class_t* @"OBJC_CLASS_$_NSConstantString" to i32*), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i32 6 }, section "__DATA,__objc_stringobj,regular"
+
+// CHECK-FRAGILE: attributes #0 = { "objc_arc_inert" }
+// CHECK-NONFRAGILE: attributes #0 = { "objc_arc_inert" }
\ No newline at end of file
Index: clang/lib/CodeGen/CGObjCMac.cpp
===================================================================
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1978,6 +1978,7 @@
return V;
}
+// This is only used when `-fno-constant-cfstrings` is given
ConstantAddress
CGObjCCommonMac::GenerateConstantNSString(const StringLiteral *Literal) {
unsigned StringLength = 0;
@@ -2029,13 +2030,12 @@
GV = Fields.finishAndCreateGlobal("_unnamed_nsstring_", Alignment,
/*constant*/ true,
llvm::GlobalVariable::PrivateLinkage);
- const char *NSStringSection = "__OBJC,__cstring_object,regular,no_dead_strip";
- const char *NSStringNonFragileABISection =
- "__DATA,__objc_stringobj,regular,no_dead_strip";
- // FIXME. Fix section.
+ const char *NSStringSection = "__OBJC,__cstring_object,regular";
+ const char *NSStringNonFragileABISection = "__DATA,__objc_stringobj,regular";
GV->setSection(CGM.getLangOpts().ObjCRuntime.isNonFragile()
? NSStringNonFragileABISection
: NSStringSection);
+ GV->addAttribute("objc_arc_inert");
Entry.second = GV;
return ConstantAddress(GV, Alignment);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70284.229441.patch
Type: text/x-patch
Size: 3230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191115/8878fdfe/attachment.bin>
More information about the cfe-commits
mailing list