The goal of the patch is to pass unmodified arguments to compilers as they were written in the makefile. Arguments taken from @ARGV may be modified by the system and Perl, at least quotes and backslash sequences are processed. Using this arguments may cause compiler errors. Sometimes system+Perl corrupt arguments completely, for example, using perl from MSYS 1.0 on Windows I got:
Line from makefile:
   $(CXX) -DMACRO=\"string\" file.cpp "asd dff ghh" -o file.exe

arguments red from @ARGV by c++-analyzer:
  "-DMACRO=\string\" file.cpp -o file.exe"

Please review!

--
Anton

Index: ccc-analyzer
===================================================================
--- ccc-analyzer	(revision 218624)
+++ ccc-analyzer	(working copy)
@@ -25,6 +25,13 @@
 # Compiler command setup.
 ##===----------------------------------------------------------------------===##
 
+# Read unmodified command line arguments preserved by scan-build.
+if (defined $ENV{"CCC_ANALYZER_ARGS"}) {
+  my $Args = $ENV{"CCC_ANALYZER_ARGS"};
+  @ARGV = quotewords('\s+', 1, $Args);
+  undef $ENV{"CCC_ANALYZER_ARGS"};
+};
+
 # Search in the PATH if the compiler exists
 sub SearchInPath {
     my $file = shift;
Index: scan-build
===================================================================
--- scan-build	(revision 219794)
+++ scan-build	(working copy)
@@ -1025,6 +1025,8 @@
   my $CXXAnalyzer = shift;
   my $Options = shift;
 
+  undef $ENV{"CCC_ANALYZER_ARGS"};
+
   if ($Cmd =~ /\bxcodebuild$/) {
     return RunXcodebuild($Args, $IgnoreErrors, $CCAnalyzer, $CXXAnalyzer, $Options);
   }
@@ -1063,6 +1065,38 @@
       AddIfNotPresent($Args,"-k");
       AddIfNotPresent($Args,"-i");
     }
+    
+    # @ARGV hold arguments processed and modified by the system (the system 
+    # processes quotes, backslash sequences, e.t.c).
+    # In ccc/c++-analyzer we need the original unmodified arguments passed to
+    # the ccc/c++-analyzer in order to pass them to the native compiler and 
+    # clang, otherwise we may end up with different errors caused by the 
+    # corrupted arguments. It seems there is no guaranteed way to get the
+    # original command line of the process neither in Windows nor in Unix and 
+    # MacOS.
+    #
+    # The below solution starts the 'make' command with the option to only print 
+    # the recipe without running them, an output is then returned to the 
+    # scan-build, the line that starts the ccc/c++-analyzer is found and the 
+    # original arguments are put to an environtment variable for the further use
+    # by the ccc/c++-analyzer instead of reading corrupted arguments from the 
+    # @ARGV.
+
+    my $BuildCommand = join ' ', @$Args;
+    # Disable the "Don't echo recipes." option.
+    $BuildCommand =~ s/\s+-s(\s+|$)/ /og;
+
+    # -n: Don't actually run any recipe; just print them.
+    my @BuildCommandOutput = `$BuildCommand -n`;
+
+    foreach my $Recipe (@BuildCommandOutput) {
+      # Strip everything before ccc/c++-analyzer arguments.
+      if ($Recipe =~ s/.*?(ccc|c\+\+)-analyzer\S*\s*//o) {
+        $Recipe =~ s/\s+$//;
+        $ENV{"CCC_ANALYZER_ARGS"} = $Recipe;
+        last;
+      }
+    }
   }
 
   return (system(@$Args) >> 8);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to