<div dir="ltr">When printing a command that a user can use, each argument is typically quoted/escaped. This is true of almost every tool I've used that prints out a command to copy paste and seems like the proper solution. I don't think it's reasonable to assume that without any work, raw arguments are shell copy pastable.<div>For example, a file name with a space would already not work with your proposed driver -###.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 11, 2021 at 12:42 PM Cameron McInally via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hey llvm-dev,<br>
<br>
The new Pass Manager's "-passes=default<Ox>" syntax is a little wonky.<br>
It was unfortunate that "<" and ">" were chosen, since those are the<br>
Unix I/O redirection operators.<br>
<br>
Let's take the case of a simple driver:<br>
<br>
#include <stddef.h><br>
#include <unistd.h><br>
#include <string.h><br>
#include <stdio.h><br>
<br>
int main(int argc, char *argv[]) {<br>
char* cmd = "opt";<br>
char* arr[] = {"-passes=default<O2>", "-S", "test.ll", NULL};<br>
<br>
if (argc == 1)<br>
execv(cmd, arr);<br>
else {<br>
if (strcmp(argv[1], "-###") == 0) {<br>
printf("%s ", cmd);<br>
for(int i =0 ; arr[i] != NULL; i++)<br>
printf("%s ", arr[i]);<br>
printf("\n");<br>
}<br>
}<br>
return 0;<br>
}<br>
<br>
So there's two modes there: execute the opt subcommand; or dump the<br>
subcommand in a dryrun. Typically, we'd want to be able to<br>
copy-and-paste the output of the dryrun to the command line.<br>
<br>
$ ./driver -###<br>
opt -passes=default<O2> -S test.ll<br>
$ opt -passes=default<O2> -S test.ll<br>
-bash: O2: No such file or directory<br>
<br>
But in this case, the new -passes=default<O2> option makes that<br>
awkward since we'd need to escape the '<' and '>' symbols, so that the<br>
shell doesn't interpret them as I/O redirectors.<br>
<br>
Unfortunately, patching this up in our driver is clunky. So I'm<br>
reaching out to the list to see if there's an appetite for a better<br>
way to express this option.<br>
<br>
Thanks,<br>
Cameron<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>