[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

llvm-svn: 295238
diff --git a/llvm/unittests/IR/FunctionTest.cpp b/llvm/unittests/IR/FunctionTest.cpp
index fb458597..6838d7e 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 @@
   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