[llvm] r295238 - [GlobalObject] Fix setSection("")
Keno Fischer via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 15 13:42:42 PST 2017
Author: kfischer
Date: Wed Feb 15 15:42:42 2017
New Revision: 295238
URL: http://llvm.org/viewvc/llvm-project?rev=295238&view=rev
Log:
[GlobalObject] Fix setSection("")
Summary:
In rL291613, the section name was interned in LLVMContext. However,
this broke the ability to remove the section from a GlobalObject,
because it tried to intern empty strings, which is not allowed.
Fix that and add an appropriate regression test.
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D29795
Modified:
llvm/trunk/lib/IR/Globals.cpp
llvm/trunk/unittests/IR/FunctionTest.cpp
Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=295238&r1=295237&r2=295238&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Wed Feb 15 15:42:42 2017
@@ -177,7 +177,9 @@ void GlobalObject::setSection(StringRef
// 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
Modified: llvm/trunk/unittests/IR/FunctionTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/FunctionTest.cpp?rev=295238&r1=295237&r2=295238&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/FunctionTest.cpp (original)
+++ llvm/trunk/unittests/IR/FunctionTest.cpp Wed Feb 15 15:42:42 2017
@@ -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
More information about the llvm-commits
mailing list