aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Cutil.ml
diff options
context:
space:
mode:
authorBernhard Schommer <bschommer@users.noreply.github.com>2018-05-27 09:05:47 +0200
committerXavier Leroy <xavierleroy@users.noreply.github.com>2018-05-27 09:05:47 +0200
commita5f96b68f8af673f7666658f796f2322b6b9da93 (patch)
tree10690b73f3029a0940c8c20352ec7886702801b2 /cparser/Cutil.ml
parent9dc1505c01a5748cdd5cac9d978645e2fbc0773c (diff)
downloadcompcert-kvx-a5f96b68f8af673f7666658f796f2322b6b9da93.tar.gz
compcert-kvx-a5f96b68f8af673f7666658f796f2322b6b9da93.zip
String literals are l-values and have array types (#116)
* Allow strings literals as lvalues. Strings and WStrings literals are lvalues, thus it is allowed to take their addresses. Bug 23356. * String literals have types "array of (wide) char", not "pointer to (wide) char" The pointer types were a leftover from the early, CIL-based C frontend. * Remove special case for sizeof("string literal") during elaboration No longer needed now that literals have array types.
Diffstat (limited to 'cparser/Cutil.ml')
-rw-r--r--cparser/Cutil.ml10
1 files changed, 8 insertions, 2 deletions
diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml
index 99b059c0..4d97823a 100644
--- a/cparser/Cutil.ml
+++ b/cparser/Cutil.ml
@@ -932,8 +932,12 @@ let ptrdiff_t_ikind () = find_matching_signed_ikind !config.sizeof_ptrdiff_t
let type_of_constant = function
| CInt(_, ik, _) -> TInt(ik, [])
| CFloat(_, fk) -> TFloat(fk, [])
- | CStr _ -> TPtr(TInt(IChar, []), [])
- | CWStr _ -> TPtr(TInt(wchar_ikind(), []), [])
+ | CStr s ->
+ let size = Int64.of_int (String.length s + 1) in
+ TArray(TInt(IChar,[]), Some size, [])
+ | CWStr s ->
+ let size = Int64.of_int (List.length s + 1) in
+ TArray(TInt(wchar_ikind(), []), Some size, [])
| CEnum(_, _) -> TInt(IInt, [])
(* Check that a C expression is a lvalue *)
@@ -941,6 +945,8 @@ let type_of_constant = function
let rec is_lvalue e =
match e.edesc with
| EVar id -> true
+ | EConst (CStr _)
+ | EConst (CWStr _) -> true
| EUnop((Oderef | Oarrow _), _) -> true
| EUnop(Odot _, e') -> is_lvalue e'
| EBinop(Oindex, _, _, _) -> true