From 70b69dcc759f35d81fd95c025d35844f74e16180 Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Thu, 31 Aug 2017 20:47:37 +0000 Subject: [PATCH] [NFC] Change Key in Argument to a std::string Before, Key was a StringRef to avoid unnecessary copies. This commit changes that to a std::string. This was okay previously because when people called emit for remarks before, they would create the remark *within* the call to emit. However, if you build the remark up and call emit *afterward*, it's possible to end up freeing the memory assigned to the StringRef before the call to emit. This caused a test failure with https://reviews.llvm.org/D37085 on Linux. Since building remarks before a call to emit is a valid use-case, it makes sense to replace this with a std::string. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312277 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DiagnosticInfo.h | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/include/llvm/IR/DiagnosticInfo.h b/include/llvm/IR/DiagnosticInfo.h index b2fa898d353..fc6a8b214db 100644 --- a/include/llvm/IR/DiagnosticInfo.h +++ b/include/llvm/IR/DiagnosticInfo.h @@ -188,17 +188,13 @@ private: public: /// \p The function that is concerned by this stack size diagnostic. /// \p The computed stack size. - DiagnosticInfoResourceLimit(const Function &Fn, - const char *ResourceName, + DiagnosticInfoResourceLimit(const Function &Fn, const char *ResourceName, uint64_t ResourceSize, DiagnosticSeverity Severity = DS_Warning, DiagnosticKind Kind = DK_ResourceLimit, uint64_t ResourceLimit = 0) - : DiagnosticInfo(Kind, Severity), - Fn(Fn), - ResourceName(ResourceName), - ResourceSize(ResourceSize), - ResourceLimit(ResourceLimit) {} + : DiagnosticInfo(Kind, Severity), Fn(Fn), ResourceName(ResourceName), + ResourceSize(ResourceSize), ResourceLimit(ResourceLimit) {} const Function &getFunction() const { return Fn; } const char *getResourceName() const { return ResourceName; } @@ -209,19 +205,17 @@ public: void print(DiagnosticPrinter &DP) const override; static bool classof(const DiagnosticInfo *DI) { - return DI->getKind() == DK_ResourceLimit || - DI->getKind() == DK_StackSize; + return DI->getKind() == DK_ResourceLimit || DI->getKind() == DK_StackSize; } }; class DiagnosticInfoStackSize : public DiagnosticInfoResourceLimit { public: - DiagnosticInfoStackSize(const Function &Fn, - uint64_t StackSize, + DiagnosticInfoStackSize(const Function &Fn, uint64_t StackSize, DiagnosticSeverity Severity = DS_Warning, uint64_t StackLimit = 0) - : DiagnosticInfoResourceLimit(Fn, "stack size", StackSize, - Severity, DK_StackSize, StackLimit) {} + : DiagnosticInfoResourceLimit(Fn, "stack size", StackSize, Severity, + DK_StackSize, StackLimit) {} uint64_t getStackSize() const { return getResourceSize(); } uint64_t getStackLimit() const { return getResourceLimit(); } @@ -244,7 +238,7 @@ public: /// \p The module that is concerned by this debug metadata version diagnostic. /// \p The actual metadata version. DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion, - DiagnosticSeverity Severity = DS_Warning) + DiagnosticSeverity Severity = DS_Warning) : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M), MetadataVersion(MetadataVersion) {} @@ -411,7 +405,7 @@ public: /// \brief Used in the streaming interface as the general argument type. It /// internally converts everything into a key-value pair. struct Argument { - StringRef Key; + std::string Key; std::string Val; // If set, the debug location corresponding to the value. DiagnosticLocation Loc; -- 2.50.1