diff options
| author | Alexey Samsonov <vonosmas@gmail.com> | 2014-06-05 20:53:34 +0000 |
|---|---|---|
| committer | Alexey Samsonov <vonosmas@gmail.com> | 2014-06-05 20:53:34 +0000 |
| commit | f6a54b977d50f16291be44ec26715f1e6a2d543d (patch) | |
| tree | 5222df684cbb148edf1f2578c9bf3a3472a7af95 /lib/CodeGen/CGExpr.cpp | |
| parent | bbc8adc78dd442e6a7133ca3ed2bdcfcd3acfc07 (diff) | |
| download | clang-f6a54b977d50f16291be44ec26715f1e6a2d543d.tar.gz clang-f6a54b977d50f16291be44ec26715f1e6a2d543d.tar.bz2 clang-f6a54b977d50f16291be44ec26715f1e6a2d543d.tar.xz | |
Mangle predefined string constants names to merge them at link-time
Summary:
This change generalizes the code used to create global LLVM
variables referencing predefined strings (e.g. __FUNCTION__): now it
just calls GetAddrOfConstantStringFromLiteral method. As a result,
global variables for these predefined strings may get mangled names
and linkonce_odr linkage. Fix the test accordingly.
Test Plan: clang regression tests
Reviewers: majnemer
Reviewed By: majnemer
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D4023
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210284 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
| -rw-r--r-- | lib/CodeGen/CGExpr.cpp | 36 |
1 files changed, 6 insertions, 30 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index a43093e553..f682c2c04a 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1988,28 +1988,6 @@ LValue CodeGenFunction::EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E) { E->getType()); } -static llvm::Constant* -GetAddrOfConstantWideString(StringRef Str, - const char *GlobalName, - ASTContext &Context, - QualType Ty, SourceLocation Loc, - CodeGenModule &CGM) { - - StringLiteral *SL = StringLiteral::Create(Context, - Str, - StringLiteral::Wide, - /*Pascal = */false, - Ty, Loc); - llvm::Constant *C = CGM.GetConstantArrayFromStringLiteral(SL); - auto *GV = new llvm::GlobalVariable( - CGM.getModule(), C->getType(), !CGM.getLangOpts().WritableStrings, - llvm::GlobalValue::PrivateLinkage, C, GlobalName); - const unsigned WideAlignment = - Context.getTypeAlignInChars(Ty).getQuantity(); - GV->setAlignment(WideAlignment); - return GV; -} - static void ConvertUTF8ToWideString(unsigned CharByteWidth, StringRef Source, SmallString<32>& Target) { Target.resize(CharByteWidth * (Source.size() + 1)); @@ -2078,14 +2056,12 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) { if (ElemType->isWideCharType()) { SmallString<32> RawChars; ConvertUTF8ToWideString( - getContext().getTypeSizeInChars(ElemType).getQuantity(), - FunctionName, RawChars); - C = GetAddrOfConstantWideString(RawChars, - GVName.c_str(), - getContext(), - E->getType(), - E->getLocation(), - CGM); + getContext().getTypeSizeInChars(ElemType).getQuantity(), FunctionName, + RawChars); + StringLiteral *SL = StringLiteral::Create( + getContext(), RawChars, StringLiteral::Wide, + /*Pascal = */ false, E->getType(), E->getLocation()); + C = CGM.GetAddrOfConstantStringFromLiteral(SL); } else { C = CGM.GetAddrOfConstantCString(FunctionName, GVName.c_str(), 1); } |
