os << "unknown";
})
.Case<FileLineColLoc>([&](FileLineColLoc loc) {
- StringRef mayQuote = pretty ? "" : "\"";
- os << mayQuote << loc.getFilename() << mayQuote << ':' << loc.getLine()
- << ':' << loc.getColumn();
+ if (pretty) {
+ os << loc.getFilename();
+ } else {
+ os << "\"";
+ printEscapedString(loc.getFilename(), os);
+ os << "\"";
+ }
+ os << ':' << loc.getLine() << ':' << loc.getColumn();
})
.Case<NameLoc>([&](NameLoc loc) {
- os << '\"' << loc.getName() << '\"';
+ os << '\"';
+ printEscapedString(loc.getName(), os);
+ os << '\"';
// Print the child if it isn't unknown.
auto childLoc = loc.getChildLoc();
// CHECK-LABEL: func private @loc_attr(i1 {foo.loc_attr = loc(callsite("foo" at "mysource.cc":10:8))})
func private @loc_attr(i1 {foo.loc_attr = loc(callsite("foo" at "mysource.cc":10:8))})
+ // Check that locations get properly escaped.
+// CHECK-LABEL: func @escape_strings()
+func @escape_strings() {
+ // CHECK: loc("escaped\0A")
+ "foo"() : () -> () loc("escaped\n")
+
+ // CHECK: loc("escaped\0A")
+ "foo"() : () -> () loc("escaped\0A")
+
+ // CHECK: loc("escaped\0A":0:0)
+ "foo"() : () -> () loc("escaped\n":0:0)
+ return
+}
+
// CHECK-ALIAS: "foo.op"() : () -> () loc(#[[LOC:.*]])
"foo.op"() : () -> () loc(#loc)