aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Cutil.ml
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2014-12-30 17:10:43 +0100
committerXavier Leroy <xavier.leroy@inria.fr>2014-12-30 17:10:43 +0100
commit3b8a094dafdeea5499239adadaf24d2b8bdb1f76 (patch)
treef43cb88aa5e8f0d80a11af889b59163e07dac894 /cparser/Cutil.ml
parent2d32afc5daf16c75d1a34f2716c34ae2e1efcce4 (diff)
downloadcompcert-kvx-3b8a094dafdeea5499239adadaf24d2b8bdb1f76.tar.gz
compcert-kvx-3b8a094dafdeea5499239adadaf24d2b8bdb1f76.zip
PR#6: fix handling of wchar_t and assignments from wide string literals.
- cparser/Machine indicates whether wchar_t is signed or not (it is signed int in Linux and BSD, but unsigned short in Win32) - The type of a wide string literal is "wchar_t *" if the typedef "wchar_t" exists in the environment (e.g. after #include <stddef.h>). Only if wchar_t is not defined do we use the default from Machine. - Permit initialization of any integer array from a wide string literal, not just an array of wchar_t.
Diffstat (limited to 'cparser/Cutil.ml')
-rw-r--r--cparser/Cutil.ml18
1 files changed, 15 insertions, 3 deletions
diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml
index 9ad0b13d..7d1c2e4b 100644
--- a/cparser/Cutil.ml
+++ b/cparser/Cutil.ml
@@ -692,18 +692,30 @@ let find_matching_signed_ikind sz =
else if sz = !config.sizeof_longlong then ILongLong
else assert false
-let wchar_ikind = find_matching_unsigned_ikind !config.sizeof_wchar
+let wchar_ikind =
+ if !config.wchar_signed
+ then find_matching_signed_ikind !config.sizeof_wchar
+ else find_matching_unsigned_ikind !config.sizeof_wchar
let size_t_ikind = find_matching_unsigned_ikind !config.sizeof_size_t
let ptr_t_ikind = find_matching_unsigned_ikind !config.sizeof_ptr
let ptrdiff_t_ikind = find_matching_signed_ikind !config.sizeof_ptrdiff_t
+(** The wchar_t type. Try to get it from a typedef in the environment,
+ otherwise use the integer type described in !config. *)
+
+let wchar_type env =
+ try
+ let (id, def) = Env.lookup_typedef env "wchar_t" in TNamed(id, [])
+ with Env.Error _ ->
+ TInt(wchar_ikind, [])
+
(** The type of a constant *)
-let type_of_constant = function
+let type_of_constant env = function
| CInt(_, ik, _) -> TInt(ik, [])
| CFloat(_, fk) -> TFloat(fk, [])
| CStr _ -> TPtr(TInt(IChar, []), [])
- | CWStr _ -> TPtr(TInt(wchar_ikind, []), [])
+ | CWStr _ -> TPtr(wchar_type env, [])
| CEnum(_, _) -> TInt(IInt, [])
(* Check that a C expression is a lvalue *)