Skip to content

goto-cc: newlines in command files are just whitespace #6595

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
Jan 19, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions regression/goto-gcc/at_files/args
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-o
test.gb
other.c
17 changes: 10 additions & 7 deletions src/goto-cc/gcc_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Author: CM Wintersteiger, 2006
#include "gcc_cmdline.h"

#include <cstring>
#include <iostream>
#include <fstream>
#include <iostream>
#include <sstream>

#include <util/prefix.h>

Expand Down Expand Up @@ -256,16 +257,18 @@ bool gcc_cmdlinet::parse_arguments(
if(has_prefix(argv_i, "@"))
{
std::ifstream opts_file(argv_i.substr(1));
std::ostringstream all_lines;
std::string line;

while(std::getline(opts_file, line))
{
// erase leading whitespace
line.erase(0, line.find_first_not_of("\t "));
all_lines << ' ' << line;
Copy link
Contributor

@chrisr-diffblue chrisr-diffblue Jan 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will effectively be replacing newlines with single spaces... it may be an edge case that we really don't care about too much, but just to check have you considered how this may/may not play with the quoting and escaping rules for @files ? It looks to me like theoretically a "backslash, newline" sequence is valid and should be preserved as a newline, for instance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good call-out, but I'm not entirely sure how where I might be able to put such a newline. The following won't work with GCC:

-o
file.gb
-Dhello="  \
"
test.c

With the above, hello just expands to an empty token. I also tried

-o
file.gb
'-Dhello="  \
"'
test.c

but then I even get a warning:

<command-line>:0:7: warning: missing terminating " character

Any ideas what else I might try?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats good enough for me to think that "theoretically" doesn't map to "actually supported by gcc in reality" :-)


if(!line.empty())
parse_specs_line(line, false);
}
line = all_lines.str();
// erase leading whitespace
line.erase(0, line.find_first_not_of("\t "));

if(!line.empty())
parse_specs_line(line, false);

continue;
}
Expand Down