r210403 - Avoid dubious IdentifierInfo::getNameStart() uses
Alp Toker
alp at nuanti.com
Sat Jun 7 16:30:53 PDT 2014
Author: alp
Date: Sat Jun 7 18:30:53 2014
New Revision: 210403
URL: http://llvm.org/viewvc/llvm-project?rev=210403&view=rev
Log:
Avoid dubious IdentifierInfo::getNameStart() uses
These cases in particular were incurring an extra strlen() when we already knew
the length. They appear to be leftovers from when the interfaces worked with C
strings that have continued to compile due to the implicit StringRef ctor.
Modified:
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/lib/Sema/SemaPseudoObject.cpp
cfe/trunk/lib/Sema/SemaStmtAttr.cpp
cfe/trunk/tools/libclang/CXString.cpp
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=210403&r1=210402&r2=210403&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sat Jun 7 18:30:53 2014
@@ -1947,9 +1947,7 @@ public:
//
// FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
// something different.
- StringRef getName() const {
- return Id ? Id->getNameStart() : "";
- }
+ StringRef getName() const { return Id ? Id->getName() : StringRef(); }
/// @brief Get the name of the class associated with this interface.
//
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=210403&r1=210402&r2=210403&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sat Jun 7 18:30:53 2014
@@ -1018,14 +1018,12 @@ protected:
/// \param Name - The variable name.
/// \param Init - The variable initializer; this is also used to
/// define the type of the variable.
- /// \param Section - The section the variable should go into, or 0.
+ /// \param Section - The section the variable should go into, or empty.
/// \param Align - The alignment for the variable, or 0.
/// \param AddToUsed - Whether the variable should be added to
/// "llvm.used".
- llvm::GlobalVariable *CreateMetadataVar(Twine Name,
- llvm::Constant *Init,
- const char *Section,
- unsigned Align,
+ llvm::GlobalVariable *CreateMetadataVar(Twine Name, llvm::Constant *Init,
+ StringRef Section, unsigned Align,
bool AddToUsed);
CodeGen::RValue EmitMessageSend(CodeGen::CodeGenFunction &CGF,
@@ -2723,9 +2721,8 @@ CGObjCMac::EmitProtocolExtension(const O
llvm::ConstantStruct::get(ObjCTypes.ProtocolExtensionTy, Values);
// No special section, but goes in llvm.used
- return CreateMetadataVar("\01l_OBJC_PROTOCOLEXT_" + PD->getName(),
- Init,
- nullptr, 0, true);
+ return CreateMetadataVar("\01l_OBJC_PROTOCOLEXT_" + PD->getName(), Init,
+ StringRef(), 0, true);
}
/*
@@ -2858,11 +2855,9 @@ CGObjCCommonMac::EmitProtocolMethodTypes
MethodTypes.size());
llvm::Constant *Init = llvm::ConstantArray::get(AT, MethodTypes);
- llvm::GlobalVariable *GV =
- CreateMetadataVar(Name, Init,
- (ObjCABI == 2) ? "__DATA, __objc_const" : nullptr,
- (ObjCABI == 2) ? 8 : 4,
- true);
+ llvm::GlobalVariable *GV = CreateMetadataVar(
+ Name, Init, (ObjCABI == 2) ? "__DATA, __objc_const" : StringRef(),
+ (ObjCABI == 2) ? 8 : 4, true);
return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.Int8PtrPtrTy);
}
@@ -3395,18 +3390,17 @@ llvm::Function *CGObjCCommonMac::Generat
return Method;
}
-llvm::GlobalVariable *
-CGObjCCommonMac::CreateMetadataVar(Twine Name,
- llvm::Constant *Init,
- const char *Section,
- unsigned Align,
- bool AddToUsed) {
+llvm::GlobalVariable *CGObjCCommonMac::CreateMetadataVar(Twine Name,
+ llvm::Constant *Init,
+ StringRef Section,
+ unsigned Align,
+ bool AddToUsed) {
llvm::Type *Ty = Init->getType();
llvm::GlobalVariable *GV =
new llvm::GlobalVariable(CGM.getModule(), Ty, false,
llvm::GlobalValue::PrivateLinkage, Init, Name);
assertPrivateName(GV);
- if (Section)
+ if (!Section.empty())
GV->setSection(Section);
if (Align)
GV->setAlignment(Align);
@@ -4457,13 +4451,12 @@ llvm::Constant *CGObjCCommonMac::GetClas
llvm::GlobalVariable *&Entry = ClassNames[Ident];
if (!Entry)
- Entry = CreateMetadataVar("\01L_OBJC_CLASS_NAME_",
- llvm::ConstantDataArray::getString(VMContext,
- Ident->getNameStart()),
- ((ObjCABI == 2) ?
- "__TEXT,__objc_classname,cstring_literals" :
- "__TEXT,__cstring,cstring_literals"),
- 1, true);
+ Entry = CreateMetadataVar(
+ "\01L_OBJC_CLASS_NAME_",
+ llvm::ConstantDataArray::getString(VMContext, Ident->getName()),
+ ((ObjCABI == 2) ? "__TEXT,__objc_classname,cstring_literals"
+ : "__TEXT,__cstring,cstring_literals"),
+ 1, true);
return getConstantGEP(VMContext, Entry, 0, 0);
}
@@ -4926,11 +4919,10 @@ llvm::Constant *CGObjCCommonMac::GetProp
llvm::GlobalVariable *&Entry = PropertyNames[Ident];
if (!Entry)
- Entry = CreateMetadataVar("\01L_OBJC_PROP_NAME_ATTR_",
- llvm::ConstantDataArray::getString(VMContext,
- Ident->getNameStart()),
- "__TEXT,__cstring,cstring_literals",
- 1, true);
+ Entry = CreateMetadataVar(
+ "\01L_OBJC_PROP_NAME_ATTR_",
+ llvm::ConstantDataArray::getString(VMContext, Ident->getName()),
+ "__TEXT,__cstring,cstring_literals", 1, true);
return getConstantGEP(VMContext, Entry, 0, 0);
}
Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=210403&r1=210402&r2=210403&view=diff
==============================================================================
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Sat Jun 7 18:30:53 2014
@@ -824,7 +824,7 @@ bool clang::index::generateUSRForMacro(c
if (ShouldGenerateLocation)
printLoc(Out, Loc, SM, /*IncludeOffset=*/true);
Out << "@macro@";
- Out << MD->getName()->getNameStart();
+ Out << MD->getName()->getName();
return false;
}
Modified: cfe/trunk/lib/Sema/SemaPseudoObject.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaPseudoObject.cpp?rev=210403&r1=210402&r2=210403&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaPseudoObject.cpp (original)
+++ cfe/trunk/lib/Sema/SemaPseudoObject.cpp Sat Jun 7 18:30:53 2014
@@ -569,13 +569,11 @@ bool ObjCPropertyOpBuilder::findGetter()
assert(setter && "both setter and getter are null - cannot happen");
IdentifierInfo *setterName =
setter->getSelector().getIdentifierInfoForSlot(0);
- const char *compStr = setterName->getNameStart();
- compStr += 3;
- IdentifierInfo *getterName = &S.Context.Idents.get(compStr);
+ IdentifierInfo *getterName =
+ &S.Context.Idents.get(setterName->getName().substr(3));
GetterSelector =
S.PP.getSelectorTable().getNullarySelector(getterName);
return false;
-
}
}
Modified: cfe/trunk/lib/Sema/SemaStmtAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAttr.cpp?rev=210403&r1=210402&r2=210403&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAttr.cpp Sat Jun 7 18:30:53 2014
@@ -62,7 +62,7 @@ static Attr *handleLoopHintAttr(Sema &S,
assert(OptionInfo && "Attribute must have valid option info.");
LoopHintAttr::OptionType Option =
- llvm::StringSwitch<LoopHintAttr::OptionType>(OptionInfo->getNameStart())
+ llvm::StringSwitch<LoopHintAttr::OptionType>(OptionInfo->getName())
.Case("vectorize", LoopHintAttr::Vectorize)
.Case("vectorize_width", LoopHintAttr::VectorizeWidth)
.Case("interleave", LoopHintAttr::Interleave)
Modified: cfe/trunk/tools/libclang/CXString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXString.cpp?rev=210403&r1=210402&r2=210403&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXString.cpp (original)
+++ cfe/trunk/tools/libclang/CXString.cpp Sat Jun 7 18:30:53 2014
@@ -81,7 +81,11 @@ CXString createDup(const char *String) {
CXString createRef(StringRef String) {
// If the string is not nul-terminated, we have to make a copy.
- // This is doing a one past end read, and should be removed!
+
+ // FIXME: This is doing a one past end read, and should be removed! For memory
+ // we don't manage, the API string can become unterminated at any time outside
+ // our control.
+
if (!String.empty() && String.data()[String.size()] != 0)
return createDup(String);
More information about the cfe-commits
mailing list