Skip to content

Commit b6e17cb

Browse files
Fix escaping bugs that currently affect the JSON formatting test on
Windows. Other escaping bugs may remain; #620 is to fix all of them. Fixes #619.
1 parent a929d23 commit b6e17cb

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

clang/include/clang/3C/PersistentSourceLoc.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ class PersistentSourceLoc {
5656
return FileName < O.FileName;
5757
}
5858

59-
void print(llvm::raw_ostream &O) const {
60-
O << FileName << ":" << LineNo << ":" << ColNoS << ":" << ColNoE;
59+
std::string toString() const {
60+
return FileName + ":" + std::to_string(LineNo) + ":" +
61+
std::to_string(ColNoS) + ":" + std::to_string(ColNoE);
6162
}
6263

64+
void print(llvm::raw_ostream &O) const { O << toString(); }
65+
6366
void dump() const { print(llvm::errs()); }
6467

6568
static PersistentSourceLoc mkPSL(const clang::Decl *D,

clang/lib/3C/3CInteractiveData.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "clang/3C/3CInteractiveData.h"
14+
#include "llvm/Support/JSON.h"
1415

1516
void ConstraintsInfo::clear() {
1617
RootWildAtomsWithReason.clear();
@@ -116,11 +117,9 @@ void ConstraintsInfo::printConstraintStats(llvm::raw_ostream &O,
116117
O << "\"InSrc\":" << (InSrcWildAtoms.find(Cause) != InSrcWildAtoms.end()) << ", ";
117118
O << "\"Location\":";
118119
const PersistentSourceLoc &PSL = PtrInfo.getLocation();
119-
if (PSL.valid()) {
120-
O << "\"";
121-
PSL.print(O);
122-
O << "\"";
123-
} else
120+
if (PSL.valid())
121+
O << llvm::json::Value(PSL.toString());
122+
else
124123
O << "null";
125124
O << ", ";
126125

clang/lib/3C/ProgramInfo.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "clang/3C/ConstraintsGraph.h"
1414
#include "clang/3C/MappingVisitor.h"
1515
#include "clang/3C/Utils.h"
16+
#include "llvm/Support/JSON.h"
1617
#include <sstream>
1718

1819
using namespace clang;
@@ -66,7 +67,10 @@ void dumpStaticFuncMapJson(const ProgramInfo::StaticFunctionMapType &EMap,
6667
if (AddComma) {
6768
O << ",\n";
6869
}
69-
O << "{\"FuncName\":\"" << DefM.first << "\", \"Constraints\":[";
70+
// The `FuncName` and `FileName` field names are backwards: this is actually
71+
// the file name, hence the need to defend against special characters.
72+
O << "{\"FuncName\":" << llvm::json::Value(DefM.first)
73+
<< ", \"Constraints\":[";
7074
bool AddComma1 = false;
7175
for (const auto &J : DefM.second) {
7276
if (AddComma1) {
@@ -113,9 +117,9 @@ void ProgramInfo::dumpJson(llvm::raw_ostream &O) const {
113117
}
114118
PersistentSourceLoc L = I.first;
115119

116-
O << "{\"line\":\"";
117-
L.print(O);
118-
O << "\",\"Variables\":[";
120+
O << "{\"line\":";
121+
O << llvm::json::Value(L.toString());
122+
O << ",\"Variables\":[";
119123
I.second->dumpJson(O);
120124
O << "]}";
121125
AddComma = true;
@@ -315,7 +319,7 @@ void ProgramInfo::printStats(const std::set<std::string> &F, raw_ostream &O,
315319
if (AddComma) {
316320
O << ",\n";
317321
}
318-
O << "{\"" << I.first << "\":{";
322+
O << "{" << llvm::json::Value(I.first) << ":{";
319323
O << "\"constraints\":" << V << ",";
320324
O << "\"ptr\":" << P << ",";
321325
O << "\"ntarr\":" << Nt << ",";

0 commit comments

Comments
 (0)