Skip to content

C front-end: fix promotion order for types ranking lower than int #1751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion regression/cbmc/Pointer_byte_extract5/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stdlib.h>
void *malloc(__CPROVER_size_t);

typedef union
{
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc/Pointer_byte_extract8/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stdlib.h>
void *malloc(__CPROVER_size_t);

typedef union
{
Expand Down
12 changes: 12 additions & 0 deletions regression/cbmc/Promotion4/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
int main(int argc, char *argv[])
{
__CPROVER_assert(sizeof(unsigned int) == 2, "[--16] size of int is 16 bit");
__CPROVER_assert(
sizeof(unsigned long) == 4, "[--LP32] size of long is 32 bit");

unsigned int k = non_det_unsigned();
__CPROVER_assume(k < 1);
__CPROVER_assert(k != 0xffff, "false counter example 16Bit?");

return 0;
}
8 changes: 8 additions & 0 deletions regression/cbmc/Promotion4/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--16
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
3 changes: 2 additions & 1 deletion regression/cbmc/address_space_size_limit2/test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <assert.h>

void *malloc(__CPROVER_size_t);

int main(int argc, char** argv)
{
char* c=(char*)malloc(10);
Expand Down
9 changes: 8 additions & 1 deletion src/ansi-c/c_preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,20 @@ bool c_preprocess_visual_studio(
// yes, both _WIN32 and _WIN64 get defined
command_file << "/D_WIN64" << "\n";
}
else if(config.ansi_c.int_width == 16 && config.ansi_c.pointer_width == 32)
{
// 16-bit LP32 is an artificial architecture we simulate when using --16
DATA_INVARIANT(
pointer_diff_type() == signed_long_int_type(),
"Pointer difference expected to be long int typed");
command_file << "/D__PTRDIFF_TYPE__=long" << '\n';
}
else
{
DATA_INVARIANT(
pointer_diff_type()==signed_int_type(),
"Pointer difference expected to be int typed");
command_file << "/D__PTRDIFF_TYPE__=int" << "\n";
command_file << "/U_WIN64" << "\n";
}

if(config.ansi_c.char_is_unsigned)
Expand Down
15 changes: 7 additions & 8 deletions src/ansi-c/c_typecast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,15 @@ c_typecastt::c_typet c_typecastt::minimum_promotion(
c_typet max_type=std::max(c_type, INT); // minimum promotion

// The second case can arise if we promote any unsigned type
// that is as large as unsigned int.

if(config.ansi_c.short_int_width==config.ansi_c.int_width &&
max_type==USHORT)
// that is as large as unsigned int. In this case the promotion configuration
// via the enum is actually wrong, and we need to fix this up.
if(
config.ansi_c.short_int_width == config.ansi_c.int_width &&
c_type == USHORT)
max_type=UINT;
else if(config.ansi_c.char_width==config.ansi_c.int_width &&
max_type==UCHAR)
else if(
config.ansi_c.char_width == config.ansi_c.int_width && c_type == UCHAR)
max_type=UINT;
else
max_type=std::max(max_type, INT);

if(max_type==UINT &&
type.id()==ID_c_bit_field &&
Expand Down