16
16
#include < util/arith_tools.h>
17
17
#include < util/base_type.h>
18
18
#include < util/c_types.h>
19
+ #include < util/config.h>
19
20
#include < util/cprover_prefix.h>
20
21
#include < util/ieee_float.h>
21
22
#include < util/pointer_offset_size.h>
@@ -2581,7 +2582,7 @@ exprt c_typecheck_baset::do_special_functions(
2581
2582
}
2582
2583
else if (identifier==" __builtin_classify_type" )
2583
2584
{
2584
- // This is a gcc extension that produces an integer
2585
+ // This is a gcc/clang extension that produces an integer
2585
2586
// constant for the type of the argument expression.
2586
2587
if (expr.arguments ().size ()!=1 )
2587
2588
{
@@ -2594,22 +2595,34 @@ exprt c_typecheck_baset::do_special_functions(
2594
2595
2595
2596
// The value doesn't matter at all, we only care about the type.
2596
2597
// Need to sync with typeclass.h.
2597
- const typet &type=follow (object.type ());
2598
-
2599
- unsigned type_number=
2600
- type.id ()==ID_empty?0 :
2601
- type.id ()==ID_c_enum_tag?3 :
2602
- (type.id ()==ID_bool || type.id ()==ID_c_bool)?4 :
2603
- type.id ()==ID_pointer?5 :
2604
- type.id ()==ID_floatbv?8 :
2605
- (type.id ()==ID_complex && type.subtype ().id ()==ID_floatbv)?9 :
2606
- type.id ()==ID_struct?12 :
2607
- type.id ()==ID_union?13 :
2608
- type.id ()==ID_array?14 :
2609
- 1 ; // int, short
2610
-
2611
- // clang returns 15 for the three 'char' types,
2612
- // gcc treats these as 'int'
2598
+ typet type = follow (object.type ());
2599
+
2600
+ // use underlying type for bit fields
2601
+ if (type.id () == ID_c_bit_field)
2602
+ type = to_c_bit_field_type (type).subtype ();
2603
+
2604
+ unsigned type_number;
2605
+
2606
+ if (type.id () == ID_bool || type.id () == ID_c_bool)
2607
+ {
2608
+ // clang returns 4 for _Bool, gcc treats these as 'int'.
2609
+ type_number =
2610
+ config.ansi_c .preprocessor == configt::ansi_ct::preprocessort::CLANG
2611
+ ? 4
2612
+ : 1 ;
2613
+ }
2614
+ else
2615
+ {
2616
+ type_number =
2617
+ type.id () == ID_empty ? 0
2618
+ : (type.id () == ID_bool || type.id () == ID_c_bool) ? 4
2619
+ : (type.id () == ID_pointer || type.id () == ID_array) ? 5
2620
+ : type.id () == ID_floatbv ? 8
2621
+ : (type.id () == ID_complex && type.subtype ().id () == ID_floatbv) ? 9
2622
+ : type.id () == ID_struct ? 12
2623
+ : type.id () == ID_union ? 13
2624
+ : 1 ; // int, short, char, enum_tag
2625
+ }
2613
2626
2614
2627
exprt tmp=from_integer (type_number, expr.type ());
2615
2628
tmp.add_source_location ()=source_location;
0 commit comments