[llvm] r269218 - Return a StringRef from getSection.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed May 11 11:21:59 PDT 2016
Author: rafael
Date: Wed May 11 13:21:59 2016
New Revision: 269218
URL: http://llvm.org/viewvc/llvm-project?rev=269218&view=rev
Log:
Return a StringRef from getSection.
This is similar to how getName is handled.
Modified:
llvm/trunk/include/llvm/IR/GlobalObject.h
llvm/trunk/include/llvm/IR/GlobalValue.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/IR/Core.cpp
llvm/trunk/lib/IR/Globals.cpp
llvm/trunk/lib/Linker/IRMover.cpp
llvm/trunk/lib/Object/IRObjectFile.cpp
llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/trunk/lib/Target/XCore/XCoreISelLowering.cpp
llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Modified: llvm/trunk/include/llvm/IR/GlobalObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalObject.h?rev=269218&r1=269217&r2=269218&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalObject.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalObject.h Wed May 11 13:21:59 2016
@@ -54,8 +54,8 @@ public:
unsigned getGlobalObjectSubClassData() const;
void setGlobalObjectSubClassData(unsigned Val);
- bool hasSection() const { return !StringRef(getSection()).empty(); }
- const char *getSection() const { return Section.c_str(); }
+ bool hasSection() const { return !getSection().empty(); }
+ StringRef getSection() const { return Section; }
void setSection(StringRef S);
bool hasComdat() const { return getComdat() != nullptr; }
Modified: llvm/trunk/include/llvm/IR/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalValue.h?rev=269218&r1=269217&r2=269218&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalValue.h Wed May 11 13:21:59 2016
@@ -198,14 +198,8 @@ public:
}
void setDLLStorageClass(DLLStorageClassTypes C) { DllStorageClass = C; }
- bool hasSection() const { return !StringRef(getSection()).empty(); }
- // It is unfortunate that we have to use "char *" in here since this is
- // always non NULL, but:
- // * The C API expects a null terminated string, so we cannot use StringRef.
- // * The C API expects us to own it, so we cannot use a std:string.
- // * For GlobalAliases we can fail to find the section and we have to
- // return "", so we cannot use a "const std::string &".
- const char *getSection() const;
+ bool hasSection() const { return !getSection().empty(); }
+ StringRef getSection() const;
/// Global values are always pointers.
PointerType *getType() const { return cast<PointerType>(User::getType()); }
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=269218&r1=269217&r2=269218&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed May 11 13:21:59 2016
@@ -1528,7 +1528,7 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(c
}
// Ignore debug and non-emitted data. This handles llvm.compiler.used.
- if (StringRef(GV->getSection()) == "llvm.metadata" ||
+ if (GV->getSection() == "llvm.metadata" ||
GV->hasAvailableExternallyLinkage())
return true;
Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=269218&r1=269217&r2=269218&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Wed May 11 13:21:59 2016
@@ -1485,7 +1485,9 @@ void LLVMSetLinkage(LLVMValueRef Global,
}
const char *LLVMGetSection(LLVMValueRef Global) {
- return unwrap<GlobalValue>(Global)->getSection();
+ // Using .data() is safe because of how GlobalObject::setSection is
+ // implemented.
+ return unwrap<GlobalValue>(Global)->getSection().data();
}
void LLVMSetSection(LLVMValueRef Global, const char *Section) {
Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=269218&r1=269217&r2=269218&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Wed May 11 13:21:59 2016
@@ -128,7 +128,7 @@ std::string GlobalValue::getGlobalIdenti
getParent()->getSourceFileName());
}
-const char *GlobalValue::getSection() const {
+StringRef GlobalValue::getSection() const {
if (auto *GA = dyn_cast<GlobalAlias>(this)) {
// In general we cannot compute this at the IR level, but we try.
if (const GlobalObject *GO = GA->getBaseObject())
@@ -151,7 +151,12 @@ Comdat *GlobalValue::getComdat() {
return cast<GlobalObject>(this)->getComdat();
}
-void GlobalObject::setSection(StringRef S) { Section = S; }
+void GlobalObject::setSection(StringRef S) {
+ Section = S;
+
+ // The C api requires this to be null terminated.
+ Section.c_str();
+}
bool GlobalValue::isDeclaration() const {
// Globals are definitions if they have an initializer.
Modified: llvm/trunk/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=269218&r1=269217&r2=269218&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp (original)
+++ llvm/trunk/lib/Linker/IRMover.cpp Wed May 11 13:21:59 2016
@@ -786,7 +786,7 @@ Constant *IRLinker::linkAppendingVarProt
return nullptr;
}
- if (StringRef(DstGV->getSection()) != SrcGV->getSection()) {
+ if (DstGV->getSection() != SrcGV->getSection()) {
emitError(
"Appending variables with different section name need to be linked!");
return nullptr;
Modified: llvm/trunk/lib/Object/IRObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRObjectFile.cpp?rev=269218&r1=269217&r2=269218&view=diff
==============================================================================
--- llvm/trunk/lib/Object/IRObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/IRObjectFile.cpp Wed May 11 13:21:59 2016
@@ -248,7 +248,7 @@ uint32_t IRObjectFile::getSymbolFlags(Da
if (GV->getName().startswith("llvm."))
Res |= BasicSymbolRef::SF_FormatSpecific;
else if (auto *Var = dyn_cast<GlobalVariable>(GV)) {
- if (Var->getSection() == StringRef("llvm.metadata"))
+ if (Var->getSection() == "llvm.metadata")
Res |= BasicSymbolRef::SF_FormatSpecific;
}
Modified: llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp?rev=269218&r1=269217&r2=269218&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Wed May 11 13:21:59 2016
@@ -1041,7 +1041,7 @@ void NVPTXAsmPrinter::printModuleLevelGV
// Skip meta data
if (GVar->hasSection()) {
- if (GVar->getSection() == StringRef("llvm.metadata"))
+ if (GVar->getSection() == "llvm.metadata")
return;
}
Modified: llvm/trunk/lib/Target/XCore/XCoreISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreISelLowering.cpp?rev=269218&r1=269217&r2=269218&view=diff
==============================================================================
--- llvm/trunk/lib/Target/XCore/XCoreISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/XCore/XCoreISelLowering.cpp Wed May 11 13:21:59 2016
@@ -258,7 +258,7 @@ SDValue XCoreTargetLowering::getGlobalAd
return DAG.getNode(XCoreISD::PCRelativeWrapper, dl, MVT::i32, GA);
const auto *GVar = dyn_cast<GlobalVariable>(GV);
- if ((GV->hasSection() && StringRef(GV->getSection()).startswith(".cp.")) ||
+ if ((GV->hasSection() && GV->getSection().startswith(".cp.")) ||
(GVar && GVar->isConstant() && GV->hasLocalLinkage()))
return DAG.getNode(XCoreISD::CPRelativeWrapper, dl, MVT::i32, GA);
Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=269218&r1=269217&r2=269218&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Wed May 11 13:21:59 2016
@@ -1242,7 +1242,7 @@ bool AddressSanitizerModule::ShouldInstr
if (G->getAlignment() > MinRedzoneSizeForGlobal()) return false;
if (G->hasSection()) {
- StringRef Section(G->getSection());
+ StringRef Section = G->getSection();
// Globals from llvm.metadata aren't emitted, do not instrument them.
if (Section == "llvm.metadata") return false;
More information about the llvm-commits
mailing list