r202409 - Assert that the name of some internal variables start with \01L or \01l.
Rafael Espindola
rafael.espindola at gmail.com
Thu Feb 27 08:26:32 PST 2014
Author: rafael
Date: Thu Feb 27 10:26:32 2014
New Revision: 202409
URL: http://llvm.org/viewvc/llvm-project?rev=202409&view=rev
Log:
Assert that the name of some internal variables start with \01L or \01l.
No functionality change. This is just an intermediate patch for changing those
global variables to use private linkage.
Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=202409&r1=202408&r2=202409&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Feb 27 10:26:32 2014
@@ -2567,6 +2567,12 @@ llvm::Constant *CGObjCCommonMac::GetProt
return GetOrEmitProtocolRef(PD);
}
+static void assertPrivateName(const llvm::GlobalValue *GV) {
+ StringRef NameRef = GV->getName();
+ assert(NameRef[0] == '\01' && (NameRef[1] == 'L' || NameRef[1] == 'l'));
+ assert(GV->getLinkage() == llvm::GlobalValue::InternalLinkage);
+}
+
/*
// Objective-C 1.0 extensions
struct _objc_protocol {
@@ -2652,7 +2658,6 @@ llvm::Constant *CGObjCMac::GetOrEmitProt
if (Entry) {
// Already created, fix the linkage and update the initializer.
- assert(Entry->getLinkage() == llvm::GlobalValue::InternalLinkage);
Entry->setInitializer(Init);
} else {
Entry =
@@ -2666,6 +2671,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProt
Protocols[PD->getIdentifier()] = Entry;
}
+ assertPrivateName(Entry);
CGM.AddUsedGlobal(Entry);
return Entry;
@@ -2687,6 +2693,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProt
// FIXME: Is this necessary? Why only for protocol?
Entry->setAlignment(4);
}
+ assertPrivateName(Entry);
return Entry;
}
@@ -3142,14 +3149,13 @@ void CGObjCMac::GenerateClass(const ObjC
if (GV) {
assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
"Forward metaclass reference has incorrect type.");
- assert(GV->getLinkage() == llvm::GlobalValue::InternalLinkage);
GV->setInitializer(Init);
GV->setSection(Section);
GV->setAlignment(4);
CGM.AddUsedGlobal(GV);
- }
- else
+ } else
GV = CreateMetadataVar(Name, Init, Section, 4, true);
+ assertPrivateName(GV);
DefinedClasses.push_back(GV);
// method definition entries must be clear for next implementation.
MethodDefinitions.clear();
@@ -3210,13 +3216,13 @@ llvm::Constant *CGObjCMac::EmitMetaClass
if (GV) {
assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
"Forward metaclass reference has incorrect type.");
- assert(GV->getLinkage() == llvm::GlobalValue::InternalLinkage);
GV->setInitializer(Init);
} else {
GV = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false,
llvm::GlobalValue::InternalLinkage,
Init, Name);
}
+ assertPrivateName(GV);
GV->setSection("__OBJC,__meta_class,regular,no_dead_strip");
GV->setAlignment(4);
CGM.AddUsedGlobal(GV);
@@ -3235,35 +3241,29 @@ llvm::Constant *CGObjCMac::EmitMetaClass
// Check for an existing forward reference.
// Previously, metaclass with internal linkage may have been defined.
// pass 'true' as 2nd argument so it is returned.
- if (llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name,
- true)) {
- assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
- "Forward metaclass reference has incorrect type.");
- return GV;
- } else {
- // Generate as an external reference to keep a consistent
- // module. This will be patched up when we emit the metaclass.
- return new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false,
- llvm::GlobalValue::InternalLinkage,
- 0,
- Name);
- }
+ llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name, true);
+ if (!GV)
+ GV = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false,
+ llvm::GlobalValue::InternalLinkage, 0, Name);
+
+ assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
+ "Forward metaclass reference has incorrect type.");
+ assertPrivateName(GV);
+ return GV;
}
llvm::Value *CGObjCMac::EmitSuperClassRef(const ObjCInterfaceDecl *ID) {
std::string Name = "\01L_OBJC_CLASS_" + ID->getNameAsString();
-
- if (llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name,
- true)) {
- assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
- "Forward class metadata reference has incorrect type.");
- return GV;
- } else {
- return new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false,
- llvm::GlobalValue::InternalLinkage,
- 0,
- Name);
- }
+ llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name, true);
+
+ if (!GV)
+ GV = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false,
+ llvm::GlobalValue::InternalLinkage, 0, Name);
+
+ assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
+ "Forward class metadata reference has incorrect type.");
+ assertPrivateName(GV);
+ return GV;
}
/*
@@ -3436,6 +3436,7 @@ CGObjCCommonMac::CreateMetadataVar(Twine
llvm::GlobalVariable *GV =
new llvm::GlobalVariable(CGM.getModule(), Ty, false,
llvm::GlobalValue::InternalLinkage, Init, Name);
+ assertPrivateName(GV);
if (Section)
GV->setSection(Section);
if (Align)
@@ -4998,7 +4999,7 @@ void CGObjCMac::FinishModule() {
Values[2] = llvm::Constant::getNullValue(ObjCTypes.ProtocolListPtrTy);
Values[3] = Values[4] =
llvm::Constant::getNullValue(ObjCTypes.MethodDescriptionListPtrTy);
- assert(I->second->getLinkage() == llvm::GlobalValue::InternalLinkage);
+ assertPrivateName(I->second);
I->second->setInitializer(llvm::ConstantStruct::get(ObjCTypes.ProtocolTy,
Values));
CGM.AddUsedGlobal(I->second);
@@ -5526,6 +5527,7 @@ AddModuleClassList(ArrayRef<llvm::Global
llvm::GlobalValue::InternalLinkage,
Init,
SymbolName);
+ assertPrivateName(GV);
GV->setAlignment(CGM.getDataLayout().getABITypeAlignment(Init->getType()));
GV->setSection(SectionName);
CGM.AddUsedGlobal(GV);
@@ -5714,6 +5716,7 @@ llvm::GlobalVariable * CGObjCNonFragileA
(flags & NonFragileABI_Class_Meta) ?
std::string("\01l_OBJC_METACLASS_RO_$_")+ClassName :
std::string("\01l_OBJC_CLASS_RO_$_")+ClassName);
+ assertPrivateName(CLASS_RO_GV);
CLASS_RO_GV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ClassRonfABITy));
CLASS_RO_GV->setSection("__DATA, __objc_const");
@@ -6037,6 +6040,7 @@ void CGObjCNonFragileABIMac::GenerateCat
llvm::GlobalValue::InternalLinkage,
Init,
ExtCatName);
+ assertPrivateName(GCATV);
GCATV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(ObjCTypes.CategorynfABITy));
GCATV->setSection("__DATA, __objc_const");
@@ -6097,6 +6101,7 @@ CGObjCNonFragileABIMac::EmitMethodList(T
llvm::GlobalVariable *GV =
new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false,
llvm::GlobalValue::InternalLinkage, Init, Name);
+ assertPrivateName(GV);
GV->setAlignment(CGM.getDataLayout().getABITypeAlignment(Init->getType()));
GV->setSection(Section);
CGM.AddUsedGlobal(GV);
@@ -6215,6 +6220,7 @@ llvm::Constant *CGObjCNonFragileABIMac::
llvm::GlobalValue::InternalLinkage,
Init,
Prefix + OID->getName());
+ assertPrivateName(GV);
GV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(Init->getType()));
GV->setSection("__DATA, __objc_const");
@@ -6424,6 +6430,7 @@ CGObjCNonFragileABIMac::EmitProtocolList
GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false,
llvm::GlobalValue::InternalLinkage,
Init, Name);
+ assertPrivateName(GV);
GV->setSection("__DATA, __objc_const");
GV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(Init->getType()));
@@ -6675,7 +6682,7 @@ llvm::Value *CGObjCNonFragileABIMac::Emi
Entry->setSection("__DATA, __objc_classrefs, regular, no_dead_strip");
CGM.AddUsedGlobal(Entry);
}
-
+ assertPrivateName(Entry);
return CGF.Builder.CreateLoad(Entry);
}
@@ -6709,7 +6716,7 @@ CGObjCNonFragileABIMac::EmitSuperClassRe
Entry->setSection("__DATA, __objc_superrefs, regular, no_dead_strip");
CGM.AddUsedGlobal(Entry);
}
-
+ assertPrivateName(Entry);
return CGF.Builder.CreateLoad(Entry);
}
@@ -6719,23 +6726,23 @@ CGObjCNonFragileABIMac::EmitSuperClassRe
llvm::Value *CGObjCNonFragileABIMac::EmitMetaClassRef(CodeGenFunction &CGF,
const ObjCInterfaceDecl *ID) {
llvm::GlobalVariable * &Entry = MetaClassReferences[ID->getIdentifier()];
- if (Entry)
- return CGF.Builder.CreateLoad(Entry);
+ if (!Entry) {
- std::string MetaClassName(getMetaclassSymbolPrefix() + ID->getNameAsString());
- llvm::GlobalVariable *MetaClassGV = GetClassGlobal(MetaClassName);
- Entry =
- new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassnfABIPtrTy, false,
- llvm::GlobalValue::InternalLinkage,
- MetaClassGV,
- "\01L_OBJC_CLASSLIST_SUP_REFS_$_");
- Entry->setAlignment(
- CGM.getDataLayout().getABITypeAlignment(
- ObjCTypes.ClassnfABIPtrTy));
+ std::string MetaClassName(getMetaclassSymbolPrefix() +
+ ID->getNameAsString());
+ llvm::GlobalVariable *MetaClassGV = GetClassGlobal(MetaClassName);
+ Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassnfABIPtrTy,
+ false, llvm::GlobalValue::InternalLinkage,
+ MetaClassGV,
+ "\01L_OBJC_CLASSLIST_SUP_REFS_$_");
+ Entry->setAlignment(
+ CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ClassnfABIPtrTy));
- Entry->setSection("__DATA, __objc_superrefs, regular, no_dead_strip");
- CGM.AddUsedGlobal(Entry);
+ Entry->setSection("__DATA, __objc_superrefs, regular, no_dead_strip");
+ CGM.AddUsedGlobal(Entry);
+ }
+ assertPrivateName(Entry);
return CGF.Builder.CreateLoad(Entry);
}
@@ -6819,6 +6826,7 @@ llvm::Value *CGObjCNonFragileABIMac::Emi
Entry->setSection("__DATA, __objc_selrefs, literal_pointers, no_dead_strip");
CGM.AddUsedGlobal(Entry);
}
+ assertPrivateName(Entry);
if (lval)
return Entry;
More information about the cfe-commits
mailing list