File tree 6 files changed +46
-6
lines changed
6 files changed +46
-6
lines changed Original file line number Diff line number Diff line change
1
+ int main (int argc, char *argv[])
2
+ {
3
+ __CPROVER_assert (
4
+ sizeof (char *) > sizeof (int ) || argc < 0x7FFFFFFF ,
5
+ " argc cannot reach INT_MAX on 32-bit systems" );
6
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.i
3
+ --32
4
+ ^VERIFICATION SUCCESSFUL$
5
+ ^EXIT=0$
6
+ ^SIGNAL=0$
7
+ --
8
+ ^warning: ignoring
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ activate-multi-line-match
5
5
^EXIT=10$
6
6
^SIGNAL=0$
7
7
VERIFICATION FAILED
8
- Trace for main\.assertion\.1:(\n.*){22} assertion 4 \!= argc(\n.*){5}Trace for main\.assertion\.3:(\n.*){36} assertion argc != 4(\n.*){5}Trace for main\.assertion\.4:(\n.*){50} assertion argc \+ 1 != 5
8
+ Trace for main\.assertion\.1:(( \n.*){19}|(\n.*){ 22}) assertion 4 \!= argc(\n.*){5}Trace for main\.assertion\.3:(( \n.*){33}|(\n.*){ 36}) assertion argc != 4(\n.*){5}Trace for main\.assertion\.4:(( \n.*){47}|(\n.*){ 50}) assertion argc \+ 1 != 5
9
9
\*\* 3 of 4 failed
10
10
--
11
11
^warning: ignoring
Original file line number Diff line number Diff line change @@ -313,12 +313,10 @@ bool generate_ansi_c_start_function(
313
313
init_code.add (code_assumet (std::move (ge)));
314
314
}
315
315
316
+ if (config.ansi_c .max_argc .has_value ())
316
317
{
317
- // assume argc is at most MAX/8-1
318
- mp_integer upper_bound=
319
- power (2 , config.ansi_c .int_width -4 );
320
-
321
- exprt bound_expr=from_integer (upper_bound, argc_symbol.type );
318
+ exprt bound_expr =
319
+ from_integer (*config.ansi_c .max_argc , argc_symbol.type );
322
320
323
321
binary_relation_exprt le (
324
322
argc_symbol.symbol_expr (), ID_le, std::move (bound_expr));
Original file line number Diff line number Diff line change @@ -1146,6 +1146,29 @@ bool configt::set(const cmdlinet &cmdline)
1146
1146
if (cmdline.isset (" cpp11" ))
1147
1147
cpp.set_cpp11 ();
1148
1148
1149
+ // set the upper bound for argc
1150
+ if (os == " windows" )
1151
+ {
1152
+ // On Windows, CreateProcess accepts no more than 32767 characters, so make
1153
+ // that a hard limit.
1154
+ ansi_c.max_argc = mp_integer{32767 };
1155
+ }
1156
+ else
1157
+ {
1158
+ // For other systems assume argc is no larger than the what would make argv
1159
+ // consume all available memory space:
1160
+ // 2^pointer_width / (pointer_width / char_width) is the maximum number of
1161
+ // argv elements sysconf(ARG_MAX) is likely much lower than this, but we
1162
+ // don't know that value for the verification target platform.
1163
+ const auto pointer_bits_2log =
1164
+ address_bits (ansi_c.pointer_width / ansi_c.char_width );
1165
+ if (ansi_c.pointer_width - pointer_bits_2log <= ansi_c.int_width )
1166
+ {
1167
+ ansi_c.max_argc = power (2 , config.ansi_c .int_width - pointer_bits_2log);
1168
+ }
1169
+ // otherwise we leave argc unconstrained
1170
+ }
1171
+
1149
1172
return false ;
1150
1173
}
1151
1174
Original file line number Diff line number Diff line change @@ -258,6 +258,11 @@ class configt
258
258
malloc_failure_modet malloc_failure_mode = malloc_failure_mode_none;
259
259
260
260
static const std::size_t default_object_bits = 8 ;
261
+
262
+ // / Maximum value of argc, which is operating-systems dependent: Windows
263
+ // / limits the number of characters accepte by CreateProcess, and Unix
264
+ // / systems have sysconf(ARG_MAX).
265
+ optionalt<mp_integer> max_argc;
261
266
} ansi_c;
262
267
263
268
struct cppt
You can’t perform that action at this time.
0 commit comments