Skip to content

Commit 93c28b3

Browse files
author
kroening
committed
Parse C11 _Noreturn
git-svn-id: svn+ssh://svn.cprover.org/srv/svn/cbmc/trunk@6389 6afb6bc1-c8e4-404c-8f48-9ae832c5b171
1 parent dc7afc7 commit 93c28b3

File tree

8 files changed

+42
-5
lines changed

8 files changed

+42
-5
lines changed

regression/ansi-c/_Noreturn1/main.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern _Noreturn void foo();
2+
3+
int main()
4+
{
5+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

src/ansi-c/ansi_c_convert_type.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ void ansi_c_convert_typet::read_rec(const typet &type)
225225
}
226226
}
227227
}
228+
else if(type.id()==ID_noreturn)
229+
c_qualifiers.is_noreturn=true;
228230
else
229231
other.push_back(type);
230232
}

src/ansi-c/c_qualifiers.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ std::string c_qualifierst::as_string() const
4343

4444
if(is_ptr64)
4545
qualifiers+="__ptr64 ";
46+
47+
if(is_noreturn)
48+
qualifiers+="_Noreturn ";
4649

4750
return qualifiers;
4851
}
@@ -81,6 +84,9 @@ void c_qualifierst::read(const typet &src)
8184

8285
if(src.get_bool(ID_C_transparent_union))
8386
is_transparent_union=true;
87+
88+
if(src.get_bool(ID_C_noreturn))
89+
is_noreturn=true;
8490
}
8591

8692
/*******************************************************************\
@@ -131,6 +137,11 @@ void c_qualifierst::write(typet &dest) const
131137
dest.set(ID_C_transparent_union, true);
132138
else
133139
dest.remove(ID_C_transparent_union);
140+
141+
if(is_noreturn)
142+
dest.set(ID_C_noreturn, true);
143+
else
144+
dest.remove(ID_C_noreturn);
134145
}
135146

136147
/*******************************************************************\
@@ -153,6 +164,7 @@ void c_qualifierst::clear(typet &dest)
153164
dest.remove(ID_C_ptr32);
154165
dest.remove(ID_C_ptr64);
155166
dest.remove(ID_C_transparent_union);
167+
dest.remove(ID_C_noreturn);
156168
}
157169

158170
/*******************************************************************\

src/ansi-c/c_qualifiers.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ class c_qualifierst
3535
is_atomic=false;
3636
is_ptr32=is_ptr64=false;
3737
is_transparent_union=false;
38+
is_noreturn=false;
3839
}
3940

4041
// standard ones
41-
bool is_constant, is_volatile, is_restricted, is_atomic;
42+
bool is_constant, is_volatile, is_restricted, is_atomic, is_noreturn;
4243

4344
// MS Visual Studio extension
4445
bool is_ptr32, is_ptr64;
@@ -61,7 +62,8 @@ class c_qualifierst
6162
(!is_restricted || q.is_restricted) &&
6263
(!is_atomic || q.is_atomic) &&
6364
(!is_ptr32 || q.is_ptr32) &&
64-
(!is_ptr64 || q.is_ptr64);
65+
(!is_ptr64 || q.is_ptr64) &&
66+
(!is_noreturn || q.is_noreturn);
6567

6668
// is_transparent_union isn't checked
6769
}
@@ -76,7 +78,8 @@ class c_qualifierst
7678
a.is_atomic==b.is_atomic &&
7779
a.is_ptr32==b.is_ptr32 &&
7880
a.is_ptr64==b.is_ptr64 &&
79-
a.is_transparent_union==b.is_transparent_union;
81+
a.is_transparent_union==b.is_transparent_union &&
82+
a.is_noreturn==b.is_noreturn;
8083
}
8184

8285
friend bool operator != (
@@ -96,13 +99,14 @@ class c_qualifierst
9699
is_ptr32|=b.is_ptr32;
97100
is_ptr64|=b.is_ptr64;
98101
is_transparent_union|=b.is_transparent_union;
102+
is_noreturn|=b.is_noreturn;
99103
return *this;
100104
}
101105

102106
friend unsigned count(const c_qualifierst &q)
103107
{
104108
return q.is_constant+q.is_volatile+q.is_restricted+q.is_atomic+
105-
q.is_ptr32+q.is_ptr64;
109+
q.is_ptr32+q.is_ptr64+q.is_noreturn;
106110
}
107111
};
108112

src/ansi-c/parser.y

+2
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,8 @@ gcc_type_attribute:
15181518
{ $$=$1; set($$, ID_gcc_attribute_mode); stack($$).set(ID_size, stack($3).get(ID_identifier)); }
15191519
| TOK_GCC_ATTRIBUTE_GNU_INLINE TOK_GCC_ATTRIBUTE_END
15201520
{ $$=$1; set($$, ID_static); } /* GCC extern inline - cleanup in ansi_c_declarationt::to_symbol */
1521+
| TOK_NORETURN
1522+
{ $$=$1; set($$, ID_noreturn); }
15211523
| gcc_attribute_specifier
15221524
;
15231525

src/ansi-c/type2name.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ static std::string type2name(
124124
if(type.get_bool(ID_C_transparent_union))
125125
result+='t';
126126

127+
if(type.get_bool(ID_C_noreturn))
128+
result+='n';
129+
127130
// this isn't really a qualifier, but the linker needs to
128131
// distinguish these - should likely be fixed in the linker instead
129132
if(!type.source_location().get_function().empty())

src/util/irep_ids.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ C_qualifier #qualifier
393393
C_ptr32 #ptr32
394394
C_ptr64 #ptr64
395395
C_atomic #atomic
396-
C_noreturn #noreturn
397396
restrict
398397
byte_extract_big_endian
399398
byte_extract_little_endian
@@ -711,3 +710,5 @@ force
711710
release
712711
popcount
713712
function_type
713+
noreturn
714+
C_noreturn #noreturn

0 commit comments

Comments
 (0)