Skip to content

Commit be6e3b6

Browse files
author
Daniel Kroening
committed
__float80 is a typedef, not a keyword
1 parent d7876ef commit be6e3b6

File tree

5 files changed

+55
-12
lines changed

5 files changed

+55
-12
lines changed

src/ansi-c/ansi_c_internal_additions.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,17 @@ void ansi_c_internal_additions(std::string &code)
213213
code+="typedef long double __float128;\n";
214214
}
215215

216-
// On 64-bit systems, both gcc and clang have typedefs
216+
if(
217+
config.ansi_c.arch == "i386" || config.ansi_c.arch == "x86_64" ||
218+
config.ansi_c.arch == "x32" || config.ansi_c.arch == "ia64")
219+
{
220+
// clang doesn't do __float80
221+
// Note that __float80 is a typedef, and not a keyword.
222+
if(config.ansi_c.mode != configt::ansi_ct::flavourt::CLANG)
223+
code += "typedef __CPROVER_Float64x __float80;\n";
224+
}
225+
226+
// On 64-bit systems, gcc has typedefs
217227
// __int128_t und __uint128_t -- but not on 32 bit!
218228
if(config.ansi_c.long_int_width>=64)
219229
{

src/ansi-c/scanner.l

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,12 @@ void ansi_c_scanner_init()
489489
return make_identifier();
490490
}
491491

492-
"__float80" { // clang doesn't have it
493-
if(PARSER.mode==configt::ansi_ct::flavourt::GCC)
494-
{ loc(); return TOK_GCC_FLOAT80; }
495-
else
496-
return make_identifier();
492+
"__CPROVER_Float64x" {
493+
loc(); return TOK_GCC_FLOAT64X;
494+
}
495+
496+
"__CPROVER_Float80" {
497+
loc(); return TOK_GCC_FLOAT80;
497498
}
498499

499500
"__float128" { // This is a keyword for CLANG,

src/cpp/cpp_convert_type.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class cpp_convert_typet
3232
double_cnt, float_cnt, complex_cnt, cpp_bool_cnt, proper_bool_cnt,
3333
extern_cnt, noreturn_cnt, wchar_t_cnt, char16_t_cnt, char32_t_cnt,
3434
int8_cnt, int16_cnt, int32_cnt, int64_cnt, ptr32_cnt, ptr64_cnt,
35-
float128_cnt, int128_cnt;
35+
float80_cnt, float128_cnt, int128_cnt;
3636

3737
void read(const typet &type);
3838
void write(typet &type);
@@ -55,7 +55,7 @@ void cpp_convert_typet::read(const typet &type)
5555
double_cnt=float_cnt=complex_cnt=cpp_bool_cnt=proper_bool_cnt=
5656
extern_cnt=noreturn_cnt=wchar_t_cnt=char16_t_cnt=char32_t_cnt=
5757
int8_cnt=int16_cnt=int32_cnt=int64_cnt=
58-
ptr32_cnt=ptr64_cnt=float128_cnt=int128_cnt=0;
58+
ptr32_cnt=ptr64_cnt=float80_cnt=float128_cnt=int128_cnt=0;
5959

6060
other.clear();
6161

@@ -96,6 +96,8 @@ void cpp_convert_typet::read_rec(const typet &type)
9696
double_cnt++;
9797
else if(type.id()==ID_float)
9898
float_cnt++;
99+
else if(type.id()==ID_gcc_float80)
100+
float80_cnt++;
99101
else if(type.id()==ID_gcc_float128)
100102
float128_cnt++;
101103
else if(type.id()==ID_gcc_int128)
@@ -329,7 +331,7 @@ void cpp_convert_typet::write(typet &type)
329331
short_cnt || char_cnt || wchar_t_cnt ||
330332
char16_t_cnt || char32_t_cnt ||
331333
int8_cnt || int16_cnt || int32_cnt ||
332-
int64_cnt || float128_cnt || int128_cnt)
334+
int64_cnt || float80_cnt || float128_cnt || int128_cnt)
333335
throw "type modifier not applicable";
334336

335337
if(other.size()!=1)
@@ -346,7 +348,7 @@ void cpp_convert_typet::write(typet &type)
346348
float_cnt ||
347349
int8_cnt || int16_cnt || int32_cnt ||
348350
int64_cnt || ptr32_cnt || ptr64_cnt ||
349-
float128_cnt || int128_cnt)
351+
float80_cnt || float128_cnt || int128_cnt)
350352
throw "illegal type modifier for double";
351353

352354
if(long_cnt)
@@ -361,14 +363,32 @@ void cpp_convert_typet::write(typet &type)
361363
short_cnt || char_cnt || wchar_t_cnt || double_cnt ||
362364
char16_t_cnt || char32_t_cnt ||
363365
int8_cnt || int16_cnt || int32_cnt ||
364-
int64_cnt || ptr32_cnt || ptr64_cnt || float128_cnt || int128_cnt)
366+
int64_cnt || ptr32_cnt || ptr64_cnt ||
367+
float80_cnt || float128_cnt || int128_cnt)
365368
throw "illegal type modifier for float";
366369

367370
if(long_cnt)
368371
throw "float can't be long";
369372

370373
type=float_type();
371374
}
375+
else if(float80_cnt)
376+
{
377+
if(signed_cnt || unsigned_cnt || int_cnt ||
378+
cpp_bool_cnt || proper_bool_cnt ||
379+
short_cnt || char_cnt || wchar_t_cnt || double_cnt ||
380+
char16_t_cnt || char32_t_cnt ||
381+
int8_cnt || int16_cnt || int32_cnt ||
382+
int64_cnt || int128_cnt || ptr32_cnt || ptr64_cnt ||
383+
float128_cnt)
384+
throw "illegal type modifier for __float80";
385+
386+
if(long_cnt)
387+
throw "__float80 can't be long";
388+
389+
// this isn't the same as long double
390+
type=gcc_float64x_type();
391+
}
372392
else if(float128_cnt)
373393
{
374394
if(signed_cnt || unsigned_cnt || int_cnt ||

src/cpp/cpp_internal_additions.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ void cpp_internal_additions(std::ostream &out)
145145
out << "typedef long double __float128;" << '\n';
146146
}
147147

148+
if(
149+
config.ansi_c.arch == "i386" || config.ansi_c.arch == "x86_64" ||
150+
config.ansi_c.arch == "x32" || config.ansi_c.arch == "ia64")
151+
{
152+
// clang doesn't do __float80
153+
// Note that __float80 is a typedef, and not a keyword,
154+
// and that C++ doesn't have _Float64x.
155+
if(config.ansi_c.mode != configt::ansi_ct::flavourt::CLANG)
156+
out << "typedef __CPROVER_Float80 __float80;" << '\n';
157+
}
158+
148159
// On 64-bit systems, gcc has typedefs
149160
// __int128_t und __uint128_t -- but not on 32 bit!
150161
if(config.ansi_c.long_int_width >= 64)

src/cpp/parse.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ bool Parser::isTypeSpecifier()
762762
|| t==TOK_INT8 || t==TOK_INT16 || t==TOK_INT32 || t==TOK_INT64
763763
|| t==TOK_GCC_INT128
764764
|| t==TOK_PTR32 || t==TOK_PTR64
765-
|| t==TOK_GCC_FLOAT128
765+
|| t==TOK_GCC_FLOAT80 || t==TOK_GCC_FLOAT128
766766
|| t==TOK_VOID || t==TOK_BOOL || t==TOK_CPROVER_BOOL
767767
|| t==TOK_CLASS || t==TOK_STRUCT || t==TOK_UNION || t==TOK_ENUM
768768
|| t==TOK_INTERFACE
@@ -2455,6 +2455,7 @@ bool Parser::optIntegralTypeOrClassSpec(typet &p)
24552455
case TOK_INT32: type_id=ID_int32; break;
24562456
case TOK_INT64: type_id=ID_int64; break;
24572457
case TOK_GCC_INT128: type_id=ID_gcc_int128; break;
2458+
case TOK_GCC_FLOAT80: type_id=ID_gcc_float80; break;
24582459
case TOK_GCC_FLOAT128: type_id=ID_gcc_float128; break;
24592460
case TOK_BOOL: type_id=ID_bool; break;
24602461
case TOK_CPROVER_BOOL: type_id=ID_proper_bool; break;

0 commit comments

Comments
 (0)