r281997 - CodeGen: further merge cstring literal construction
Saleem Abdulrasool via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 20 11:38:54 PDT 2016
Author: compnerd
Date: Tue Sep 20 13:38:54 2016
New Revision: 281997
URL: http://llvm.org/viewvc/llvm-project?rev=281997&view=rev
Log:
CodeGen: further merge cstring literal construction
Use the new CreateCStringLiteral in an additional site. Now all the C string
literals are created in one function. Furthermore, mark the additional literal
as an `unnamed_addr constant`.
Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=281997&r1=281996&r2=281997&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Sep 20 13:38:54 2016
@@ -1026,7 +1026,9 @@ public:
bool AddToUsed);
llvm::GlobalVariable *CreateCStringLiteral(StringRef Name,
- ObjCLabelType LabelType);
+ ObjCLabelType LabelType,
+ bool ForceNonFragileABI = false,
+ bool NullTerminate = true);
protected:
CodeGen::RValue EmitMessageSend(CodeGen::CodeGenFunction &CGF,
@@ -2586,10 +2588,9 @@ llvm::Constant *CGObjCCommonMac::getBitm
}
}
- llvm::GlobalVariable *Entry = CreateMetadataVar(
- "OBJC_CLASS_NAME_",
- llvm::ConstantDataArray::getString(VMContext, BitMap, false),
- "__TEXT,__objc_classname,cstring_literals", CharUnits::One(), true);
+ auto *Entry = CreateCStringLiteral(BitMap, ObjCLabelType::ClassName,
+ /*ForceNonFragileABI=*/true,
+ /*NullTerminate=*/false);
return getConstantGEP(VMContext, Entry, 0, 0);
}
@@ -3661,7 +3662,9 @@ llvm::GlobalVariable *CGObjCCommonMac::C
}
llvm::GlobalVariable *
-CGObjCCommonMac::CreateCStringLiteral(StringRef Name, ObjCLabelType Type) {
+CGObjCCommonMac::CreateCStringLiteral(StringRef Name, ObjCLabelType Type,
+ bool ForceNonFragileABI,
+ bool NullTerminate) {
StringRef Label;
switch (Type) {
case ObjCLabelType::ClassName: Label = "OBJC_CLASS_NAME_"; break;
@@ -3670,26 +3673,29 @@ CGObjCCommonMac::CreateCStringLiteral(St
case ObjCLabelType::PropertyName: Label = "OBJC_PROP_NAME_ATTR_"; break;
}
+ bool NonFragile = ForceNonFragileABI || isNonFragileABI();
+
StringRef Section;
switch (Type) {
case ObjCLabelType::ClassName:
- Section = isNonFragileABI() ? "__TEXT,__objc_classname,cstring_literals"
- : "__TEXT,__cstring,cstring_literals";
+ Section = NonFragile ? "__TEXT,__objc_classname,cstring_literals"
+ : "__TEXT,__cstring,cstring_literals";
break;
case ObjCLabelType::MethodVarName:
- Section = isNonFragileABI() ? "__TEXT,__objc_methname,cstring_literals"
- : "__TEXT,__cstring,cstring_literals";
+ Section = NonFragile ? "__TEXT,__objc_methname,cstring_literals"
+ : "__TEXT,__cstring,cstring_literals";
break;
case ObjCLabelType::MethodVarType:
- Section = isNonFragileABI() ? "__TEXT,__objc_methtype,cstring_literals"
- : "__TEXT,__cstring,cstring_literals";
+ Section = NonFragile ? "__TEXT,__objc_methtype,cstring_literals"
+ : "__TEXT,__cstring,cstring_literals";
break;
case ObjCLabelType::PropertyName:
Section = "__TEXT,__cstring,cstring_literals";
break;
}
- llvm::Constant *Value = llvm::ConstantDataArray::getString(VMContext, Name);
+ llvm::Constant *Value =
+ llvm::ConstantDataArray::getString(VMContext, Name, NullTerminate);
llvm::GlobalVariable *GV =
new llvm::GlobalVariable(CGM.getModule(), Value->getType(),
/*isConstant=*/true,
Modified: cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm?rev=281997&r1=281996&r2=281997&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm Tue Sep 20 13:38:54 2016
@@ -2,7 +2,7 @@
// CHECK: [[A:.*]] = type { i64, [10 x i8*] }
-// CHECK: [[LAYOUT0:@.*]] = private global [3 x i8] c" 9\00"
+// CHECK: [[LAYOUT0:@.*]] = private unnamed_addr constant [3 x i8] c" 9\00"
// rdar://13045269
// If a __block variable requires extended layout information *and*
More information about the cfe-commits
mailing list