10
10
11
11
#include < util/c_types.h>
12
12
#include < util/config.h>
13
+ #include < util/run.h>
13
14
#include < util/suffix.h>
14
15
#include < util/tempfile.h>
15
16
#include < util/unicode.h>
@@ -383,8 +384,9 @@ bool c_preprocess_visual_studio(
383
384
command += " 2> \" " + stderr_file () + " \" " ;
384
385
385
386
// _popen isn't very reliable on WIN32
386
- // that's why we use system()
387
- int result=system (command.c_str ());
387
+ // that's why we use run()
388
+ int result =
389
+ run (" cl" , {" cl" , " @" + command_file_name ()}, " " , tmpi (), stderr_file ());
388
390
389
391
std::ifstream instream (tmpi ());
390
392
@@ -463,30 +465,30 @@ bool c_preprocess_codewarrior(
463
465
464
466
temporary_filet stderr_file (" tmp.stderr" , " " );
465
467
466
- std::string command;
467
-
468
- command=" mwcceppc -E -P -D__CPROVER__ -ppopt line -ppopt full" ;
468
+ std::vector<std::string> command =
469
+ { " mwcceppc" , " -E" , " -P" , " -D__CPROVER__" , " -ppopt" , " line" , " -ppopt full" };
469
470
470
471
for (const auto &define : config.ansi_c .defines )
471
- command+= " -D" +shell_quote ( define);
472
+ command. push_back ( " -D" +define);
472
473
473
474
for (const auto &include_path : config.ansi_c .include_paths )
474
- command+= " -I" +shell_quote ( include_path);
475
+ command. push_back ( " -I" +include_path);
475
476
476
477
for (const auto &include_file : config.ansi_c .include_files )
477
- command+=" -include " +shell_quote (include_file);
478
+ {
479
+ command.push_back (" -include" );
480
+ command.push_back (include_file);
481
+ }
478
482
479
483
for (const auto &opt : config.ansi_c .preprocessor_options )
480
- command+=" " +opt;
481
-
482
- int result;
484
+ command.push_back (opt);
483
485
484
486
temporary_filet tmpi (" tmp.cl" , " " );
485
- command+= " \" " + file+ " \" " ;
486
- command += " -o \" " + tmpi () + " \" " ;
487
- command += " 2> \" " + stderr_file () + " \" " ;
487
+ command. push_back ( file) ;
488
+ command. push_back ( " -o " ) ;
489
+ command. push_back ( tmpi ()) ;
488
490
489
- result= system (command. c_str ());
491
+ int result = run (command[ 0 ], command, " " , " " , stderr_file ());
490
492
491
493
std::ifstream stream_i (tmpi ());
492
494
@@ -532,62 +534,63 @@ bool c_preprocess_gcc_clang(
532
534
533
535
temporary_filet stderr_file (" tmp.stderr" , " " );
534
536
535
- std::string command ;
537
+ std::vector<std:: string> argv ;
536
538
537
539
if (preprocessor==configt::ansi_ct::preprocessort::CLANG)
538
- command= " clang" ;
540
+ argv. push_back ( " clang" ) ;
539
541
else
540
- command= " gcc" ;
542
+ argv. push_back ( " gcc" ) ;
541
543
542
- command += " -E -D__CPROVER__" ;
544
+ argv.push_back (" -E" );
545
+ argv.push_back (" -D__CPROVER__" );
543
546
544
547
const irep_idt &arch = config.ansi_c .arch ;
545
548
546
549
if (config.ansi_c .pointer_width == 16 )
547
550
{
548
551
if (arch == " i386" || arch == " x86_64" || arch == " x32" )
549
- command += " -m16" ;
552
+ argv. push_back ( " -m16" ) ;
550
553
else if (has_prefix (id2string (arch), " mips" ))
551
- command += " -mips16" ;
554
+ argv. push_back ( " -mips16" ) ;
552
555
}
553
556
else if (config.ansi_c .pointer_width == 32 )
554
557
{
555
558
if (arch == " i386" || arch == " x86_64" )
556
- command += " -m32" ;
559
+ argv. push_back ( " -m32" ) ;
557
560
else if (arch == " x32" )
558
- command += " -mx32" ;
561
+ argv. push_back ( " -mx32" ) ;
559
562
else if (has_prefix (id2string (arch), " mips" ))
560
- command += " -mabi=32" ;
563
+ argv. push_back ( " -mabi=32" ) ;
561
564
else if (arch == " powerpc" || arch == " ppc64" || arch == " ppc64le" )
562
- command += " -m32" ;
565
+ argv. push_back ( " -m32" ) ;
563
566
else if (arch == " s390" || arch == " s390x" )
564
- command += " -m31" ; // yes, 31, not 32!
567
+ argv. push_back ( " -m31" ) ; // yes, 31, not 32!
565
568
else if (arch == " sparc" || arch == " sparc64" )
566
- command += " -m32" ;
569
+ argv. push_back ( " -m32" ) ;
567
570
}
568
571
else if (config.ansi_c .pointer_width == 64 )
569
572
{
570
573
if (arch == " i386" || arch == " x86_64" || arch == " x32" )
571
- command += " -m64" ;
574
+ argv. push_back ( " -m64" ) ;
572
575
else if (has_prefix (id2string (arch), " mips" ))
573
- command += " -mabi=64" ;
576
+ argv. push_back ( " -mabi=64" ) ;
574
577
else if (arch == " powerpc" || arch == " ppc64" || arch == " ppc64le" )
575
- command += " -m64" ;
578
+ argv. push_back ( " -m64" ) ;
576
579
else if (arch == " s390" || arch == " s390x" )
577
- command += " -m64" ;
580
+ argv. push_back ( " -m64" ) ;
578
581
else if (arch == " sparc" || arch == " sparc64" )
579
- command += " -m64" ;
582
+ argv. push_back ( " -m64" ) ;
580
583
}
581
584
582
585
// The width of wchar_t depends on the OS!
583
586
if (config.ansi_c .wchar_t_width == config.ansi_c .short_int_width )
584
- command += " -fshort-wchar" ;
587
+ argv. push_back ( " -fshort-wchar" ) ;
585
588
586
589
if (config.ansi_c .char_is_unsigned )
587
- command += " -funsigned-char" ;
590
+ argv. push_back ( " -funsigned-char" ) ;
588
591
589
592
if (config.ansi_c .os == configt::ansi_ct::ost::NO_OS)
590
- command += " -nostdinc" ;
593
+ argv. push_back ( " -nostdinc" ) ;
591
594
592
595
// Set the standard
593
596
if (has_suffix (file, " .cpp" ) || has_suffix (file, " .CPP" ) ||
@@ -600,19 +603,19 @@ bool c_preprocess_gcc_clang(
600
603
switch (config.cpp .cpp_standard )
601
604
{
602
605
case configt::cppt::cpp_standardt::CPP98:
603
- command += " -std=gnu++98" ;
606
+ argv. push_back ( " -std=gnu++98" ) ;
604
607
break ;
605
608
606
609
case configt::cppt::cpp_standardt::CPP03:
607
- command += " -std=gnu++03" ;
610
+ argv. push_back ( " -std=gnu++03" ) ;
608
611
break ;
609
612
610
613
case configt::cppt::cpp_standardt::CPP11:
611
- command += " -std=gnu++11" ;
614
+ argv. push_back ( " -std=gnu++11" ) ;
612
615
break ;
613
616
614
617
case configt::cppt::cpp_standardt::CPP14:
615
- command += " -std=gnu++14" ;
618
+ argv. push_back ( " -std=gnu++14" ) ;
616
619
break ;
617
620
}
618
621
}
@@ -621,30 +624,33 @@ bool c_preprocess_gcc_clang(
621
624
switch (config.ansi_c .c_standard )
622
625
{
623
626
case configt::ansi_ct::c_standardt::C89:
624
- command += " -std=gnu++89" ;
627
+ argv. push_back ( " -std=gnu++89" ) ;
625
628
break ;
626
629
627
630
case configt::ansi_ct::c_standardt::C99:
628
- command += " -std=gnu99" ;
631
+ argv. push_back ( " -std=gnu99" ) ;
629
632
break ;
630
633
631
634
case configt::ansi_ct::c_standardt::C11:
632
- command += " -std=gnu11" ;
635
+ argv. push_back ( " -std=gnu11" ) ;
633
636
break ;
634
637
}
635
638
}
636
639
637
640
for (const auto &define : config.ansi_c .defines )
638
- command+= " -D" +shell_quote ( define);
641
+ argv. push_back ( " -D" +define);
639
642
640
643
for (const auto &include_path : config.ansi_c .include_paths )
641
- command+= " -I" +shell_quote ( include_path);
644
+ argv. push_back ( " -I" +include_path);
642
645
643
646
for (const auto &include_file : config.ansi_c .include_files )
644
- command+=" -include " +shell_quote (include_file);
647
+ {
648
+ argv.push_back (" -include" );
649
+ argv.push_back (include_file);
650
+ }
645
651
646
652
for (const auto &opt : config.ansi_c .preprocessor_options )
647
- command+= " " + opt;
653
+ argv. push_back ( opt) ;
648
654
649
655
int result;
650
656
@@ -660,15 +666,17 @@ bool c_preprocess_gcc_clang(
660
666
}
661
667
#endif
662
668
669
+ // the file that is to be preprocessed
670
+ argv.push_back (file);
671
+
663
672
#ifdef _WIN32
664
673
temporary_filet tmpi (" tmp.gcc" , " " );
665
- command+=" \" " +file+" \" " ;
666
- command += " -o \" " + tmpi () + " \" " ;
667
- command += " 2> \" " + stderr_file () + " \" " ;
674
+ argv.push_back (" -o" );
675
+ argv.push_back (tmpi ());
668
676
669
677
// _popen isn't very reliable on WIN32
670
- // that's why we use system () and a temporary file
671
- result=system (command. c_str ());
678
+ // that's why we use run () and a temporary file
679
+ result=run (argv[ 0 ], argv, " " , " " , stderr_file ());
672
680
673
681
std::ifstream instream (tmpi ());
674
682
@@ -688,7 +696,11 @@ bool c_preprocess_gcc_clang(
688
696
result=1 ;
689
697
}
690
698
#else
691
- command+=" \" " +file+" \" " ;
699
+
700
+ std::string command;
701
+ for (const auto &arg : argv)
702
+ command+=" " +shell_quote (arg);
703
+
692
704
command += " 2> \" " + stderr_file () + " \" " ;
693
705
694
706
FILE *stream=popen (command.c_str (), " r" );
@@ -738,50 +750,52 @@ bool c_preprocess_arm(
738
750
739
751
temporary_filet stderr_file (" tmp.stderr" , " " );
740
752
741
- std::string command ;
753
+ std::vector<std:: string> argv ;
742
754
743
- command=" armcc -E -D__CPROVER__" ;
755
+ argv.push_back (" armcc" );
756
+ argv.push_back (" -E" );
757
+ argv.push_back (" -D__CPROVER__" );
744
758
745
759
if (config.ansi_c .endianness == configt::ansi_ct::endiannesst::IS_BIG_ENDIAN)
746
- command += " --bigend" ;
760
+ argv. push_back ( " --bigend" ) ;
747
761
else
748
- command += " --littleend" ;
762
+ argv. push_back ( " --littleend" ) ;
749
763
750
764
if (config.ansi_c .char_is_unsigned )
751
- command += " --unsigned_chars" ;
765
+ argv. push_back ( " --unsigned_chars" ) ;
752
766
else
753
- command += " --signed_chars" ;
767
+ argv. push_back ( " --signed_chars" ) ;
754
768
755
769
// Set the standard
756
770
switch (config.ansi_c .c_standard )
757
771
{
758
772
case configt::ansi_ct::c_standardt::C89:
759
- command += " --c90" ;
773
+ argv. push_back ( " --c90" ) ;
760
774
break ;
761
775
762
776
case configt::ansi_ct::c_standardt::C99:
763
777
case configt::ansi_ct::c_standardt::C11:
764
- command += " --c99" ;
778
+ argv. push_back ( " --c99" ) ;
765
779
break ;
766
780
}
767
781
768
782
for (const auto &define : config.ansi_c .defines )
769
- command+= " " + shell_quote (" -D" +define);
783
+ argv. push_back (" -D" +define);
770
784
771
785
for (const auto &include_path : config.ansi_c .include_paths )
772
- command+=" " +shell_quote (" -I" +include_path);
786
+ argv.push_back (" -I" +include_path);
787
+
788
+ // the file that is to be preprocessed
789
+ argv.push_back (file);
773
790
774
791
int result;
775
792
776
793
#ifdef _WIN32
777
- temporary_filet tmpi (" tmp.cl" , " " );
778
- command+=" \" " +file+" \" " ;
779
- command += " > \" " + tmpi () + " \" " ;
780
- command += " 2> \" " + stderr_file () + " \" " ;
794
+ temporary_filet tmpi (" tmp.armcc" , " " );
781
795
782
796
// _popen isn't very reliable on WIN32
783
- // that's why we use system () and a temporary file
784
- result=system (command. c_str ());
797
+ // that's why we use run () and a temporary file
798
+ result=run (argv[ 0 ], argv, " " , tmpi (), stderr_file ());
785
799
786
800
std::ifstream instream (tmpi ());
787
801
@@ -797,7 +811,10 @@ bool c_preprocess_arm(
797
811
return true ;
798
812
}
799
813
#else
800
- command+=" \" " +file+" \" " ;
814
+ std::string command;
815
+ for (const auto &arg : argv)
816
+ command+=" " +shell_quote (arg);
817
+
801
818
command += " 2> \" " + stderr_file () + " \" " ;
802
819
803
820
FILE *stream=popen (command.c_str (), " r" );
0 commit comments