diff options
author | Kostya Serebryany <kcc@google.com> | 2018-10-11 23:03:27 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2018-10-11 23:03:27 +0000 |
commit | d891ac9794363641f919c9ca8a7f9e3726121baf (patch) | |
tree | a5da2acdd10a720dd9cf80aecd546e01420c11d2 /llvm/lib/Transforms/Instrumentation/Instrumentation.cpp | |
parent | d1dd5c3a88724a25d9fef3962600ce5b223440ca (diff) | |
download | bcm5719-llvm-d891ac9794363641f919c9ca8a7f9e3726121baf.tar.gz bcm5719-llvm-d891ac9794363641f919c9ca8a7f9e3726121baf.zip |
merge two near-identical functions createPrivateGlobalForString into one
Summary:
We have two copies of createPrivateGlobalForString (in asan and in esan).
This change merges them into one. NFC
Reviewers: vitalybuka
Reviewed By: vitalybuka
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D53178
llvm-svn: 344314
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/Instrumentation.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/Instrumentation.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp b/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp index ea819c1856b..1c739c09e39 100644 --- a/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp @@ -15,6 +15,7 @@ #include "llvm/Transforms/Instrumentation.h" #include "llvm-c/Initialization.h" #include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/Module.h" #include "llvm/InitializePasses.h" #include "llvm/PassRegistry.h" @@ -53,6 +54,22 @@ BasicBlock::iterator llvm::PrepareToSplitEntryBlock(BasicBlock &BB, return IP; } +// Create a constant for Str so that we can pass it to the run-time lib. +GlobalVariable *llvm::createPrivateGlobalForString(Module &M, StringRef Str, + bool AllowMerging, + const char *NamePrefix) { + Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str); + // We use private linkage for module-local strings. If they can be merged + // with another one, we set the unnamed_addr attribute. + GlobalVariable *GV = + new GlobalVariable(M, StrConst->getType(), true, + GlobalValue::PrivateLinkage, StrConst, NamePrefix); + if (AllowMerging) + GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); + GV->setAlignment(1); // Strings may not be merged w/o setting align 1. + return GV; +} + /// initializeInstrumentation - Initialize all passes in the TransformUtils /// library. void llvm::initializeInstrumentation(PassRegistry &Registry) { |