ScopGraphPrinter: Escape error message

Otherwise a '"' in the error message, yields an invalid .dot file.

llvm-svn: 163466
This commit is contained in:
Tobias Grosser 2012-09-08 08:31:55 +00:00
parent 26b1388293
commit 0b5a1959f4
1 changed files with 16 additions and 0 deletions

View File

@ -101,6 +101,21 @@ struct DOTGraphTraits<ScopDetection*> : public DOTGraphTraits<RegionNode*> {
return DOTGraphTraits<RegionNode*>
::getNodeLabel(Node, SD->getRI()->getTopLevelRegion());
}
static std::string escapeString(std::string String) {
std::string Escaped;
for (std::string::iterator SI = String.begin(), SE = String.end();
SI != SE; ++SI) {
if (*SI == '"')
Escaped += '\\';
Escaped += *SI;
}
return Escaped;
}
// Print the cluster of the subregions. This groups the single basic blocks
// and adds a different background color for each group.
static void printRegionCluster(const ScopDetection *SD, const Region *R,
@ -108,6 +123,7 @@ struct DOTGraphTraits<ScopDetection*> : public DOTGraphTraits<RegionNode*> {
O.indent(2 * depth) << "subgraph cluster_" << static_cast<const void*>(R)
<< " {\n";
std::string ErrorMessage = SD->regionIsInvalidBecause(R);
ErrorMessage = escapeString(ErrorMessage);
O.indent(2 * (depth + 1)) << "label = \"" << ErrorMessage << "\";\n";
if (SD->isMaxRegionInScop(*R)) {