r226317 - Add comdat to string literal variables on COFF.
Rafael Espindola
rafael.espindola at gmail.com
Fri Jan 16 12:32:35 PST 2015
Author: rafael
Date: Fri Jan 16 14:32:35 2015
New Revision: 226317
URL: http://llvm.org/viewvc/llvm-project?rev=226317&view=rev
Log:
Add comdat to string literal variables on COFF.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/c-strings.c
cfe/trunk/test/CodeGenCXX/ms_wide_predefined_expr.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=226317&r1=226316&r2=226317&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Jan 16 14:32:35 2015
@@ -2876,12 +2876,18 @@ GenerateStringLiteral(llvm::Constant *C,
if (CGM.getLangOpts().OpenCL)
AddrSpace = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
+ llvm::Module &M = CGM.getModule();
// Create a global variable for this string
auto *GV = new llvm::GlobalVariable(
- CGM.getModule(), C->getType(), !CGM.getLangOpts().WritableStrings, LT, C,
- GlobalName, nullptr, llvm::GlobalVariable::NotThreadLocal, AddrSpace);
+ M, C->getType(), !CGM.getLangOpts().WritableStrings, LT, C, GlobalName,
+ nullptr, llvm::GlobalVariable::NotThreadLocal, AddrSpace);
GV->setAlignment(Alignment);
GV->setUnnamedAddr(true);
+ if (GV->isWeakForLinker()) {
+ assert(CGM.supportsCOMDAT() && "Only COFF uses weak string literals");
+ GV->setComdat(M.getOrInsertComdat(GV->getName()));
+ }
+
return GV;
}
Modified: cfe/trunk/test/CodeGen/c-strings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/c-strings.c?rev=226317&r1=226316&r2=226317&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/c-strings.c (original)
+++ cfe/trunk/test/CodeGen/c-strings.c Fri Jan 16 14:32:35 2015
@@ -6,7 +6,7 @@
// CHECK: @align = global i8 [[ALIGN:[0-9]+]]
// ITANIUM: @.str = private unnamed_addr constant [6 x i8] c"hello\00"
-// MSABI: @"\01??_C at _05CJBACGMB@hello?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"hello\00", align 1
+// MSABI: @"\01??_C at _05CJBACGMB@hello?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"hello\00", comdat, align 1
// ITANIUM: @f1.x = internal global i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0)
// MSABI: @f1.x = internal global i8* getelementptr inbounds ([6 x i8]* @"\01??_C at _05CJBACGMB@hello?$AA@", i32 0, i32 0)
// CHECK: @f2.x = internal global [6 x i8] c"hello\00", align [[ALIGN]]
Modified: cfe/trunk/test/CodeGenCXX/ms_wide_predefined_expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ms_wide_predefined_expr.cpp?rev=226317&r1=226316&r2=226317&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ms_wide_predefined_expr.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ms_wide_predefined_expr.cpp Fri Jan 16 14:32:35 2015
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 %s -fms-extensions -triple i686-pc-win32 -emit-llvm -o - | FileCheck %s
-// CHECK: @"\01??_C at _19DPFBEKIN@?$AAf?$AAu?$AAn?$AAc?$AA?$AA@" = linkonce_odr unnamed_addr constant [5 x i16] [i16 102, i16 117, i16 110, i16 99, i16 0], align 2
+// CHECK: @"\01??_C at _19DPFBEKIN@?$AAf?$AAu?$AAn?$AAc?$AA?$AA@" = linkonce_odr unnamed_addr constant [5 x i16] [i16 102, i16 117, i16 110, i16 99, i16 0], comdat, align 2
void wprint(const wchar_t*);
More information about the cfe-commits
mailing list