diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2016-05-11 18:21:59 +0000 | 
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2016-05-11 18:21:59 +0000 | 
| commit | 83658d6e7ac38a35dbbd9ef78b38b4705111e6c1 (patch) | |
| tree | 671c7623bef0badf6f246c9a2d8a0ed750d4be0a /llvm/lib/IR | |
| parent | 3f61c1ab5eedcb8621060014f863579862a33e04 (diff) | |
| download | bcm5719-llvm-83658d6e7ac38a35dbbd9ef78b38b4705111e6c1.tar.gz bcm5719-llvm-83658d6e7ac38a35dbbd9ef78b38b4705111e6c1.zip | |
Return a StringRef from getSection.
This is similar to how getName is handled.
llvm-svn: 269218
Diffstat (limited to 'llvm/lib/IR')
| -rw-r--r-- | llvm/lib/IR/Core.cpp | 4 | ||||
| -rw-r--r-- | llvm/lib/IR/Globals.cpp | 9 | 
2 files changed, 10 insertions, 3 deletions
| diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index d69e8d59d01..0c6c6f5157d 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -1485,7 +1485,9 @@ void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {  }  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) { diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index a9702b7af81..7e8ef6526fc 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -128,7 +128,7 @@ std::string GlobalValue::getGlobalIdentifier() const {                               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. | 

