Skip to content

Commit 7f8efa0

Browse files
authored
Merge pull request #971 from diffblue/c-types-typing
Make the c_types have stronger C++ types
2 parents 3dbda92 + 2e11fef commit 7f8efa0

File tree

4 files changed

+216
-167
lines changed

4 files changed

+216
-167
lines changed

src/ansi-c/ansi_c_convert_type.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,25 @@ void ansi_c_convert_typet::write(typet &type)
464464
}
465465

466466
if(int8_cnt)
467-
type=is_signed?signed_char_type():unsigned_char_type();
467+
if(is_signed)
468+
type=signed_char_type();
469+
else
470+
type=unsigned_char_type();
468471
else if(int16_cnt)
469-
type=is_signed?signed_short_int_type():unsigned_short_int_type();
472+
if(is_signed)
473+
type=signed_short_int_type();
474+
else
475+
type=unsigned_short_int_type();
470476
else if(int32_cnt)
471-
type=is_signed?signed_int_type():unsigned_int_type();
477+
if(is_signed)
478+
type=signed_int_type();
479+
else
480+
type=unsigned_int_type();
472481
else if(int64_cnt) // Visual Studio: equivalent to long long int
473-
type=
474-
is_signed?signed_long_long_int_type():unsigned_long_long_int_type();
482+
if(is_signed)
483+
type=signed_long_long_int_type();
484+
else
485+
type=unsigned_long_long_int_type();
475486
else
476487
assert(false);
477488
}
@@ -509,19 +520,31 @@ void ansi_c_convert_typet::write(typet &type)
509520
throw 0;
510521
}
511522

512-
type=is_signed?signed_short_int_type():unsigned_short_int_type();
523+
if(is_signed)
524+
type=signed_short_int_type();
525+
else
526+
type=unsigned_short_int_type();
513527
}
514528
else if(long_cnt==0)
515529
{
516-
type=is_signed?signed_int_type():unsigned_int_type();
530+
if(is_signed)
531+
type=signed_int_type();
532+
else
533+
type=unsigned_int_type();
517534
}
518535
else if(long_cnt==1)
519536
{
520-
type=is_signed?signed_long_int_type():unsigned_long_int_type();
537+
if(is_signed)
538+
type=signed_long_int_type();
539+
else
540+
type=unsigned_long_int_type();
521541
}
522542
else if(long_cnt==2)
523543
{
524-
type=is_signed?signed_long_long_int_type():unsigned_long_long_int_type();
544+
if(is_signed)
545+
type=signed_long_long_int_type();
546+
else
547+
type=unsigned_long_long_int_type();
525548
}
526549
else
527550
{

src/ansi-c/c_typecheck_type.cpp

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,39 +134,74 @@ void c_typecheck_baset::typecheck_type(typet &type)
134134
typet result;
135135

136136
if(mode=="__QI__") // 8 bits
137-
result=is_signed?signed_char_type():unsigned_char_type();
137+
if(is_signed)
138+
result=signed_char_type();
139+
else
140+
result=unsigned_char_type();
138141
else if(mode=="__byte__") // 8 bits
139-
result=is_signed?signed_char_type():unsigned_char_type();
142+
if(is_signed)
143+
result=signed_char_type();
144+
else
145+
result=unsigned_char_type();
140146
else if(mode=="__HI__") // 16 bits
141-
result=is_signed?signed_short_int_type():unsigned_short_int_type();
147+
if(is_signed)
148+
result=signed_short_int_type();
149+
else
150+
result=unsigned_short_int_type();
142151
else if(mode=="__SI__") // 32 bits
143-
result=is_signed?signed_int_type():unsigned_int_type();
152+
if(is_signed)
153+
result=signed_int_type();
154+
else
155+
result=unsigned_int_type();
144156
else if(mode=="__word__") // long int, we think
145-
result=is_signed?signed_long_int_type():unsigned_long_int_type();
157+
if(is_signed)
158+
result=signed_long_int_type();
159+
else
160+
result=unsigned_long_int_type();
146161
else if(mode=="__pointer__") // we think this is size_t/ssize_t
147-
result=is_signed?signed_size_type():size_type();
162+
if(is_signed)
163+
result=signed_size_type();
164+
else
165+
result=size_type();
148166
else if(mode=="__DI__") // 64 bits
149167
{
150168
if(config.ansi_c.long_int_width==64)
151-
result=is_signed?signed_long_int_type():unsigned_long_int_type();
169+
if(is_signed)
170+
result=signed_long_int_type();
171+
else
172+
result=unsigned_long_int_type();
152173
else
153174
{
154175
assert(config.ansi_c.long_long_int_width==64);
155-
result=
156-
is_signed?signed_long_long_int_type():unsigned_long_long_int_type();
176+
177+
if(is_signed)
178+
result=signed_long_long_int_type();
179+
else
180+
result=unsigned_long_long_int_type();
157181
}
158182
}
159183
else if(mode=="__TI__") // 128 bits
160-
result=is_signed?gcc_signed_int128_type():gcc_unsigned_int128_type();
184+
if(is_signed)
185+
result=gcc_signed_int128_type();
186+
else
187+
result=gcc_unsigned_int128_type();
161188
else if(mode=="__V2SI__") // vector of 2 ints, deprecated by gcc
162-
result=
163-
vector_typet(
164-
is_signed?signed_int_type():unsigned_int_type(),
189+
if(is_signed)
190+
result=vector_typet(
191+
signed_int_type(),
192+
from_integer(2, size_type()));
193+
else
194+
result=vector_typet(
195+
unsigned_int_type(),
165196
from_integer(2, size_type()));
166197
else if(mode=="__V4SI__") // vector of 4 ints, deprecated by gcc
167-
result=
168-
vector_typet(
169-
is_signed?signed_int_type():unsigned_int_type(),
198+
if(is_signed)
199+
result=vector_typet(
200+
signed_int_type(),
201+
from_integer(4, size_type()));
202+
else
203+
result=vector_typet(
204+
unsigned_int_type(),
170205
from_integer(4, size_type()));
171206
else // give up, just use subtype
172207
result=type.subtype();

0 commit comments

Comments
 (0)