aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Elab.ml
diff options
context:
space:
mode:
authorxleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2011-03-15 12:41:45 +0000
committerxleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2011-03-15 12:41:45 +0000
commitffd6080f9e1e742c73ac38354b31c6fc4e3963ba (patch)
tree48466e94e6ae8a8f7fa50c8fcf4ffb610d6dbed1 /cparser/Elab.ml
parentb6a2f5a9177892fa325e35a845c593902f6f203e (diff)
downloadcompcert-ffd6080f9e1e742c73ac38354b31c6fc4e3963ba.tar.gz
compcert-ffd6080f9e1e742c73ac38354b31c6fc4e3963ba.zip
Revised handling of sizeof(string-literal)
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1611 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'cparser/Elab.ml')
-rw-r--r--cparser/Elab.ml17
1 files changed, 12 insertions, 5 deletions
diff --git a/cparser/Elab.ml b/cparser/Elab.ml
index b79aa10b..92452b90 100644
--- a/cparser/Elab.ml
+++ b/cparser/Elab.ml
@@ -837,15 +837,22 @@ let elab_expr loc env a =
| CAST ((spec, dcl), _) ->
error "cast of initializer expression is not supported"
- | EXPR_SIZEOF(CONSTANT(CONST_STRING s)) ->
- let cst = CInt(Int64.of_int (String.length s), size_t_ikind, "") in
- { edesc = EConst cst; etyp = type_of_constant cst }
-
| EXPR_SIZEOF a1 ->
let b1 = elab a1 in
if sizeof env b1.etyp = None then
err "incomplete type %a" Cprint.typ b1.etyp;
- { edesc = ESizeof b1.etyp; etyp = TInt(size_t_ikind, []) }
+ 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, []) }
| TYPE_SIZEOF (spec, dcl) ->
let ty = elab_type loc env spec dcl in