aboutsummaryrefslogtreecommitdiffstats
path: root/cfrontend
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 /cfrontend
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 'cfrontend')
-rw-r--r--cfrontend/C2C.ml13
1 files changed, 7 insertions, 6 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