[cfe-dev] Tests and include paths

Gordon Henriksen gordonhenriksen at me.com
Fri Aug 14 17:03:01 PDT 2009


It's very hard to pass arbitrary strings through the Windows  
CreateProcess API unmolested; Python may not be doing the right thing  
on your behalf. (.NET doesn't, believe it or not.) This is some  
Managed C++ to implement the CreateProcess escape algorithm for a  
single argument:

     void EscapeArg(StringBuilder %sb, String ^arg) {
         // This looks utterly inane, but is correct.
         unsigned quoteCount = 0;
         for (int i = 0, e = arg->Length; i != e; ++i) {
             wchar_t c = (*arg)[i];
             switch (c) {
                 case L'"':
                     for (; quoteCount; --quoteCount)
                         sb.Append(L"\\\\");
                     sb.Append(L'\\');
                     sb.Append(c);
                     break;
                 case L'\\':
                     ++quoteCount;
                     break;
                 default:
                     for (; quoteCount; --quoteCount)
                         sb.Append(L'\\');
                     sb.Append(c);
                     break;
             }
         }
         for (; quoteCount; --quoteCount)
             sb.Append(L"\\\\");
     }

This is quite dissimilar to the algorithms applicable to Unix shells.  
(It's also undocumented, perhaps because it's insane.)


On 2009-08-13, at 20:03, John Thompson wrote:

> I've been looking into the problem with using grep with search strings
> with double-quotes.
>
> I wrote a little C program that just prints out its arguments, so I
> could see what grep was possibly seeing (though it's argument parsing
> internally might be different, being an MSYS program).
>
>> From mangle.c, the script is given as:
>
> RUN: dsparg '@"\\01foo"' %t
>
> In the test report output:
>
> Command 3: "c:\tools\bin\dsparg.EXE" "@"\\01foo""
> "C:\Tools\llvm\tools\clang\test\Output\CodeGen\mangle.c.tmp"
> Command 3 Result: 1
> Command 3 Output:
> argc = 3
> argv[0] = [c:\tools\bin\dsparg.EXE]
> argv[1] = [@"\\01foo"]
> argv[2] = [C:\Tools\llvm\tools\clang\test\Output\CodeGen\mangle.c.tmp]
>
> So, it appears that the search string is getting to the program, but
> without the single quotes.
>
> I tried running grep directly from the Windows command line, and this
> is the only thing that worked:
>
> C:\Tools\llvm\tools\clang\test\Output\CodeGen>grep '@"\\\\01foo"'  
> mangle.c.tmp
> @"\01foo" = common global i32 0, align 4                ; <i32*>  
> [#uses=2]
>        %tmp = load i32* @"\01foo"              ; <i32> [#uses=1]
>        %tmp1 = load float* bitcast (i32* @"\01foo" to float*)
> ; <float> [#uses=1]
>
> The grep program (coming from MSYS) appears to be confused by the
> embedded quotes, so I'm not sure how to best deal with this.  Some
> possibilities:
>
> 1. Find a different grep that will work.
> 2. Write or hack a specialized grep to use in the problematic places.
> 3. Make the Python script do the grep.
> 4. Limit the search string to avoid the double-quotes or other
> problematic characters.  (I.e. look for just \\01foo in the above
> case).
> 5. Change the test case to avoid having to search for problematic
> things.  (Probably not an option here, since that format seems common
> in the LLVM code.)
> 6. Switch to a test mechanism that just compares the output file to a
> reference file.
>
> -John
>
> -- 
> John Thompson
> John.Thompson.JTSoftware at gmail.com
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090814/cbdb9759/attachment.html>


More information about the cfe-dev mailing list