Skip to content

Commit 0149fc1

Browse files
committed
Fix ldc-developers#3490 avoid new allocation of StringExp data in toir.
1 parent 8d5a971 commit 0149fc1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

dmd/expression.h

+5
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ class StringExp : public Expression
390390
assert(sz == 1);
391391
return {len, static_cast<const char *>(string)};
392392
}
393+
394+
DArray<const unsigned char> peekData() const
395+
{
396+
return {len * sz, static_cast<const unsigned char *>(string)};
397+
}
393398
#endif
394399
size_t numberOfCodeUnits(int tynto = 0) const;
395400
void writeTo(void* dest, bool zero, int tyto = 0) const;

gen/toir.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ class ToElemVisitor : public Visitor {
389389
llvm::StringMap<llvm::GlobalVariable *> *stringLiteralCache =
390390
stringLiteralCacheForType(cty);
391391

392-
llvm::StringRef key(e->toChars());
392+
DArray<const unsigned char> keyData = e->peekData();
393+
llvm::StringRef key(static_cast<const char*>(keyData.ptr), keyData.length);
393394
llvm::GlobalVariable *gvar;
394395

395396
auto iter = stringLiteralCache->find(key);

0 commit comments

Comments
 (0)