Skip to content

Commit ba76a8f

Browse files
author
Daniel Kroening
authored
Merge pull request #1751 from tautschnig/fix-1748
C front-end: fix promotion order for types ranking lower than int
2 parents d0889a8 + cab7b52 commit ba76a8f

File tree

7 files changed

+39
-12
lines changed

7 files changed

+39
-12
lines changed

regression/cbmc/Pointer_byte_extract5/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <stdlib.h>
1+
void *malloc(__CPROVER_size_t);
22

33
typedef union
44
{

regression/cbmc/Pointer_byte_extract8/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <stdlib.h>
1+
void *malloc(__CPROVER_size_t);
22

33
typedef union
44
{

regression/cbmc/Promotion4/main.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
int main(int argc, char *argv[])
2+
{
3+
__CPROVER_assert(sizeof(unsigned int) == 2, "[--16] size of int is 16 bit");
4+
__CPROVER_assert(
5+
sizeof(unsigned long) == 4, "[--LP32] size of long is 32 bit");
6+
7+
unsigned int k = non_det_unsigned();
8+
__CPROVER_assume(k < 1);
9+
__CPROVER_assert(k != 0xffff, "false counter example 16Bit?");
10+
11+
return 0;
12+
}

regression/cbmc/Promotion4/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--16
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

regression/cbmc/address_space_size_limit2/test.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#include <stdlib.h>
21
#include <assert.h>
32

3+
void *malloc(__CPROVER_size_t);
4+
45
int main(int argc, char** argv)
56
{
67
char* c=(char*)malloc(10);

src/ansi-c/c_preprocess.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,20 @@ bool c_preprocess_visual_studio(
437437
// yes, both _WIN32 and _WIN64 get defined
438438
command_file << "/D_WIN64" << "\n";
439439
}
440+
else if(config.ansi_c.int_width == 16 && config.ansi_c.pointer_width == 32)
441+
{
442+
// 16-bit LP32 is an artificial architecture we simulate when using --16
443+
DATA_INVARIANT(
444+
pointer_diff_type() == signed_long_int_type(),
445+
"Pointer difference expected to be long int typed");
446+
command_file << "/D__PTRDIFF_TYPE__=long" << '\n';
447+
}
440448
else
441449
{
442450
DATA_INVARIANT(
443451
pointer_diff_type()==signed_int_type(),
444452
"Pointer difference expected to be int typed");
445453
command_file << "/D__PTRDIFF_TYPE__=int" << "\n";
446-
command_file << "/U_WIN64" << "\n";
447454
}
448455

449456
if(config.ansi_c.char_is_unsigned)

src/ansi-c/c_typecast.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -418,16 +418,15 @@ c_typecastt::c_typet c_typecastt::minimum_promotion(
418418
c_typet max_type=std::max(c_type, INT); // minimum promotion
419419

420420
// The second case can arise if we promote any unsigned type
421-
// that is as large as unsigned int.
422-
423-
if(config.ansi_c.short_int_width==config.ansi_c.int_width &&
424-
max_type==USHORT)
421+
// that is as large as unsigned int. In this case the promotion configuration
422+
// via the enum is actually wrong, and we need to fix this up.
423+
if(
424+
config.ansi_c.short_int_width == config.ansi_c.int_width &&
425+
c_type == USHORT)
425426
max_type=UINT;
426-
else if(config.ansi_c.char_width==config.ansi_c.int_width &&
427-
max_type==UCHAR)
427+
else if(
428+
config.ansi_c.char_width == config.ansi_c.int_width && c_type == UCHAR)
428429
max_type=UINT;
429-
else
430-
max_type=std::max(max_type, INT);
431430

432431
if(max_type==UINT &&
433432
type.id()==ID_c_bit_field &&

0 commit comments

Comments
 (0)