aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cfrontend/C2C.ml13
-rw-r--r--cparser/Ceval.ml8
-rw-r--r--cparser/Cutil.ml10
-rw-r--r--cparser/Elab.ml13
4 files changed, 21 insertions, 23 deletions
diff --git a/cfrontend/C2C.ml b/cfrontend/C2C.ml
index 5777eb96..9b6a4a7f 100644
--- a/cfrontend/C2C.ml
+++ b/cfrontend/C2C.ml
@@ -717,6 +717,7 @@ let ewrap = function
let rec convertExpr env e =
match e.edesc with
+ | C.EConst (C.CStr _ | C.CWStr _)
| C.EVar _
| C.EUnop((C.Oderef|C.Odot _|C.Oarrow _), _)
| C.EBinop(C.Oindex, _, _, _) ->
@@ -732,12 +733,6 @@ let rec convertExpr env e =
if k = C.FLongDouble && not !Clflags.option_flongdouble then
unsupported "'long double' floating-point constant";
convertFloat f k
- | C.EConst(C.CStr s) ->
- let ty = typeStringLiteral s in
- Evalof(Evar(name_for_string_literal s, ty), ty)
- | C.EConst(C.CWStr s) ->
- let ty = typeWideStringLiteral s in
- Evalof(Evar(name_for_wide_string_literal s, ty), ty)
| C.EConst(C.CEnum(id, i)) ->
Ctyping.econst_int (convertInt32 i) Signed
| C.ESizeof ty1 ->
@@ -960,6 +955,12 @@ and convertLvalue env e =
let e1' = convertExpr env e1 and e2' = convertExpr env e2 in
let e3' = ewrap (Ctyping.ebinop Cop.Oadd e1' e2') in
ewrap (Ctyping.ederef e3')
+ | C.EConst(C.CStr s) ->
+ let ty = typeStringLiteral s in
+ Evar(name_for_string_literal s, ty)
+ | C.EConst(C.CWStr s) ->
+ let ty = typeWideStringLiteral s in
+ Evar(name_for_wide_string_literal s, ty)
| _ ->
error "illegal lvalue"; ezero
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, _) ->
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
diff --git a/cparser/Elab.ml b/cparser/Elab.ml
index 6923491a..0d9d9d09 100644
--- a/cparser/Elab.ml
+++ b/cparser/Elab.ml
@@ -1765,18 +1765,7 @@ let elab_expr vararg loc env a =
error "invalid application of 'sizeof' to an incomplete type %a" (print_typ env) b1.etyp;
if wrap is_bitfield loc env b1 then
error "invalid application of 'sizeof' to a bit-field";
- let bdesc =
- (* Catch special cases sizeof("string literal") *)
- match b1.edesc with
- | EConst(CStr s) ->
- let sz = String.length s + 1 in
- EConst(CInt(Int64.of_int sz, size_t_ikind(), ""))
- | EConst(CWStr s) ->
- let sz = (!config).sizeof_wchar * (List.length s + 1) in
- EConst(CInt(Int64.of_int sz, size_t_ikind(), ""))
- | _ ->
- ESizeof b1.etyp in
- { edesc = bdesc; etyp = TInt(size_t_ikind(), []) },env
+ { edesc = ESizeof b1.etyp; etyp = TInt(size_t_ikind(), []) },env
| TYPE_SIZEOF (spec, dcl) ->
let (ty, env') = elab_type loc env spec dcl in