summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/IR/Globals.cpp4
-rw-r--r--llvm/unittests/IR/FunctionTest.cpp21
2 files changed, 24 insertions, 1 deletions
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 6f7356524d3..675c515b21f 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -177,7 +177,9 @@ void GlobalObject::setSection(StringRef S) {
// Get or create a stable section name string and put it in the table in the
// context.
- S = getContext().pImpl->SectionStrings.insert(S).first->first();
+ if (!S.empty()) {
+ S = getContext().pImpl->SectionStrings.insert(S).first->first();
+ }
getContext().pImpl->GlobalObjectSections[this] = S;
// Update the HasSectionHashEntryBit. Setting the section to the empty string
diff --git a/llvm/unittests/IR/FunctionTest.cpp b/llvm/unittests/IR/FunctionTest.cpp
index fb458597c37..6838d7e2527 100644
--- a/llvm/unittests/IR/FunctionTest.cpp
+++ b/llvm/unittests/IR/FunctionTest.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/IR/Function.h"
+#include "llvm/IR/Module.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -109,4 +110,24 @@ TEST(FunctionTest, stealArgumentListFrom) {
EXPECT_TRUE(F2->hasLazyArguments());
}
+// Test setting and removing section information
+TEST(FunctionTest, setSection) {
+ LLVMContext C;
+ Module M("test", C);
+
+ llvm::Function *F =
+ Function::Create(llvm::FunctionType::get(llvm::Type::getVoidTy(C), false),
+ llvm::GlobalValue::ExternalLinkage, "F", &M);
+
+ F->setSection(".text.test");
+ EXPECT_TRUE(F->getSection() == ".text.test");
+ EXPECT_TRUE(F->hasSection());
+ F->setSection("");
+ EXPECT_FALSE(F->hasSection());
+ F->setSection(".text.test");
+ F->setSection(".text.test2");
+ EXPECT_TRUE(F->getSection() == ".text.test2");
+ EXPECT_TRUE(F->hasSection());
+}
+
} // end namespace
OpenPOWER on IntegriCloud