From a5f96b68f8af673f7666658f796f2322b6b9da93 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Sun, 27 May 2018 09:05:47 +0200 Subject: 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. --- cparser/Ceval.ml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'cparser/Ceval.ml') diff --git a/cparser/Ceval.ml b/cparser/Ceval.ml index 6247254f..58dea5f4 100644 --- a/cparser/Ceval.ml +++ b/cparser/Ceval.ml @@ -103,7 +103,7 @@ let cast env ty_to v = else raise Notconst | TPtr(ty, _), I n -> I (normalize_int n (ptr_t_ikind ())) - | TPtr(ty, _), (S _ | WS _) -> + | (TArray(ty, _, _) | TPtr (ty, _)), (S _ | WS _) -> v | TEnum(_, _), I n -> I (normalize_int n enum_ikind) @@ -272,8 +272,8 @@ let constant_expr env ty e = match unroll env ty, cast env ty (expr env e) with | TInt(ik, _), I n -> Some(CInt(n, ik, "")) | TPtr(_, _), I n -> Some(CInt(n, IInt, "")) - | TPtr(_, _), S s -> Some(CStr s) - | TPtr(_, _), WS s -> Some(CWStr s) + | (TArray(_, _, _) | TPtr(_, _)), S s -> Some(CStr s) + | (TArray(_, _, _) | TPtr(_, _)), WS s -> Some(CWStr s) | TEnum(_, _), I n -> Some(CInt(n, enum_ikind, "")) | _ -> None with Notconst -> None @@ -348,6 +348,8 @@ and is_constant_rval_of_lval env e = and is_constant_lval env e = match e.edesc with + | EConst (CStr _) + | EConst (CWStr _) -> true | EVar id -> begin match Env.find_ident env id with | Env.II_ident(sto, _) -> -- cgit