summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2014-05-08 07:52:46 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2014-05-08 07:52:46 +0000
commit329b44b4864eeefb5f935282c3fe6c025bc1c8bc (patch)
tree7d155623b113cd85c309cb9dde6f4d72feed650c
parentb4200796aab1ec26288a1376c7dd99c0927b5ee9 (diff)
Fixed regression on initializers of the form T x[N] = "literal";
where T is a typedef for a character type. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2488 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
-rw-r--r--Changelog9
-rw-r--r--cparser/Elab.ml18
-rw-r--r--test/regression/Results/initializers1
-rw-r--r--test/regression/initializers.c7
4 files changed, 27 insertions, 8 deletions
diff --git a/Changelog b/Changelog
index 833b9df..3d8bf53 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,12 @@
+Usability:
+- Re-added alternate keywords __restrict, __inline__, etc,
+ for GCC compatibility.
+- Do not assume that the preprocessor removed all comments.
+
+Bug fixing:
+- Fixed regression on initializers of the form T x[N] = "literal";
+ where T is a typedef for a character type.
+
Release 2.3, 2014-05-05
=======================
diff --git a/cparser/Elab.ml b/cparser/Elab.ml
index 871d545..95484b4 100644
--- a/cparser/Elab.ml
+++ b/cparser/Elab.ml
@@ -1664,22 +1664,24 @@ and elab_item zi item il =
or wchar array = L"wide string literal" *)
| (SINGLE_INIT (CONSTANT (CONST_STRING s))
| COMPOUND_INIT [_, SINGLE_INIT(CONSTANT (CONST_STRING s))]),
- TArray(TInt(ik, _), sz, _) ->
- begin match elab_string_literal loc s with
- | CStr s ->
- if ik <> IChar && ik <> IUChar && ik <> ISChar then
- error loc "initialization of an array of non-char elements with a string literal";
+ TArray(ty_elt, sz, _) ->
+ begin match elab_string_literal loc s, unroll env ty_elt with
+ | CStr s, TInt((IChar | ISChar | IUChar), _) ->
if not (I.index_below (Int64.of_int(String.length s - 1)) sz) then
warning loc "initializer string for array of chars %s is too long"
(I.name zi);
elab_list (I.set zi (init_char_array_string sz s)) il false
- | CWStr s ->
- if ik <> wchar_ikind then
- error loc "initialization of an array of non-wchar_t elements with a wide string literal";
+ | CStr _, _ ->
+ error loc "initialization of an array of non-char elements with a string literal";
+ elab_list zi il false
+ | CWStr s, TInt(ik, _) when ik = wchar_ikind ->
if not (I.index_below (Int64.of_int(List.length s - 1)) sz) then
warning loc "initializer string for array of wide chars %s is too long"
(I.name zi);
elab_list (I.set zi (init_int_array_wstring sz s)) il false
+ | CWStr _, _ ->
+ error loc "initialization of an array of non-wchar_t elements with a wide string literal";
+ elab_list zi il false
| _ -> assert false
end
(* Brace-enclosed compound initializer *)
diff --git a/test/regression/Results/initializers b/test/regression/Results/initializers
index a263012..5956fd9 100644
--- a/test/regression/Results/initializers
+++ b/test/regression/Results/initializers
@@ -22,3 +22,4 @@ x20 = { 'H', 'e', 'l', }
x21 = { 'H', 'e', 'l', 'l', 'o', '!', 0, 0, 0, 0, }
x22 ok
x23 = { hd = 8, tl = ok }
+x24[6] = { '/', '*', 'B', '*', '/', 0, }
diff --git a/test/regression/initializers.c b/test/regression/initializers.c
index 938795a..3524793 100644
--- a/test/regression/initializers.c
+++ b/test/regression/initializers.c
@@ -57,6 +57,10 @@ char * x22 = &(x10.u.y);
/* Initializer can refer to ident just declared */
struct list { int hd; struct list * tl; } x23 = { sizeof(x23), &x23 };
+/* Watch out for aliases of char types */
+typedef unsigned char byte;
+byte x24[] = "/*B*/";
+
static void print_chars(char * s, int sz)
{
int i;
@@ -120,6 +124,9 @@ int main()
printf("x22 error\n");
printf("x23 = { hd = %d, tl = %s }\n",
x23.hd, x23.tl == &x23 ? "ok" : "ERROR");
+ printf("x24[%d] = { ", (int) sizeof(x24));
+ print_chars((char *) x24, sizeof(x24));
+ printf("}\n");
return 0;
}