Skip to content

Commit ae9c63e

Browse files
author
Daniel Kroening
committed
fix __builtin_classify_type
1 parent 5fbe624 commit ae9c63e

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

regression/goto-gcc/gcc_builtins4/main.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@ union { int i; } u;
77
enum { Econst } e;
88
int a[10];
99

10-
#ifndef __clang__
11-
STATIC_ASSERT(__builtin_classify_type(*(void *)0)==0);
1210
STATIC_ASSERT(__builtin_classify_type((int)0)==1);
13-
STATIC_ASSERT(__builtin_classify_type(e)==3);
11+
STATIC_ASSERT(__builtin_classify_type(e)==1);
12+
#ifndef __clang__
13+
STATIC_ASSERT(__builtin_classify_type((_Bool)0)==1);
14+
#else
1415
STATIC_ASSERT(__builtin_classify_type((_Bool)0)==4);
16+
#endif
1517
STATIC_ASSERT(__builtin_classify_type((int *)0)==5);
1618
STATIC_ASSERT(__builtin_classify_type(1.0)==8);
1719
STATIC_ASSERT(__builtin_classify_type(*(0?(void *)0:(double *)0))==8);
1820
STATIC_ASSERT(__builtin_classify_type(*(0?(double *)0:(void *)0))==8);
1921
STATIC_ASSERT(__builtin_classify_type((_Complex double)0)==9);
2022
STATIC_ASSERT(__builtin_classify_type(s)==12);
2123
STATIC_ASSERT(__builtin_classify_type(u)==13);
22-
STATIC_ASSERT(__builtin_classify_type(a)==14);
24+
STATIC_ASSERT(__builtin_classify_type(a)==5);
25+
#ifndef __clang__
26+
STATIC_ASSERT(__builtin_classify_type((char)0)==15);
27+
#else
28+
STATIC_ASSERT(__builtin_classify_type((char)0)==1);
2329
#endif
2430

2531
#endif

regression/goto-gcc/gcc_builtins4/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
KNOWNBUG
22
main.c
33

44
^EXIT=0$

src/ansi-c/c_typecheck_expr.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@ exprt c_typecheck_baset::do_special_functions(
25812581
}
25822582
else if(identifier=="__builtin_classify_type")
25832583
{
2584-
// This is a gcc extension that produces an integer
2584+
// This is a gcc/clang extension that produces an integer
25852585
// constant for the type of the argument expression.
25862586
if(expr.arguments().size()!=1)
25872587
{
@@ -2598,18 +2598,18 @@ exprt c_typecheck_baset::do_special_functions(
25982598

25992599
unsigned type_number=
26002600
type.id()==ID_empty?0:
2601-
type.id()==ID_c_enum_tag?3:
2601+
type.id()==ID_c_enum_tag?1:
26022602
(type.id()==ID_bool || type.id()==ID_c_bool)?4:
26032603
type.id()==ID_pointer?5:
26042604
type.id()==ID_floatbv?8:
26052605
(type.id()==ID_complex && type.subtype().id()==ID_floatbv)?9:
26062606
type.id()==ID_struct?12:
26072607
type.id()==ID_union?13:
2608-
type.id()==ID_array?14:
2608+
type.id()==ID_array?5:
26092609
1; // int, short
26102610

2611-
// clang returns 15 for the three 'char' types,
2612-
// gcc treats these as 'int'
2611+
// clang returns 15 for the three 'char' types, gcc treats these as 'int'.
2612+
// clang returns 4 for _Bool, gcc treats these as 'int'.
26132613

26142614
exprt tmp=from_integer(type_number, expr.type());
26152615
tmp.add_source_location()=source_location;

0 commit comments

Comments
 (0)