Skip to content

Commit 5c7a529

Browse files
authored
Merge pull request #5302 from tautschnig/array-init-cleanup
C front-end: clarify string initialiser control flow
2 parents 473f6a9 + 03bec50 commit 5c7a529

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,26 @@ exprt c_typecheck_baset::do_initializer_list(
872872

873873
const typet &full_type=follow(type);
874874

875+
// 6.7.9, 14: An array of character type may be initialized by a character
876+
// string literal or UTF-8 string literal, optionally enclosed in braces.
877+
if(
878+
full_type.id() == ID_array && value.operands().size() >= 1 &&
879+
to_multi_ary_expr(value).op0().id() == ID_string_constant &&
880+
(full_type.subtype().id() == ID_signedbv ||
881+
full_type.subtype().id() == ID_unsignedbv) &&
882+
to_bitvector_type(full_type.subtype()).get_width() ==
883+
char_type().get_width())
884+
{
885+
if(value.operands().size() > 1)
886+
{
887+
warning().source_location = value.find_source_location();
888+
warning() << "ignoring excess initializers" << eom;
889+
}
890+
891+
return do_initializer_rec(
892+
to_multi_ary_expr(value).op0(), type, force_constant);
893+
}
894+
875895
exprt result;
876896
if(full_type.id()==ID_struct ||
877897
full_type.id()==ID_union ||
@@ -909,26 +929,6 @@ exprt c_typecheck_baset::do_initializer_list(
909929
}
910930
result = *zero;
911931
}
912-
913-
// 6.7.9, 14: An array of character type may be initialized by a character
914-
// string literal or UTF-8 string literal, optionally enclosed in braces.
915-
if(
916-
value.operands().size() >= 1 &&
917-
to_multi_ary_expr(value).op0().id() == ID_string_constant &&
918-
(full_type.subtype().id() == ID_signedbv ||
919-
full_type.subtype().id() == ID_unsignedbv) &&
920-
to_bitvector_type(full_type.subtype()).get_width() ==
921-
char_type().get_width())
922-
{
923-
if(value.operands().size()>1)
924-
{
925-
warning().source_location=value.find_source_location();
926-
warning() << "ignoring excess initializers" << eom;
927-
}
928-
929-
return do_initializer_rec(
930-
to_multi_ary_expr(value).op0(), type, force_constant);
931-
}
932932
}
933933
else
934934
{

0 commit comments

Comments
 (0)