[PATCH] D29795: [GlobalObject] Fix setSection("")
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 15 13:54:16 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL295238: [GlobalObject] Fix setSection("") (authored by kfischer).
Changed prior to commit:
https://reviews.llvm.org/D29795?vs=87895&id=88600#toc
Repository:
rL LLVM
https://reviews.llvm.org/D29795
Files:
llvm/trunk/lib/IR/Globals.cpp
llvm/trunk/unittests/IR/FunctionTest.cpp
Index: llvm/trunk/lib/IR/Globals.cpp
===================================================================
--- llvm/trunk/lib/IR/Globals.cpp
+++ llvm/trunk/lib/IR/Globals.cpp
@@ -177,7 +177,9 @@
// 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
Index: llvm/trunk/unittests/IR/FunctionTest.cpp
===================================================================
--- llvm/trunk/unittests/IR/FunctionTest.cpp
+++ llvm/trunk/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 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29795.88600.patch
Type: text/x-patch
Size: 1723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170215/64a31d09/attachment.bin>
More information about the llvm-commits
mailing list