From 5e54eb1954a6eea918dbe1512048a552872c39d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez=20Troiti=C3=B1o?= Date: Wed, 30 Oct 2019 17:03:21 -0700 Subject: [PATCH] [Diagnostics] Use constant strings to avoid use after free. Using std::string in the function signature copies the constant string into a stack allocated copy, which is the one referenced by the StringRef that DiagnosticInfo stores. when the stack is abandoned, the string seems to be modificed in VC++, which makes the test fail in Windows. Using const char * in the signature avoids the std::string creation, and StringRef will refer to the static data instead. --- unittests/AST/DiagnosticConsumerTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/AST/DiagnosticConsumerTests.cpp b/unittests/AST/DiagnosticConsumerTests.cpp index 85b611744dfca..d347f8f32845f 100644 --- a/unittests/AST/DiagnosticConsumerTests.cpp +++ b/unittests/AST/DiagnosticConsumerTests.cpp @@ -50,7 +50,7 @@ namespace { } }; - DiagnosticInfo testDiagnosticInfo(SourceLoc Loc, std::string Message, + DiagnosticInfo testDiagnosticInfo(SourceLoc Loc, const char *Message, DiagnosticKind Kind) { return DiagnosticInfo(DiagID(0), Loc, Kind, Message, /*args*/ {}, /*indirectBuffer*/ SourceLoc(), /*childInfo*/ {},