Skip to content

Swift: escape path literals for ExpressionParser #6763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,24 @@ __builtin_logger_initialize()

assert(!playground && !repl && "Playground/REPL mode not expected");

auto path_literal = [](const char *path) -> std::string {
std::string escaped;
llvm::raw_string_ostream os(escaped);
llvm::printEscapedString(path, os);
return escaped;
};

if (pound_file && pound_line) {
fixed_text.Printf("#sourceLocation(file: \"%s\", line: %u)\n%s\n",
pound_file, pound_line, orig_text);
path_literal(pound_file).c_str(), pound_line, orig_text);
text = fixed_text.GetString().data();
} else if (generate_debug_info) {
std::string expr_source_path;
if (SwiftASTManipulator::SaveExpressionTextToTempFile(orig_text, options,
expr_source_path)) {
fixed_text.Printf("#sourceLocation(file: \"%s\", line: 1)\n%s\n",
expr_source_path.c_str(), orig_text);
path_literal(expr_source_path.c_str()).c_str(),
orig_text);
text = fixed_text.GetString().data();
}
}
Expand Down