PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/src/RandomProgramGenerator.cpp

http://github.com/csmith-project/csmith
C++ | 1572 lines | 1188 code | 263 blank | 121 comment | 407 complexity | d597cabeba97f097678e6e1612978955 MD5 | raw file
Possible License(s): BSD-2-Clause
  1. // -*- mode: C++ -*-
  2. //
  3. // Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 The University of Utah
  4. // All rights reserved.
  5. //
  6. // This file is part of `csmith', a random generator of C programs.
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are met:
  10. //
  11. // * Redistributions of source code must retain the above copyright notice,
  12. // this list of conditions and the following disclaimer.
  13. //
  14. // * Redistributions in binary form must reproduce the above copyright
  15. // notice, this list of conditions and the following disclaimer in the
  16. // documentation and/or other materials provided with the distribution.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. // POSSIBILITY OF SUCH DAMAGE.
  29. //
  30. // This file was derived from a random program generator written by Bryan
  31. // Turner. The attributions in that file was:
  32. //
  33. // Random Program Generator
  34. // Bryan Turner (bryan.turner@pobox.com)
  35. // July, 2005
  36. //
  37. // Contributions and bug fixes by:
  38. // Jan-2007 : Mat Hostetter - Explicit "return 0" for main()
  39. //
  40. /*
  41. Random C/C++ Program Generator
  42. ------------------------------
  43. 1) Create a set of random types to be used throughout the program
  44. 2) Create the main func.
  45. 3) Generate a random block of statements with maximum control & expression nesting depths.
  46. 4) If new functions were defined in #3, then loop back to fill in its body.
  47. 5) When a maximum number of functions is reached, stop generating new functions and finish off the bodies of the remaining funcs.
  48. 6) Output generated program.
  49. GOALS:
  50. - Locate basic errors in compiler front-ends (crashes, etc).
  51. - Ferret out correctness errors in optimization passes.
  52. - Support the design of tools to search for improved optimization paths (partial exection, etc).
  53. TODO:
  54. - Protect back links with a global DEPTH, don't call if DEPTH is too high (avoid infinite recursion)
  55. - Main function generates hash of global state as output of program - use to locate optimization errors.
  56. - Compile in Debug mode vs. Optimized mode, compare hash value at program termination.
  57. - Improve hash function; use stronger hashing (ARCFOUR) and perform hashing at random points in the graph.
  58. - Output only after successful program termination.
  59. FUTURE:
  60. - Complex types
  61. - Type-correct expressions
  62. - Some substitutions allowed
  63. - int, char, short, long, float, double - all interchangeable to some degree (use appropriate casts)
  64. - array <--> pointer
  65. - pointer promotion (ie: passing the pointer to a local var, or droping the pointer to pass by value)
  66. - Memory Allocation & Manipulation?
  67. - Choose random functions to perform allocations
  68. - Choose random children/ancestors to perform deallocations
  69. - Work from leaves to root
  70. - If node uses pointer or array, it is potential heap store allocated.
  71. */
  72. #if HAVE_CONFIG_H
  73. # include <config.h>
  74. #endif
  75. #ifdef WIN32
  76. #pragma warning(disable : 4786) /* Disable annoying warning messages */
  77. #endif
  78. #include <ostream>
  79. #include <fstream>
  80. #include <cstring>
  81. #include <cstdio>
  82. #include "Common.h"
  83. #include "CGOptions.h"
  84. #include "AbsProgramGenerator.h"
  85. #include "git_version.h"
  86. #include "platform.h"
  87. #include "random.h"
  88. using namespace std;
  89. //#define PACKAGE_STRING "csmith 1.1.1"
  90. ///////////////////////////////////////////////////////////////////////////////
  91. // ----------------------------------------------------------------------------
  92. // Globals
  93. // Program seed - allow user to regenerate the same program on different
  94. // platforms.
  95. static unsigned long g_Seed = 0;
  96. // ----------------------------------------------------------------------------
  97. static void
  98. print_version(void)
  99. {
  100. cout << PACKAGE_STRING << endl;
  101. cout << "Git version: " << git_version << endl;
  102. // XXX print copyright, contact info, etc.?
  103. }
  104. // ----------------------------------------------------------------------------
  105. // ----------------------------------------------------------------------------
  106. bool parse_string_arg(const char *arg, string &s)
  107. {
  108. s.assign(arg);
  109. return ((!s.empty()) &&
  110. (s.compare(0, 2, "--")));
  111. }
  112. static bool
  113. parse_int_arg(char *arg, unsigned long *ret)
  114. {
  115. int res;
  116. res = sscanf (arg, "%lu", ret);
  117. if (res == 0) {
  118. cout << "expected integer at arg position " << endl;
  119. return false;
  120. }
  121. return true;
  122. }
  123. static void print_help()
  124. {
  125. cout << "Command line options: " << endl << endl;
  126. // most common options
  127. cout << " --help or -h: print this information." << endl << endl;
  128. cout << " -hh: describe extra options probably useful only for Csmith developers." << endl << endl;
  129. cout << " --version or -v: print the version of Csmith." << endl << endl;
  130. cout << " --seed <seed> or -s <seed>: use <seed> instead of a random seed generated by Csmith." << endl << endl;
  131. cout << " --output <filename> or -o <filename>: specify the output file name." << endl << endl;
  132. // enabling/disabling options
  133. cout << " --argc | --no-argc: generate main function with/without argv and argc being passed (enabled by default)." << endl << endl;
  134. cout << " --arrays | --no-arrays: enable | disable arrays (enabled by default)." << endl << endl;
  135. cout << " --bitfields | --no-bitfields: enable | disable full-bitfields structs (enabled by default)." << endl << endl;
  136. cout << " --checksum | --no-checksum: enable | disable checksum calculation (enabled by default)." << endl << endl;
  137. cout << " --comma-operators | --no-comma-operators: enable | disable comma operators (enabled by default)." << endl << endl;
  138. cout << " --compound-assignment | --no-compound-assignment: enable | disable compound assignments (enabled by default)." << endl << endl;
  139. cout << " --concise: generated programs with minimal comments (disabled by default)." << endl << endl;
  140. cout << " --consts | --no-consts: enable | disable const qualifier (enabled by default)." << endl << endl;
  141. cout << " --divs | --no-divs: enable | disable divisions (enabled by default)." << endl << endl;
  142. cout << " --embedded-assigns | --no-embedded-assigns: enable | disable embedded assignments as sub-expressions (enabled by default)." << endl << endl;
  143. cout << " --pre-incr-operator | --no-pre-incr-operator: enable | disable pre ++ operator (enabled by default)." << endl << endl;
  144. cout << " --pre-decr-operator | --no-pre-decr-operator: enable | disable pre -- operator (enabled by default)." << endl << endl;
  145. cout << " --post-incr-operator | --no-post-incr-operator: enable | disable post ++ operator (enabled by default)." << endl << endl;
  146. cout << " --post-decr-operator | --no-post-decr-operator: enable | disable post -- operator (enabled by default)." << endl << endl;
  147. cout << " --unary-plus-operator | --no-unary-plus-operator: enable | disable + operator (enabled by default)." << endl << endl;
  148. cout << " --jumps | --no-jumps: enable | disable jumps (enabled by default)." << endl << endl;
  149. cout << " --longlong| --no-longlong: enable | disable long long (enabled by default)." << endl << endl;
  150. cout << " --int8 | --no-int8: enable | disable int8_t (enabled by default)." << endl << endl;
  151. cout << " --uint8 | --no-uint8: enable | disable uint8_t (enabled by default)." << endl << endl;
  152. cout << " --float | --no-float: enable | disable float (disabled by default)." << endl << endl;
  153. cout << " --main | --nomain: enable | disable to generate main function (enabled by default)." << endl << endl;
  154. cout << " --math64 | --no-math64: enable | disable 64-bit math ops (enabled by default)." << endl << endl;
  155. cout << " --inline-function | --no-inline-function: enable | disable inline attributes on generated functions." << endl << endl;
  156. cout << " --inline-function-prob <num>: set the probability of each function being marked as inline (default is 50)." << endl << endl;
  157. cout << " --array-oob-prob <num>: set the probability for limit of an array accessing loop to be out of bounds (default is 0)." << endl << endl;
  158. // numbered controls
  159. cout << " --max-array-dim <num>: limit array dimensions to <num>. (default 3)" << endl << endl;
  160. cout << " --max-array-len-per-dim <num>: limit array length per dimension to <num> (default 10)." << endl << endl;
  161. cout << " --max-block-depth <num>: limit depth of nested blocks to <num> (default 5)." << endl << endl;
  162. cout << " --max-block-size <size>: limit the number of non-return statements in a block to <size> (default 4)." << endl << endl;
  163. cout << " --max-expr-complexity <num>: limit expression complexities to <num> (default 10)." << endl << endl;
  164. cout << " --max-funcs <num>: limit the number of functions (besides main) to <num> (default 10)." << endl << endl;
  165. cout << " --max-pointer-depth <depth>: limit the indirect depth of pointers to <depth> (default 2)." << endl << endl;
  166. cout << " --max-struct-fields <num>: limit the number of struct fields to <num> (default 10). " << endl << endl;
  167. cout << " --max-union-fields <num>: limit the number of union fields to <num> (default 5). " << endl << endl;
  168. cout << " --muls | --no-muls: enable | disable multiplications (enabled by default)." << endl << endl;
  169. cout << " --safe-math | --no-safe-math: Emit safe math wrapper functions (enabled by default)." << endl << endl;
  170. cout << " --packed-struct | --no-packed-struct: enable | disable packed structs by adding #pragma pack(1) before struct definition (enabled by default)." << endl << endl;
  171. cout << " --paranoid | --no-paranoid: enable | disable pointer-related assertions (disabled by default)." << endl << endl;
  172. cout << " --pointers | --no-pointers: enable | disable pointers (enabled by default)." << endl << endl;
  173. cout << " --quiet: generate programs with less comments (disabled by default)." << endl << endl;
  174. cout << " --structs | --no-structs: enable | disable to generate structs (enable by default)." << endl << endl;
  175. cout << " --unions | --no-unions: enable | disable to generate unions (enable by default)." << endl << endl;
  176. cout << " --volatiles | --no-volatiles: enable | disable volatiles (enabled by default)." << endl << endl;
  177. cout << " --volatile-pointers | --no-volatile-pointers: enable | disable volatile pointers (enabled by default)." << endl << endl;
  178. cout << " --const-pointers | --no-const-pointers: enable | disable const pointers (enabled by default)." << endl << endl;
  179. cout << " --global-variables | --no-global-variables: enable | disable global variables (enabled by default)." << endl << endl;
  180. cout << " --builtins | --no-builtins: enable | disable to generate builtin functions (disabled by default)." << endl << endl;
  181. cout << " --enable-builtin-kinds k1,k2 | --disable-builtin-kinds k1,k2: enable | disable certain kinds of builtin functions." << endl << endl;
  182. cout << " --builtin-function-prob <num>: set the probability of choosing a builtin function (default is 20)." << endl << endl;
  183. // language options
  184. cout << " --lang-cpp : generate C++ code (C by default)." << endl << endl;
  185. cout << " --cpp11 : generate C++11 code (C++03 by default). Works if lang-cpp is enabled." << endl << endl;
  186. //--------------------------GCC C Extensions--------------------------
  187. cout<< "------------------------------GCC C Extensions------------------------------" << endl << endl;
  188. cout << " --function-attributes | --no-func-attributes: enable | disable generate common function attributes (disabled by default)." << endl << endl;
  189. cout << " --type-attributes | --no-type-attributes: enable | disable generate common type attributes (disabled by default)." << endl << endl;
  190. cout << " --label-attributes | --no-label-attributes: enable | disable generate common label attributes (disabled by default)." << endl << endl;
  191. cout << " --variable-attributes | --no-variable-attributes: enable | disable generate common variable attributes (disabled by default)." << endl << endl;
  192. cout << " --compiler-attributes | --no-compiler-attributes: enable | disable generate function, type, label and variable attributes (disabled by default)." << endl << endl;
  193. cout << " --int128 | --no-int128: enable | disable generate __int128 as datatype extension (disabled by default)." << endl << endl;
  194. cout << " --uint128 | --no-uint128: enable | disable generate unsigned __int128 as datatype extension (disabled by default)." << endl << endl;
  195. cout << " --binary-constant | --no-binary-constant: enable | disable generate binary constant (disabled by default)." << endl << endl;
  196. }
  197. static void print_advanced_help()
  198. {
  199. cout << "'Advanced' command line options that are probably only useful for Csmith's" << endl;
  200. cout << "original developers:" << endl << endl;
  201. // file split options
  202. cout << " --max-split-files <num>: evenly split a generated program into <num> different files(default 0)." << endl << endl;
  203. cout << " --split-files-dir <dir>: generate split-files into <dir> (default ./output)." << endl << endl;
  204. // dfs-exhaustive mode options
  205. cout << " --dfs-exhaustive: enable depth first exhaustive random generation (disabled by default)." << endl << endl;
  206. cout << " --expand-struct: enable the expansion of struct in the exhaustive mode. ";
  207. cout << "Only works in the exhaustive mode and cannot used with --no-structs." << endl << endl;
  208. cout << " --compact-output: print generated programs in compact way. ";
  209. cout << "Only works in the exhaustive mode." << endl << endl;
  210. cout << " --max-nested-struct-level <num>: limit maximum nested level of structs to <num>(default 0). ";
  211. cout << "Only works in the exhaustive mode." << endl << endl;
  212. cout << " --struct-output <file>: dump structs declarations to <file>. ";
  213. cout << "Only works in the exhaustive mode." << endl << endl;
  214. cout << " --prefix-name: prefix names of global functions and variables with increasing numbers. ";
  215. cout << "Only works in the exhaustive mode." << endl << endl;
  216. cout << " --sequence-name-prefix: prefix names of global functions and variables with sequence numbers.";
  217. cout << "Only works in the exhaustive mode." << endl << endl;
  218. cout << " --compatible-check: disallow trivial code such as i = i in random programs. ";
  219. cout << "Only works in the exhaustive mode." << endl << endl;
  220. // target platforms
  221. cout << " --ccomp: generate compcert-compatible code" << endl << endl;
  222. // symblic excutions
  223. cout << " --klee: enable klee extension" << endl << endl;
  224. cout << " --crest: enable crest extension" << endl << endl;
  225. // coverage test options
  226. cout << " --coverage-test: enable coverage-test extension" << endl << endl;
  227. cout << " --coverage-test-size <num>: specify size (default 500) of the array generated to test coverage. ";
  228. cout << "Can only be used with --coverage-test." << endl << endl;
  229. cout << " --func1_max_params <num>: specify the number of symbolic variables passed to func_1 (default 3). ";
  230. cout << "Only used when --crest | --klee | --coverage-test is enabled." << endl << endl;
  231. // struct/union related options
  232. cout << " --fixed-struct-fields: fix the size of struct fields to max-struct-fields (default 10)." << endl << endl;
  233. cout << " --return-structs | --no-return-structs: enable | disable return structs from a function (enabled by default)." << endl << endl;
  234. cout << " --arg-structs | --no-arg-structs: enable | disable structs being used as args (enabled by default)." << endl << endl;
  235. cout << " --return-unions | --no-return-unions: enable | disable return unions from a function (enabled by default)." << endl << endl;
  236. cout << " --arg-unions | --no-arg-unions: enable | disable unions being used as args (enabled by default)." << endl << endl;
  237. cout << " --take-union-field-addr | --take-no-union-field-addr: allow | disallow addresses of union fields to be taken (allowed by default)." << endl << endl;
  238. cout << " --vol-struct-union-fields | --no-vol-struct-union-fields: enable | disable volatile struct/union fields (enabled by default)" << endl << endl;
  239. cout << " --const-struct-union-fields | --no-const-struct-union-fields: enable | disable const struct/union fields (enabled by default)" << endl << endl;
  240. // delta related options
  241. cout << " --delta-monitor [simple]: specify the type of delta monitor. Only [simple] type is supported now." << endl << endl;
  242. cout << " --delta-input [file]: specify the file for delta input." << endl << endl;
  243. cout << " --delta-output [file]: specify the file for delta output (default to <delta-input>)." << endl << endl;
  244. cout << " --go-delta [simple]: run delta reduction on <delta-input>." << endl << endl;
  245. cout << " --no-delta-reduction: output the same program as <delta-input>. ";
  246. cout << "Only works with --go-delta option." << endl << endl;
  247. // probability options
  248. cout << " --dump-default-probabilities <file>: dump the default probability settings into <file>" << endl << endl;
  249. cout << " --dump-random-probabilities <file>: dump the randomized probabilities into <file>" << endl << endl;
  250. cout << " --probability-configuration <file>: use probability configuration <file>" << endl << endl;
  251. cout << " --random-random: enable random probabilities." << endl << endl;
  252. // volatile checking options
  253. cout << " --enable-access-once: enable testing access once macro." << endl << endl;
  254. cout << " --strict-volatile-rule: make sure only one volatile access between any pair of sequence points. " << endl << endl;
  255. cout << " --addr-taken-of-locals: enable addr-taken of local vars. [default]" << endl << endl;
  256. cout << " --no-addr-taken-of-locals: disable addr-taken of local vars. " << endl << endl;
  257. cout << " --fresh-array-ctrl-var-names: create fresh names [i1,i2,i3...] for array control vars rather than use unique names such as i, j, k." << endl << endl;
  258. // other options
  259. cout << " --math-notmp: make csmith generate code for safe_math_macros_notmp." << endl << endl;
  260. cout << " --strict-const-arrays: restrict array elements to constants." << endl << endl;
  261. cout << " --partial-expand <assignment[,for[,block[,if-else[,invoke[,return]]]]]: ";
  262. cout <<"partial-expand controls which what kind of statements should be generated first. ";
  263. cout <<"For example, it could make Csmith start to generate if-else without go over assignment or for." << endl << endl;
  264. cout << " --dangling-global-pointers | --no-dangling-global-pointers: enable | disable to reset all dangling global pointers to null at the end of main. (enabled by default)" << endl << endl;
  265. cout << " --check-global: print the values of all integer global variables." << endl << endl;
  266. cout << " --monitor-funcs <name1,name2...>: dump the checksums after each statement in the monitored functions." << endl << endl;
  267. cout << " --step-hash-by-stmt: dump the checksum after each statement. It is applied to all functions unless --monitor-funcs is specified." << endl << endl;
  268. cout << " --stop-by-stmt <num>: try to stop generating statements after the statement with id <num>." << endl << endl;
  269. cout << " --const-as-condition: enable const to be conditions of if-statements. " << endl << endl;
  270. cout << " --match-exact-qualifiers: match exact const/volatile qualifiers for LHS and RHS of assignments." << endl << endl;
  271. cout << " --reduce <file>: reduce random program under the direction of the configuration file." << endl << endl;
  272. cout << " --return-dead-pointer | --no-return-dead-pointer: allow | disallow functions from returning dangling pointers (disallowed by default)." << endl << endl;
  273. cout << " --identify-wrappers: assign ids to used safe math wrappers." << endl << endl;
  274. cout << " --safe-math-wrappers <id1,id2...>: specifiy ids of wrapper functions that are necessary to avoid undefined behaviors, use 0 to specify none." << endl << endl;
  275. cout << " --mark-mutable-const: mark constants that can be mutated with parentheses (disabled by default)." << endl << endl;
  276. cout << " --force-non-uniform-arrays | --no-force-non-uniform-arrays: force integer arrays to be initialized with multiple values (enabled by default)." << endl << endl;
  277. cout << " --null-ptr-deref-prob <N>: allow null pointers to be dereferenced with probability N% (0 by default)." << endl << endl;
  278. cout << " --dangling-ptr-deref-prob <N>: allow dangling pointers to be dereferenced with probability N% (0 by default)." << endl << endl;
  279. cout << " --max-struct-nested-level: controls the max depth of nested structs (default is 3)." << endl << endl;
  280. cout << " --no-hash-value-printf: do not emit printf on the index of an array" << endl << endl;
  281. cout << " --no-signed-char-index: do not allow a var of type char to be used as array index" << endl << endl;
  282. cout << " --strict-float: do not allow assignments between floats and integers" << endl << endl;
  283. // type size options
  284. cout << " --int-size <size>: specify integer size of target (default taken from platform.info if it exists otherwise from host)" << endl << endl;
  285. cout << " --ptr-size <size>: specify pointer size of target (default taken from platform.info if it exists otherwise from host)" << endl << endl;
  286. }
  287. void arg_check(int argc, int i)
  288. {
  289. if (i >= argc) {
  290. cout << "expect arg at pos " << i << std::endl;
  291. exit(-1);
  292. }
  293. }
  294. // ----------------------------------------------------------------------------
  295. int
  296. main(int argc, char **argv)
  297. {
  298. g_Seed = platform_gen_seed();
  299. CGOptions::set_default_settings();
  300. for (int i=1; i<argc; i++) {
  301. if (strcmp (argv[i], "--help") == 0 ||
  302. strcmp (argv[i], "-h") == 0) {
  303. print_help();
  304. return 0;
  305. }
  306. if (strcmp (argv[i], "-hh") == 0) {
  307. print_advanced_help();
  308. return 0;
  309. }
  310. if (strcmp (argv[i], "--version") == 0 ||
  311. strcmp (argv[i], "-v") == 0) {
  312. print_version();
  313. return 0;
  314. }
  315. if (strcmp (argv[i], "--seed") == 0 ||
  316. strcmp (argv[i], "-s") == 0) {
  317. i++;
  318. arg_check(argc, i);
  319. if (!parse_int_arg(argv[i], &g_Seed))
  320. exit(-1);
  321. continue;
  322. }
  323. if (strcmp (argv[i], "--max-block-size") == 0) {
  324. unsigned long size = 0;
  325. i++;
  326. arg_check(argc, i);
  327. if (!parse_int_arg(argv[i], &size))
  328. exit(-1);
  329. CGOptions::max_block_size(size);
  330. continue;
  331. }
  332. if (strcmp (argv[i], "--max-funcs") == 0) {
  333. unsigned long size = 0;
  334. i++;
  335. arg_check(argc, i);
  336. if (!parse_int_arg(argv[i], &size))
  337. exit(-1);
  338. CGOptions::max_funcs(size);
  339. continue;
  340. }
  341. if (strcmp (argv[i], "--func1_max_params") == 0) {
  342. unsigned long num = 0;
  343. i++;
  344. arg_check(argc, i);
  345. if (!parse_int_arg(argv[i], &num))
  346. exit(-1);
  347. CGOptions::func1_max_params(num);
  348. continue;
  349. }
  350. if (strcmp (argv[i], "--klee") == 0) {
  351. CGOptions::klee(true);
  352. continue;
  353. }
  354. if (strcmp (argv[i], "--crest") == 0) {
  355. CGOptions::crest(true);
  356. continue;
  357. }
  358. if (strcmp (argv[i], "--ccomp") == 0) {
  359. CGOptions::ccomp(true);
  360. continue;
  361. }
  362. if (strcmp (argv[i], "--coverage-test") == 0) {
  363. CGOptions::coverage_test(true);
  364. continue;
  365. }
  366. if (strcmp (argv[i], "--coverage-test-size") == 0) {
  367. unsigned long size = 0;
  368. i++;
  369. arg_check(argc, i);
  370. if (!parse_int_arg(argv[i], &size))
  371. exit(-1);
  372. CGOptions::coverage_test_size(size);
  373. continue;
  374. }
  375. if (strcmp (argv[i], "--max-split-files") == 0) {
  376. unsigned long size = 0;
  377. i++;
  378. arg_check(argc, i);
  379. if (!parse_int_arg(argv[i], &size))
  380. exit(-1);
  381. CGOptions::max_split_files(size);
  382. continue;
  383. }
  384. if (strcmp (argv[i], "--split-files-dir") == 0) {
  385. string dir;
  386. i++;
  387. arg_check(argc, i);
  388. if (!parse_string_arg(argv[i], dir)) {
  389. cout << "please specify <dir>" << std::endl;
  390. exit(-1);
  391. }
  392. CGOptions::split_files_dir(dir);
  393. continue;
  394. }
  395. if (strcmp (argv[i], "--dfs-exhaustive") == 0) {
  396. CGOptions::dfs_exhaustive(true);
  397. CGOptions::random_based(false);
  398. continue;
  399. }
  400. if (strcmp (argv[i], "--compact-output") == 0) {
  401. CGOptions::compact_output(true);
  402. continue;
  403. }
  404. if (strcmp (argv[i], "--packed-struct") == 0) {
  405. CGOptions::packed_struct(true);
  406. continue;
  407. }
  408. if (strcmp (argv[i], "--no-packed-struct") == 0) {
  409. CGOptions::packed_struct(false);
  410. continue;
  411. }
  412. if (strcmp (argv[i], "--bitfields") == 0) {
  413. CGOptions::bitfields(true);
  414. continue;
  415. }
  416. if (strcmp (argv[i], "--no-bitfields") == 0) {
  417. CGOptions::bitfields(false);
  418. continue;
  419. }
  420. if (strcmp (argv[i], "--prefix-name") == 0) {
  421. CGOptions::prefix_name(true);
  422. continue;
  423. }
  424. if (strcmp (argv[i], "--sequence-name-prefix") == 0) {
  425. CGOptions::sequence_name_prefix(true);
  426. continue;
  427. }
  428. if (strcmp (argv[i], "--compatible-check") == 0) {
  429. CGOptions::compatible_check(true);
  430. continue;
  431. }
  432. if (strcmp (argv[i], "--partial-expand") == 0) {
  433. string s;
  434. i++;
  435. arg_check(argc, i);
  436. if (!parse_string_arg(argv[i], s)) {
  437. cout << "--partial-expand needs options" << std::endl;
  438. exit(-1);
  439. }
  440. CGOptions::partial_expand(s);
  441. continue;
  442. }
  443. if (strcmp (argv[i], "--paranoid") == 0) {
  444. CGOptions::paranoid(true);
  445. continue;
  446. }
  447. if (strcmp (argv[i], "--no-paranoid") == 0) {
  448. CGOptions::paranoid(false);
  449. continue;
  450. }
  451. if (strcmp (argv[i], "--quiet") == 0) {
  452. CGOptions::quiet(true);
  453. continue;
  454. }
  455. if (strcmp (argv[i], "--main") == 0) {
  456. CGOptions::nomain(false);
  457. continue;
  458. }
  459. if (strcmp (argv[i], "--nomain") == 0) {
  460. CGOptions::nomain(true);
  461. continue;
  462. }
  463. if (strcmp (argv[i], "--compound-assignment") == 0) {
  464. CGOptions::compound_assignment(true);
  465. continue;
  466. }
  467. if (strcmp (argv[i], "--no-compound-assignment") == 0) {
  468. CGOptions::compound_assignment(false);
  469. continue;
  470. }
  471. if (strcmp (argv[i], "--structs") == 0) {
  472. CGOptions::use_struct(true);
  473. continue;
  474. }
  475. if (strcmp (argv[i], "--no-structs") == 0) {
  476. CGOptions::use_struct(false);
  477. continue;
  478. }
  479. if (strcmp (argv[i], "--unions") == 0) {
  480. CGOptions::use_union(true);
  481. continue;
  482. }
  483. if (strcmp (argv[i], "--no-unions") == 0) {
  484. CGOptions::use_union(false);
  485. continue;
  486. }
  487. if (strcmp (argv[i], "--argc") == 0) {
  488. CGOptions::accept_argc(true);
  489. continue;
  490. }
  491. if (strcmp (argv[i], "--no-argc") == 0) {
  492. CGOptions::accept_argc(false);
  493. continue;
  494. }
  495. if (strcmp (argv[i], "--expand-struct") == 0) {
  496. CGOptions::expand_struct(true);
  497. continue;
  498. }
  499. if (strcmp (argv[i], "--fixed-struct-fields") == 0) {
  500. CGOptions::fixed_struct_fields(true);
  501. continue;
  502. }
  503. if (strcmp (argv[i], "--max-struct-fields") ==0 ) {
  504. unsigned long ret;
  505. i++;
  506. arg_check(argc, i);
  507. if (!parse_int_arg(argv[i], &ret))
  508. exit(-1);
  509. CGOptions::max_struct_fields(ret);
  510. continue;
  511. }
  512. if (strcmp (argv[i], "--max-union-fields") ==0 ) {
  513. unsigned long ret;
  514. i++;
  515. arg_check(argc, i);
  516. if (!parse_int_arg(argv[i], &ret))
  517. exit(-1);
  518. CGOptions::max_union_fields(ret);
  519. continue;
  520. }
  521. if (strcmp (argv[i], "--max-nested-struct-level") ==0 ) {
  522. unsigned long ret;
  523. i++;
  524. arg_check(argc, i);
  525. if (!parse_int_arg(argv[i], &ret))
  526. exit(-1);
  527. CGOptions::max_nested_struct_level(ret);
  528. continue;
  529. }
  530. if (strcmp (argv[i], "--struct-output") == 0) {
  531. string s;
  532. i++;
  533. arg_check(argc, i);
  534. if (!parse_string_arg(argv[i], s))
  535. exit(-1);
  536. CGOptions::struct_output(s);
  537. continue;
  538. }
  539. if (strcmp (argv[i], "--dfs-debug-sequence") == 0) {
  540. string s;
  541. i++;
  542. arg_check(argc, i);
  543. if (!parse_string_arg(argv[i], s))
  544. exit(-1);
  545. CGOptions::dfs_debug_sequence(s);
  546. continue;
  547. }
  548. if (strcmp (argv[i], "--max-exhaustive-depth") ==0 ) {
  549. unsigned long ret;
  550. i++;
  551. arg_check(argc, i);
  552. if (!parse_int_arg(argv[i], &ret))
  553. exit(-1);
  554. CGOptions::max_exhaustive_depth(ret);
  555. continue;
  556. }
  557. if (strcmp (argv[i], "--max-pointer-depth") ==0 ) {
  558. unsigned long ret;
  559. i++;
  560. arg_check(argc, i);
  561. if (!parse_int_arg(argv[i], &ret))
  562. exit(-1);
  563. CGOptions::max_indirect_level(ret);
  564. continue;
  565. }
  566. if (strcmp (argv[i], "--output") == 0 ||
  567. strcmp (argv[i], "-o") == 0) {
  568. string o_file;
  569. i++;
  570. arg_check(argc, i);
  571. if (!parse_string_arg(argv[i], o_file))
  572. exit(-1);
  573. CGOptions::output_file(o_file);
  574. continue;
  575. }
  576. if (strcmp (argv[i], "--delta-monitor") == 0) {
  577. string monitor;
  578. i++;
  579. arg_check(argc, i);
  580. if (!parse_string_arg(argv[i], monitor)) {
  581. cout<< "please specify one delta monitor!" << std::endl;
  582. exit(-1);
  583. }
  584. CGOptions::delta_monitor(monitor);
  585. continue;
  586. }
  587. if (strcmp (argv[i], "--delta-output") == 0) {
  588. string o_file;
  589. i++;
  590. arg_check(argc, i);
  591. if (!parse_string_arg(argv[i], o_file)) {
  592. cout<< "please specify delta output file!" << std::endl;
  593. exit(-1);
  594. }
  595. CGOptions::delta_output(o_file);
  596. continue;
  597. }
  598. if (strcmp (argv[i], "--go-delta") == 0) {
  599. string monitor;
  600. i++;
  601. arg_check(argc, i);
  602. if (!parse_string_arg(argv[i], monitor)) {
  603. cout<< "please specify one delta type!" << std::endl;
  604. exit(-1);
  605. }
  606. CGOptions::go_delta(monitor);
  607. continue;
  608. }
  609. if (strcmp (argv[i], "--no-delta-reduction") == 0) {
  610. CGOptions::no_delta_reduction(true);
  611. continue;
  612. }
  613. if (strcmp (argv[i], "--math-notmp") == 0) {
  614. CGOptions::math_notmp(true);
  615. continue;
  616. }
  617. if (strcmp (argv[i], "--math64") == 0) {
  618. CGOptions::math64(true);
  619. continue;
  620. }
  621. if (strcmp (argv[i], "--no-math64") == 0) {
  622. CGOptions::math64(false);
  623. continue;
  624. }
  625. if (strcmp (argv[i], "--inline-function") == 0) {
  626. CGOptions::inline_function(true);
  627. continue;
  628. }
  629. if (strcmp (argv[i], "--no-inline-function") == 0) {
  630. CGOptions::inline_function(false);
  631. continue;
  632. }
  633. if (strcmp (argv[i], "--longlong") == 0) {
  634. CGOptions::longlong(true);
  635. continue;
  636. }
  637. if (strcmp (argv[i], "--no-longlong") == 0) {
  638. CGOptions::longlong(false);
  639. continue;
  640. }
  641. if (strcmp (argv[i], "--int8") == 0) {
  642. CGOptions::int8(true);
  643. continue;
  644. }
  645. if (strcmp (argv[i], "--no-int8") == 0) {
  646. CGOptions::int8(false);
  647. continue;
  648. }
  649. if (strcmp (argv[i], "--uint8") == 0) {
  650. CGOptions::uint8(true);
  651. continue;
  652. }
  653. if (strcmp (argv[i], "--no-uint8") == 0) {
  654. CGOptions::uint8(false);
  655. continue;
  656. }
  657. if (strcmp (argv[i], "--float") == 0) {
  658. CGOptions::enable_float(true);
  659. continue;
  660. }
  661. if (strcmp (argv[i], "--no-float") == 0) {
  662. CGOptions::enable_float(false);
  663. continue;
  664. }
  665. if (strcmp (argv[i], "--strict-float") == 0) {
  666. CGOptions::strict_float(true);
  667. continue;
  668. }
  669. if (strcmp (argv[i], "--pointers") == 0) {
  670. CGOptions::pointers(true);
  671. continue;
  672. }
  673. if (strcmp (argv[i], "--no-pointers") == 0) {
  674. CGOptions::pointers(false);
  675. continue;
  676. }
  677. if (strcmp (argv[i], "--function-attributes") == 0) {
  678. CGOptions::func_attr_flag(true);
  679. continue;
  680. }
  681. if (strcmp (argv[i], "--no-function_attributes") == 0) {
  682. CGOptions::func_attr_flag(false);
  683. continue;
  684. }
  685. if (strcmp (argv[i], "--type-attributes") == 0) {
  686. CGOptions::type_attr_flag(true);
  687. continue;
  688. }
  689. if (strcmp (argv[i], "--no-type-attributes") == 0) {
  690. CGOptions::type_attr_flag(false);
  691. continue;
  692. }
  693. if (strcmp (argv[i], "--label-attributes") == 0) {
  694. CGOptions::label_attr_flag(true);
  695. continue;
  696. }
  697. if (strcmp (argv[i], "--no-label-attributes") == 0) {
  698. CGOptions::label_attr_flag(false);
  699. continue;
  700. }
  701. if (strcmp (argv[i], "--variable-attributes") == 0) {
  702. CGOptions::var_attr_flag(true);
  703. continue;
  704. }
  705. if (strcmp (argv[i], "--no-variable-attributes") == 0) {
  706. CGOptions::var_attr_flag(false);
  707. continue;
  708. }
  709. if (strcmp (argv[i], "--compiler-attributes") == 0) {
  710. CGOptions::func_attr_flag(true);
  711. CGOptions::type_attr_flag(true);
  712. CGOptions::label_attr_flag(true);
  713. CGOptions::var_attr_flag(true);
  714. continue;
  715. }
  716. if (strcmp (argv[i], "--no-compiler-attributes") == 0) {
  717. CGOptions::func_attr_flag(false);
  718. CGOptions::type_attr_flag(false);
  719. CGOptions::label_attr_flag(false);
  720. CGOptions::var_attr_flag(false);
  721. continue;
  722. }
  723. if (strcmp (argv[i], "--int128") == 0) {
  724. CGOptions::Int128(true);
  725. continue;
  726. }
  727. if (strcmp (argv[i], "--no-int128") == 0) {
  728. CGOptions::Int128(false);
  729. continue;
  730. }
  731. if (strcmp (argv[i], "--uint128") == 0) {
  732. CGOptions::UInt128(true);
  733. continue;
  734. }
  735. if (strcmp (argv[i], "--no-uint128") == 0) {
  736. CGOptions::UInt128(false);
  737. continue;
  738. }
  739. if (strcmp (argv[i], "--binary-constant") == 0) {
  740. CGOptions::binary_constant(true);
  741. continue;
  742. }
  743. if (strcmp (argv[i], "--no-binary-constant") == 0) {
  744. CGOptions::binary_constant(false);
  745. continue;
  746. }
  747. if (strcmp (argv[i], "--max-array-dim") ==0 ) {
  748. unsigned long dim;
  749. i++;
  750. arg_check(argc, i);
  751. if (!parse_int_arg(argv[i], &dim))
  752. exit(-1);
  753. CGOptions::max_array_dimensions(dim);
  754. continue;
  755. }
  756. if (strcmp (argv[i], "--max-array-len-per-dim") ==0 ) {
  757. unsigned long length;
  758. i++;
  759. arg_check(argc, i);
  760. if (!parse_int_arg(argv[i], &length))
  761. exit(-1);
  762. CGOptions::max_array_length_per_dimension(length);
  763. continue;
  764. }
  765. if (strcmp (argv[i], "--arrays") == 0) {
  766. CGOptions::arrays(true);
  767. continue;
  768. }
  769. if (strcmp (argv[i], "--no-arrays") == 0) {
  770. CGOptions::arrays(false);
  771. continue;
  772. }
  773. if (strcmp (argv[i], "--strict-const-arrays") == 0) {
  774. CGOptions::strict_const_arrays(true);
  775. continue;
  776. }
  777. if (strcmp (argv[i], "--jumps") == 0) {
  778. CGOptions::jumps(true);
  779. continue;
  780. }
  781. if (strcmp (argv[i], "--no-jumps") == 0) {
  782. CGOptions::jumps(false);
  783. continue;
  784. }
  785. if (strcmp (argv[i], "--return-structs") == 0) {
  786. CGOptions::return_structs(true);
  787. continue;
  788. }
  789. if (strcmp (argv[i], "--no-return-structs") == 0) {
  790. CGOptions::return_structs(false);
  791. continue;
  792. }
  793. if (strcmp (argv[i], "--arg-structs") == 0) {
  794. CGOptions::arg_structs(true);
  795. continue;
  796. }
  797. if (strcmp (argv[i], "--no-arg-structs") == 0) {
  798. CGOptions::arg_structs(false);
  799. continue;
  800. }
  801. if (strcmp (argv[i], "--return-unions") == 0) {
  802. CGOptions::return_unions(true);
  803. continue;
  804. }
  805. if (strcmp (argv[i], "--no-return-unions") == 0) {
  806. CGOptions::return_unions(false);
  807. continue;
  808. }
  809. if (strcmp (argv[i], "--arg-unions") == 0) {
  810. CGOptions::arg_unions(true);
  811. continue;
  812. }
  813. if (strcmp (argv[i], "--no-arg-unions") == 0) {
  814. CGOptions::arg_unions(false);
  815. continue;
  816. }
  817. if (strcmp (argv[i], "--volatiles") == 0) {
  818. CGOptions::volatiles(true);
  819. continue;
  820. }
  821. if (strcmp (argv[i], "--no-volatiles") == 0) {
  822. CGOptions::volatiles(false);
  823. continue;
  824. }
  825. if (strcmp (argv[i], "--volatile-pointers") == 0) {
  826. CGOptions::volatile_pointers(true);
  827. continue;
  828. }
  829. if (strcmp (argv[i], "--no-volatile-pointers") == 0) {
  830. CGOptions::volatile_pointers(false);
  831. continue;
  832. }
  833. if (strcmp (argv[i], "--const-pointers") == 0) {
  834. CGOptions::const_pointers(true);
  835. continue;
  836. }
  837. if (strcmp (argv[i], "--no-const-pointers") == 0) {
  838. CGOptions::const_pointers(false);
  839. continue;
  840. }
  841. if (strcmp (argv[i], "--global-variables") == 0) {
  842. CGOptions::global_variables(true);
  843. continue;
  844. }
  845. if (strcmp (argv[i], "--no-global-variables") == 0) {
  846. CGOptions::global_variables(false);
  847. continue;
  848. }
  849. if (strcmp (argv[i], "--enable-access-once") == 0) {
  850. CGOptions::access_once(true);
  851. continue;
  852. }
  853. if (strcmp (argv[i], "--strict-volatile-rule") == 0) {
  854. CGOptions::strict_volatile_rule(true);
  855. continue;
  856. }
  857. if (strcmp (argv[i], "--addr-taken-of-locals") == 0) {
  858. CGOptions::addr_taken_of_locals(true);
  859. continue;
  860. }
  861. if (strcmp (argv[i], "--no-addr-taken-of-locals") == 0) {
  862. CGOptions::addr_taken_of_locals(false);
  863. continue;
  864. }
  865. if (strcmp (argv[i], "--fresh-array-ctrl-var-names") == 0) {
  866. CGOptions::fresh_array_ctrl_var_names(true);
  867. continue;
  868. }
  869. if (strcmp (argv[i], "--consts") == 0) {
  870. CGOptions::consts(true);
  871. continue;
  872. }
  873. if (strcmp (argv[i], "--no-consts") == 0) {
  874. CGOptions::consts(false);
  875. continue;
  876. }
  877. if (strcmp (argv[i], "--dangling-global-pointers") == 0) {
  878. CGOptions::dangling_global_ptrs(true);
  879. continue;
  880. }
  881. if (strcmp (argv[i], "--no-dangling-global-pointers") == 0) {
  882. CGOptions::dangling_global_ptrs(false);
  883. continue;
  884. }
  885. if (strcmp (argv[i], "--divs") == 0) {
  886. CGOptions::divs(true);
  887. continue;
  888. }
  889. if (strcmp (argv[i], "--no-divs") == 0) {
  890. CGOptions::divs(false);
  891. continue;
  892. }
  893. if (strcmp (argv[i], "--muls") == 0) {
  894. CGOptions::muls(true);
  895. continue;
  896. }
  897. if (strcmp (argv[i], "--no-muls") == 0) {
  898. CGOptions::muls(false);
  899. continue;
  900. }
  901. if (strcmp (argv[i], "--checksum") == 0) {
  902. CGOptions::compute_hash(true);
  903. continue;
  904. }
  905. if (strcmp (argv[i], "--no-checksum") == 0) {
  906. CGOptions::compute_hash(false);
  907. continue;
  908. }
  909. if (strcmp (argv[i], "--builtins") == 0) {
  910. CGOptions::builtins(true);
  911. continue;
  912. }
  913. if (strcmp (argv[i], "--no-builtins") == 0) {
  914. CGOptions::builtins(false);
  915. continue;
  916. }
  917. if (strcmp (argv[i], "--random-random") == 0) {
  918. CGOptions::random_random(true);
  919. continue;
  920. }
  921. if (strcmp (argv[i], "--check-global") == 0) {
  922. CGOptions::blind_check_global(true);
  923. continue;
  924. }
  925. if (strcmp (argv[i], "--step-hash-by-stmt") == 0) {
  926. CGOptions::step_hash_by_stmt(true);
  927. continue;
  928. }
  929. if (strcmp (argv[i], "--stop-by-stmt") ==0 ) {
  930. unsigned long num;
  931. i++;
  932. arg_check(argc, i);
  933. if (!parse_int_arg(argv[i], &num))
  934. exit(-1);
  935. CGOptions::stop_by_stmt(num);
  936. continue;
  937. }
  938. if (strcmp (argv[i], "--monitor-funcs") == 0) {
  939. string vname;
  940. i++;
  941. arg_check(argc, i);
  942. if (!parse_string_arg(argv[i], vname)) {
  943. cout<< "please specify name(s) of the func(s) you want to monitor" << std::endl;
  944. exit(-1);
  945. }
  946. CGOptions::monitored_funcs(vname);
  947. continue;
  948. }
  949. if (strcmp (argv[i], "--delta-input") == 0) {
  950. string filename;
  951. i++;
  952. arg_check(argc, i);
  953. if (!parse_string_arg(argv[i], filename)) {
  954. cout<< "please specify delta output file!" << std::endl;
  955. exit(-1);
  956. }
  957. CGOptions::delta_input(filename);
  958. continue;
  959. }
  960. if (strcmp (argv[i], "--dump-default-probabilities") == 0) {
  961. string filename;
  962. i++;
  963. arg_check(argc, i);
  964. if (!parse_string_arg(argv[i], filename)) {
  965. cout<< "please pass probability configuration output file!" << std::endl;
  966. exit(-1);
  967. }
  968. CGOptions::dump_default_probabilities(filename);
  969. continue;
  970. }
  971. if (strcmp (argv[i], "--dump-random-probabilities") == 0) {
  972. string filename;
  973. i++;
  974. arg_check(argc, i);
  975. if (!parse_string_arg(argv[i], filename)) {
  976. cout<< "please pass probability configuration output file!" << std::endl;
  977. exit(-1);
  978. }
  979. CGOptions::dump_random_probabilities(filename);
  980. continue;
  981. }
  982. if (strcmp (argv[i], "--probability-configuration") == 0) {
  983. string filename;
  984. i++;
  985. arg_check(argc, i);
  986. if (!parse_string_arg(argv[i], filename)) {
  987. cout<< "please probability configuration file!" << std::endl;
  988. exit(-1);
  989. }
  990. CGOptions::probability_configuration(filename);
  991. continue;
  992. }
  993. if (strcmp (argv[i], "--const-as-condition") == 0) {
  994. CGOptions::const_as_condition(true);
  995. continue;
  996. }
  997. if (strcmp (argv[i], "--match-exact-qualifiers") == 0) {
  998. CGOptions::match_exact_qualifiers(true);
  999. continue;
  1000. }
  1001. if (strcmp (argv[i], "--no-return-dead-pointer") == 0) {
  1002. CGOptions::no_return_dead_ptr(true);
  1003. continue;
  1004. }
  1005. if (strcmp (argv[i], "--return-dead-pointer") == 0) {
  1006. CGOptions::no_return_dead_ptr(false);
  1007. continue;
  1008. }
  1009. if (strcmp (argv[i], "--concise") == 0) {
  1010. //CGOptions::quiet(true);
  1011. //CGOptions::paranoid(false);
  1012. CGOptions::concise(true);
  1013. continue;
  1014. }
  1015. if (strcmp (argv[i], "--identify-wrappers") == 0) {
  1016. CGOptions::identify_wrappers(true);
  1017. continue;
  1018. }
  1019. if (strcmp (argv[i], "--safe-math-wrappers") == 0) {
  1020. string ids;
  1021. i++;
  1022. arg_check(argc, i);
  1023. if (!parse_string_arg(argv[i], ids)) {
  1024. cout<< "please specify safe math wrappers in the form of id1,id2..." << std::endl;
  1025. exit(-1);
  1026. }
  1027. CGOptions::safe_math_wrapper(ids);
  1028. continue;
  1029. }
  1030. if (strcmp (argv[i], "--mark-mutable-const") == 0) {
  1031. CGOptions::mark_mutable_const(true);
  1032. continue;
  1033. }
  1034. if (strcmp (argv[i], "--force-globals-static") == 0) {
  1035. CGOptions::force_globals_static(true);
  1036. continue;
  1037. }
  1038. if (strcmp (argv[i], "--force-non-uniform-arrays") == 0) {
  1039. CGOptions::force_non_uniform_array_init(true);
  1040. continue;
  1041. }
  1042. if (strcmp (argv[i], "--no-force-non-uniform-arrays") == 0) {
  1043. CGOptions::force_non_uniform_array_init(false);
  1044. continue;
  1045. }
  1046. if (strcmp (argv[i], "--inline-function-prob") == 0 ) {
  1047. unsigned long prob;
  1048. i++;
  1049. arg_check(argc, i);
  1050. if (!parse_int_arg(argv[i], &prob))
  1051. exit(-1);
  1052. CGOptions::inline_function_prob(prob);
  1053. continue;
  1054. }
  1055. if (strcmp (argv[i], "--builtin-function-prob") == 0 ) {
  1056. unsigned long prob;
  1057. i++;
  1058. arg_check(argc, i);
  1059. if (!parse_int_arg(argv[i], &prob))
  1060. exit(-1);
  1061. CGOptions::builtin_function_prob(prob);
  1062. continue;
  1063. }
  1064. if (strcmp (argv[i], "--array-oob-prob") == 0 ) {
  1065. unsigned long prob;
  1066. i++;
  1067. arg_check(argc, i);
  1068. if (!parse_int_arg(argv[i], &prob))
  1069. exit(-1);
  1070. CGOptions::array_oob_prob(prob);
  1071. continue;
  1072. }
  1073. if (strcmp (argv[i], "--enable-builtin-kinds") == 0) {
  1074. string kinds;
  1075. i++;
  1076. arg_check(argc, i);
  1077. if (!parse_string_arg(argv[i], kinds)) {
  1078. cout<< "please specify enabled builtin kinds in the form of k1,k2..." << std::endl;
  1079. exit(-1);
  1080. }
  1081. CGOptions::enable_builtin_kinds(kinds);
  1082. continue;
  1083. }
  1084. if (strcmp (argv[i], "--disable-builtin-kinds") == 0) {
  1085. string kinds;
  1086. i++;
  1087. arg_check(argc, i);
  1088. if (!parse_string_arg(argv[i], kinds)) {
  1089. cout<< "please specify disabled builtin kinds in the form of k1,k2..." << std::endl;
  1090. exit(-1);
  1091. }
  1092. CGOptions::disable_builtin_kinds(kinds);
  1093. continue;
  1094. }
  1095. if (strcmp (argv[i], "--null-ptr-deref-prob") == 0 ) {
  1096. unsigned long prob;
  1097. i++;
  1098. arg_check(argc, i);
  1099. if (!parse_int_arg(argv[i], &prob))
  1100. exit(-1);
  1101. CGOptions::null_pointer_dereference_prob(prob);
  1102. continue;
  1103. }
  1104. if (strcmp (argv[i], "--dangling-ptr-deref-prob") == 0 ) {
  1105. unsigned long prob;
  1106. i++;
  1107. arg_check(argc, i);
  1108. if (!parse_int_arg(argv[i], &prob))
  1109. exit(-1);
  1110. CGOptions::dead_pointer_dereference_prob(prob);
  1111. continue;
  1112. }
  1113. if (strcmp (argv[i], "--max-expr-complexity") == 0 ) {
  1114. unsigned long comp;
  1115. i++;
  1116. arg_check(argc, i);
  1117. if (!parse_int_arg(argv[i], &comp))
  1118. exit(-1);
  1119. CGOptions::max_expr_depth(comp);
  1120. continue;
  1121. }
  1122. if (strcmp (argv[i], "--max-block-depth") == 0 ) {
  1123. unsigned long depth;
  1124. i++;
  1125. arg_check(argc, i);
  1126. if (!parse_int_arg(argv[i], &depth))
  1127. exit(-1);
  1128. CGOptions::max_blk_depth(depth);
  1129. continue;
  1130. }
  1131. if (strcmp (argv[i], "--max-struct-nested-level") == 0 ) {
  1132. unsigned long depth;
  1133. i++;
  1134. arg_check(argc, i);
  1135. if (!parse_int_arg(argv[i], &depth))
  1136. exit(-1);
  1137. CGOptions::max_nested_struct_level(depth);
  1138. continue;
  1139. }
  1140. if (strcmp (argv[i], "--pre-incr-operator") == 0) {
  1141. CGOptions::pre_incr_operator(true);
  1142. continue;
  1143. }
  1144. if (strcmp (argv[i], "--no-pre-incr-operator") == 0) {
  1145. CGOptions::pre_incr_operator(false);
  1146. continue;
  1147. }
  1148. if (strcmp (argv[i], "--pre-decr-operator") == 0) {
  1149. CGOptions::pre_decr_operator(true);
  1150. continue;
  1151. }
  1152. if (strcmp (argv[i], "--no-pre-decr-operator") == 0) {
  1153. CGOptions::pre_decr_operator(false);
  1154. continue;
  1155. }
  1156. if (strcmp (argv[i], "--post-incr-operator") == 0) {
  1157. CGOptions::post_incr_operator(true);
  1158. continue;
  1159. }
  1160. if (strcmp (argv[i], "--no-post-incr-operator") == 0) {
  1161. CGOptions::post_incr_operator(false);
  1162. continue;
  1163. }
  1164. if (strcmp (argv[i], "--post-decr-operator") == 0) {
  1165. CGOptions::post_decr_operator(true);
  1166. continue;
  1167. }
  1168. if (strcmp (argv[i], "--no-post-decr-operator") == 0) {
  1169. CGOptions::post_decr_operator(false);
  1170. continue;
  1171. }
  1172. if (strcmp (argv[i], "--unary-plus-operator") == 0) {
  1173. CGOptions::unary_plus_operator(true);
  1174. continue;
  1175. }
  1176. if (strcmp (argv[i], "--no-unary-plus-operator") == 0) {
  1177. CGOptions::unary_plus_operator(false);
  1178. continue;
  1179. }
  1180. if (strcmp (argv[i], "--embedded-assigns") == 0) {
  1181. CGOptions::use_embedded_assigns(true);
  1182. continue;
  1183. }
  1184. if (strcmp (argv[i], "--no-safe-math") == 0){
  1185. CGOptions::avoid_signed_overflow(false);
  1186. continue;
  1187. }
  1188. if (strcmp (argv[i], "--safe-math") == 0){
  1189. CGOptions::avoid_signed_overflow(true);
  1190. continue;
  1191. }
  1192. if (strcmp (argv[i], "--no-embedded-assigns") == 0) {
  1193. CGOptions::use_embedded_assigns(false);
  1194. continue;
  1195. }
  1196. if (strcmp (argv[i], "--comma-operators") == 0) {
  1197. CGOptions::use_comma_exprs(true);
  1198. continue;
  1199. }
  1200. if (strcmp (argv[i], "--no-comma-operators") == 0) {
  1201. CGOptions::use_comma_exprs(false);
  1202. continue;
  1203. }
  1204. if (strcmp (argv[i], "--take-no-union-field-addr") == 0) {
  1205. CGOptions::take_union_field_addr(false);
  1206. continue;
  1207. }
  1208. if (strcmp (argv[i], "--take-union-field-addr") == 0) {
  1209. CGOptions::take_union_field_addr(true);
  1210. continue;
  1211. }
  1212. if (strcmp (argv[i], "--vol-struct-union-fields") == 0) {
  1213. CGOptions::vol_struct_union_fields(true);
  1214. continue;
  1215. }
  1216. if (strcmp (argv[i], "--no-vol-struct-union-fields") == 0) {
  1217. CGOptions::vol_struct_union_fields(false);
  1218. continue;
  1219. }
  1220. if (strcmp(argv[i], "--const-struct-union-fields") == 0) {
  1221. CGOptions::const_struct_union_fields(true);
  1222. continue;
  1223. }
  1224. if (strcmp(argv[i], "--no-const-struct-union-fields") == 0) {
  1225. CGOptions::const_struct_union_fields(false);
  1226. continue;
  1227. }
  1228. if (strcmp (argv[i], "--no-hash-value-printf") == 0) {
  1229. CGOptions::hash_value_printf(false);
  1230. continue;
  1231. }
  1232. if (strcmp (argv[i], "--no-signed-char-index") == 0) {
  1233. CGOptions::signed_char_index(false);
  1234. continue;
  1235. }
  1236. if (strcmp (argv[i], "--lang-cpp") == 0) {
  1237. CGOptions::lang_cpp(true);
  1238. continue;
  1239. }
  1240. if (strcmp(argv[i], "--cpp11") == 0) {
  1241. CGOptions::cpp11(true);
  1242. continue;
  1243. }
  1244. if (strcmp (argv[i], "--int-size") == 0) {
  1245. unsigned long size;
  1246. i++;
  1247. arg_check(argc, i);
  1248. if (!parse_int_arg(argv[i], &size))
  1249. exit(-1);
  1250. CGOptions::int_size(size);
  1251. continue;
  1252. }
  1253. if (strcmp (argv[i], "--ptr-size") == 0) {
  1254. unsigned long size;
  1255. i++;
  1256. arg_check(argc, i);
  1257. if (!parse_int_arg(argv[i], &size))
  1258. exit(-1);
  1259. CGOptions::pointer_size(size);
  1260. continue;
  1261. }
  1262. if (strcmp(argv[i], "--fast-execution") == 0) {
  1263. CGOptions::lang_cpp(true);
  1264. // jumps can easily cause infinite loops. Just disable them
  1265. CGOptions::jumps(false);
  1266. // large arrays are also reported to cause slow execution
  1267. CGOptions::max_array_length_per_dimension(5);
  1268. continue;
  1269. }
  1270. // OMIT help
  1271. // OMIT compute-hash
  1272. // OMIT depth-protect
  1273. // OMIT wrap-volatiles
  1274. // OMIT allow-const-volatile
  1275. // OMIT allow-int64
  1276. // OMIT avoid-signed-overflow
  1277. // FIXME-- we should parse all options and then this should be
  1278. // an error
  1279. cout << "invalid option " << argv[i] << " at: "
  1280. << i
  1281. << endl;
  1282. exit(-1);
  1283. }
  1284. if (CGOptions::lang_cpp()) {
  1285. CGOptions::fix_options_for_cpp();
  1286. }
  1287. if (CGOptions::has_conflict()) {
  1288. cout << "error: options conflict - " << CGOptions::conflict_msg() << std::endl;
  1289. exit(-1);
  1290. }
  1291. AbsProgramGenerator *generator = AbsProgramGenerator::CreateInstance(argc, argv, g_Seed);
  1292. if (!generator) {
  1293. cout << "error: can't create generator!" << std::endl;
  1294. exit(-1);
  1295. }
  1296. generator->goGenerator();
  1297. delete generator;
  1298. // file.close();
  1299. return 0;
  1300. }
  1301. ///////////////////////////////////////////////////////////////////////////////
  1302. // Local Variables:
  1303. // c-basic-offset: 4
  1304. // tab-width: 4
  1305. // End:
  1306. // End of file.