Skip to content

Commit ca4bb24

Browse files
author
Daniel Kroening
committed
fix return values of __builtin_classify_type
1 parent 77d5e68 commit ca4bb24

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

regression/ansi-c/gcc_builtins4/main.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@ union { int i; } u;
77
enum { Econst } e;
88
int a[10];
99

10-
STATIC_ASSERT(__builtin_classify_type(*(void *)0)==0);
1110
STATIC_ASSERT(__builtin_classify_type((int)0)==1);
12-
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
1315
STATIC_ASSERT(__builtin_classify_type((_Bool)0)==4);
16+
#endif
1417
STATIC_ASSERT(__builtin_classify_type((int *)0)==5);
1518
STATIC_ASSERT(__builtin_classify_type(1.0)==8);
1619
STATIC_ASSERT(__builtin_classify_type(*(0?(void *)0:(double *)0))==8);
1720
STATIC_ASSERT(__builtin_classify_type(*(0?(double *)0:(void *)0))==8);
1821
STATIC_ASSERT(__builtin_classify_type((_Complex double)0)==9);
1922
STATIC_ASSERT(__builtin_classify_type(s)==12);
2023
STATIC_ASSERT(__builtin_classify_type(u)==13);
21-
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);
29+
#endif
2230

2331
#endif
2432

regression/ansi-c/gcc_builtins4/test.desc

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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)