@@ -191,7 +191,11 @@ template <typename F>
191191LLGlobalVariable *
192192getCachedStringLiteralImpl (llvm::Module &module ,
193193 llvm::StringMap<LLGlobalVariable *> &cache,
194- llvm::StringRef key, F initFactory) {
194+ llvm::StringRef key,
195+ #if LDC_LLVM_VER >= 1700
196+ std::optional< unsigned > addrspace,
197+ #endif
198+ F initFactory) {
195199 auto iter = cache.find (key);
196200 if (iter != cache.end ()) {
197201 return iter->second ;
@@ -201,7 +205,12 @@ getCachedStringLiteralImpl(llvm::Module &module,
201205
202206 auto gvar =
203207 new LLGlobalVariable (module , constant->getType (), true ,
204- LLGlobalValue::PrivateLinkage, constant, " .str" );
208+ LLGlobalValue::PrivateLinkage, constant,
209+ " .str" , nullptr , llvm::GlobalValue::NotThreadLocal
210+ #if LDC_LLVM_VER >= 1700
211+ , addrspace
212+ #endif
213+ );
205214 gvar->setUnnamedAddr (LLGlobalValue::UnnamedAddr::Global);
206215
207216 cache[key] = gvar;
@@ -241,14 +250,28 @@ LLGlobalVariable *IRState::getCachedStringLiteral(StringExp *se) {
241250 const llvm::StringRef key (reinterpret_cast <const char *>(keyData.ptr ),
242251 keyData.length );
243252
244- return getCachedStringLiteralImpl (module , *cache, key, [se]() {
253+ return getCachedStringLiteralImpl (module , *cache, key,
254+ #if LDC_LLVM_VER >= 1700
255+ std::nullopt ,
256+ #endif
257+ [se]() {
245258 // null-terminate
246259 return buildStringLiteralConstant (se, se->len + 1 );
247260 });
248261}
249262
250- LLGlobalVariable *IRState::getCachedStringLiteral (llvm::StringRef s) {
251- return getCachedStringLiteralImpl (module , cachedStringLiterals, s, [&]() {
263+ LLGlobalVariable *IRState::getCachedStringLiteral (llvm::StringRef s
264+ #if LDC_LLVM_VER >= 1700
265+ ,std::optional< unsigned > addrspace
266+ #endif
267+ ) {
268+ return getCachedStringLiteralImpl (module ,
269+ cachedStringLiterals,
270+ s,
271+ #if LDC_LLVM_VER >= 1700
272+ addrspace,
273+ #endif
274+ [&]() {
252275 return llvm::ConstantDataArray::getString (context (), s, true );
253276 });
254277}
0 commit comments