Skip to content

Commit 651655e

Browse files
[Localization] Allocate a copy of diagnostic + name strings in LocalizationProducer
1 parent 1b0e8f9 commit 651655e

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

include/swift/Localization/LocalizationFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class SerializedLocalizationWriter {
155155

156156
class LocalizationProducer {
157157
bool printDiagnosticName;
158+
std::string localizedDebugDiagnosticMessage;
158159

159160
public:
160161
LocalizationProducer(bool printDiagnosticName = false)
@@ -163,7 +164,7 @@ class LocalizationProducer {
163164
/// If the message isn't available/localized in current context
164165
/// return the fallback default message.
165166
virtual llvm::StringRef getMessageOr(swift::DiagID id,
166-
llvm::StringRef defaultMessage) const;
167+
llvm::StringRef defaultMessage);
167168

168169
virtual ~LocalizationProducer() {}
169170

lib/Localization/LocalizationFormat.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ enum LocalDiagID : uint32_t {
3838
};
3939

4040
static constexpr const char *const diagnosticNameStrings[] = {
41-
#define ERROR(ID, Options, Text, Signature) " [" #ID "]",
42-
#define WARNING(ID, Options, Text, Signature) " [" #ID "]",
43-
#define NOTE(ID, Options, Text, Signature) " [" #ID "]",
44-
#define REMARK(ID, Options, Text, Signature) " [" #ID "]",
41+
#define DIAG(KIND, ID, Options, Text, Signature) " [" #ID "]",
4542
#include "swift/AST/DiagnosticsAll.def"
4643
"<not a diagnostic>",
4744
};
@@ -96,12 +93,12 @@ bool SerializedLocalizationWriter::emit(llvm::StringRef filePath) {
9693

9794
llvm::StringRef
9895
LocalizationProducer::getMessageOr(swift::DiagID id,
99-
llvm::StringRef defaultMessage) const {
96+
llvm::StringRef defaultMessage) {
10097
auto localizedMessage = getMessage(id);
10198
if (localizedMessage.empty())
10299
return defaultMessage;
103100
llvm::StringRef diagnosticName(diagnosticNameStrings[(unsigned)id]);
104-
const std::string &localizedDebugDiagnosticMessage =
101+
localizedDebugDiagnosticMessage =
105102
localizedMessage.str() + diagnosticName.str();
106103
return printDiagnosticName ? localizedDebugDiagnosticMessage
107104
: localizedMessage;

0 commit comments

Comments
 (0)