-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new gcc floating-point type identifiers, Fixes: #2151
Documentation on the new types: https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html The commit also moves other gcc-specific types to ansi-c/gcc_types.h
- Loading branch information
Daniel Kroening
committed
May 3, 2018
1 parent
41d7a45
commit 52e9737
Showing
18 changed files
with
467 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ Author: Daniel Kroening, [email protected] | |
#include <util/arith_tools.h> | ||
#include <util/std_types.h> | ||
|
||
#include "gcc_types.h" | ||
|
||
void ansi_c_convert_typet::read(const typet &type) | ||
{ | ||
clear(); | ||
|
@@ -80,8 +82,20 @@ void ansi_c_convert_typet::read_rec(const typet &type) | |
int32_cnt++; | ||
else if(type.id()==ID_int64) | ||
int64_cnt++; | ||
else if(type.id()==ID_gcc_float16) | ||
gcc_float16_cnt++; | ||
else if(type.id()==ID_gcc_float32) | ||
gcc_float32_cnt++; | ||
else if(type.id()==ID_gcc_float32x) | ||
gcc_float32x_cnt++; | ||
else if(type.id()==ID_gcc_float64) | ||
gcc_float64_cnt++; | ||
else if(type.id()==ID_gcc_float64x) | ||
gcc_float64x_cnt++; | ||
else if(type.id()==ID_gcc_float128) | ||
gcc_float128_cnt++; | ||
else if(type.id()==ID_gcc_float128x) | ||
gcc_float128x_cnt++; | ||
else if(type.id()==ID_gcc_int128) | ||
gcc_int128_cnt++; | ||
else if(type.id()==ID_gcc_attribute_mode) | ||
|
@@ -248,7 +262,11 @@ void ansi_c_convert_typet::write(typet &type) | |
unsigned_cnt || int_cnt || c_bool_cnt || proper_bool_cnt || | ||
short_cnt || char_cnt || complex_cnt || long_cnt || | ||
int8_cnt || int16_cnt || int32_cnt || int64_cnt || | ||
gcc_float128_cnt || gcc_int128_cnt || bv_cnt) | ||
gcc_float16_cnt || | ||
gcc_float32_cnt || gcc_float32x_cnt || | ||
gcc_float64_cnt || gcc_float64x_cnt || | ||
gcc_float128_cnt || gcc_float128x_cnt || | ||
gcc_int128_cnt || bv_cnt) | ||
{ | ||
error().source_location=source_location; | ||
error() << "illegal type modifier for defined type" << eom; | ||
|
@@ -305,27 +323,49 @@ void ansi_c_convert_typet::write(typet &type) | |
<< "found " << type.pretty() << eom; | ||
throw 0; | ||
} | ||
else if(gcc_float128_cnt) | ||
else if(gcc_float16_cnt || | ||
gcc_float32_cnt || gcc_float32x_cnt || | ||
gcc_float64_cnt || gcc_float64x_cnt || | ||
gcc_float128_cnt || gcc_float128x_cnt) | ||
{ | ||
if(signed_cnt || unsigned_cnt || int_cnt || c_bool_cnt || proper_bool_cnt || | ||
int8_cnt || int16_cnt || int32_cnt || int64_cnt || | ||
gcc_int128_cnt || bv_cnt || | ||
short_cnt || char_cnt) | ||
{ | ||
error().source_location=source_location; | ||
error() << "cannot combine integer type with float" << eom; | ||
error() << "cannot combine integer type with floating-point type" << eom; | ||
throw 0; | ||
} | ||
|
||
if(long_cnt || double_cnt || float_cnt) | ||
if(long_cnt+double_cnt+ | ||
float_cnt+gcc_float16_cnt+ | ||
gcc_float32_cnt+gcc_float32x_cnt+ | ||
gcc_float64_cnt+gcc_float64x_cnt+ | ||
gcc_float128_cnt+gcc_float128x_cnt>=2) | ||
{ | ||
error().source_location=source_location; | ||
error() << "conflicting type modifiers" << eom; | ||
throw 0; | ||
} | ||
|
||
// _not_ the same as long double | ||
type=gcc_float128_type(); | ||
// _not_ the same as float, double, long double | ||
if(gcc_float16_cnt) | ||
type=gcc_float16_type(); | ||
else if(gcc_float32_cnt) | ||
type=gcc_float32_type(); | ||
else if(gcc_float32x_cnt) | ||
type=gcc_float32x_type(); | ||
else if(gcc_float64_cnt) | ||
type=gcc_float64_type(); | ||
else if(gcc_float64x_cnt) | ||
type=gcc_float64x_type(); | ||
else if(gcc_float128_cnt) | ||
type=gcc_float128_type(); | ||
else if(gcc_float128x_cnt) | ||
type=gcc_float128x_type(); | ||
else | ||
UNREACHABLE; | ||
} | ||
else if(double_cnt || float_cnt) | ||
{ | ||
|
@@ -335,7 +375,7 @@ void ansi_c_convert_typet::write(typet &type) | |
short_cnt || char_cnt) | ||
{ | ||
error().source_location=source_location; | ||
error() << "cannot combine integer type with float" << eom; | ||
error() << "cannot combine integer type with floating-point type" << eom; | ||
throw 0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "ansi_c_convert_type.h" | ||
#include "c_qualifiers.h" | ||
#include "gcc_types.h" | ||
#include "padding.h" | ||
#include "type2name.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/*******************************************************************\ | ||
Module: | ||
Author: Daniel Kroening, [email protected] | ||
\*******************************************************************/ | ||
|
||
#include "gcc_types.h" | ||
|
||
#include <util/config.h> | ||
#include <util/c_types.h> | ||
|
||
bitvector_typet gcc_float16_type() | ||
{ | ||
if(config.ansi_c.use_fixed_for_float) | ||
{ | ||
fixedbv_typet result; | ||
result.set_width(16); | ||
result.set_integer_bits(16/2); | ||
result.set(ID_C_c_type, ID_gcc_float16); | ||
return result; | ||
} | ||
else | ||
{ | ||
floatbv_typet result= | ||
ieee_float_spect::half_precision().to_type(); | ||
result.set(ID_C_c_type, ID_gcc_float16); | ||
return result; | ||
} | ||
} | ||
|
||
bitvector_typet gcc_float32_type() | ||
{ | ||
// not same as float! | ||
|
||
if(config.ansi_c.use_fixed_for_float) | ||
{ | ||
fixedbv_typet result; | ||
result.set_width(config.ansi_c.single_width); | ||
result.set_integer_bits(config.ansi_c.single_width/2); | ||
result.set(ID_C_c_type, ID_gcc_float32); | ||
return result; | ||
} | ||
else | ||
{ | ||
floatbv_typet result= | ||
ieee_float_spect::single_precision().to_type(); | ||
result.set(ID_C_c_type, ID_gcc_float32); | ||
return result; | ||
} | ||
} | ||
|
||
bitvector_typet gcc_float32x_type() | ||
{ | ||
// not same as float! | ||
|
||
if(config.ansi_c.use_fixed_for_float) | ||
{ | ||
fixedbv_typet result; | ||
result.set_width(config.ansi_c.single_width); | ||
result.set_integer_bits(config.ansi_c.single_width/2); | ||
result.set(ID_C_c_type, ID_gcc_float32x); | ||
return result; | ||
} | ||
else | ||
{ | ||
floatbv_typet result= | ||
ieee_float_spect::single_precision().to_type(); | ||
result.set(ID_C_c_type, ID_gcc_float32x); | ||
return result; | ||
} | ||
} | ||
|
||
bitvector_typet gcc_float64_type() | ||
{ | ||
// not same as double! | ||
if(config.ansi_c.use_fixed_for_float) | ||
{ | ||
fixedbv_typet result; | ||
result.set_width(config.ansi_c.double_width); | ||
result.set_integer_bits(config.ansi_c.double_width/2); | ||
result.set(ID_C_c_type, ID_gcc_float64); | ||
return result; | ||
} | ||
else | ||
{ | ||
floatbv_typet result= | ||
ieee_float_spect::double_precision().to_type(); | ||
result.set(ID_C_c_type, ID_gcc_float64); | ||
return result; | ||
} | ||
} | ||
|
||
bitvector_typet gcc_float64x_type() | ||
{ | ||
// not same as double! | ||
if(config.ansi_c.use_fixed_for_float) | ||
{ | ||
fixedbv_typet result; | ||
result.set_width(config.ansi_c.double_width); | ||
result.set_integer_bits(config.ansi_c.double_width/2); | ||
result.set(ID_C_c_type, ID_gcc_float64x); | ||
return result; | ||
} | ||
else | ||
{ | ||
floatbv_typet result= | ||
ieee_float_spect::double_precision().to_type(); | ||
result.set(ID_C_c_type, ID_gcc_float64x); | ||
return result; | ||
} | ||
} | ||
|
||
bitvector_typet gcc_float128_type() | ||
{ | ||
// not same as long double! | ||
|
||
if(config.ansi_c.use_fixed_for_float) | ||
{ | ||
fixedbv_typet result; | ||
result.set_width(128); | ||
result.set_integer_bits(128/2); | ||
result.set(ID_C_c_type, ID_gcc_float128); | ||
return result; | ||
} | ||
else | ||
{ | ||
floatbv_typet result= | ||
ieee_float_spect::quadruple_precision().to_type(); | ||
result.set(ID_C_c_type, ID_gcc_float128); | ||
return result; | ||
} | ||
} | ||
|
||
bitvector_typet gcc_float128x_type() | ||
{ | ||
// not same as long double! | ||
|
||
if(config.ansi_c.use_fixed_for_float) | ||
{ | ||
fixedbv_typet result; | ||
result.set_width(128); | ||
result.set_integer_bits(128/2); | ||
result.set(ID_C_c_type, ID_gcc_float128x); | ||
return result; | ||
} | ||
else | ||
{ | ||
floatbv_typet result= | ||
ieee_float_spect::quadruple_precision().to_type(); | ||
result.set(ID_C_c_type, ID_gcc_float128x); | ||
return result; | ||
} | ||
} | ||
|
||
unsignedbv_typet gcc_unsigned_int128_type() | ||
{ | ||
unsignedbv_typet result(128); | ||
result.set(ID_C_c_type, ID_unsigned_int128); | ||
return result; | ||
} | ||
|
||
signedbv_typet gcc_signed_int128_type() | ||
{ | ||
signedbv_typet result(128); | ||
result.set(ID_C_c_type, ID_signed_int128); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*******************************************************************\ | ||
Module: | ||
Author: Daniel Kroening, [email protected] | ||
\*******************************************************************/ | ||
|
||
#ifndef CPROVER_ANSI_C_GCC_TYPES_H | ||
#define CPROVER_ANSI_C_GCC_TYPES_H | ||
|
||
#include <util/std_types.h> | ||
|
||
// These are gcc-specific; most are not implemented by clang | ||
// https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html | ||
|
||
bitvector_typet gcc_float16_type(); | ||
bitvector_typet gcc_float32_type(); | ||
bitvector_typet gcc_float32x_type(); | ||
bitvector_typet gcc_float64_type(); | ||
bitvector_typet gcc_float64x_type(); | ||
bitvector_typet gcc_float128_type(); | ||
bitvector_typet gcc_float128x_type(); | ||
unsignedbv_typet gcc_unsigned_int128_type(); | ||
signedbv_typet gcc_signed_int128_type(); | ||
|
||
#endif // CPROVER_ANSI_C_GCC_TYPES_H |
Oops, something went wrong.