Changeset 2790 for driver/clightFromC.ml


Ignore:
Timestamp:
Mar 6, 2013, 3:48:20 PM (7 years ago)
Author:
campbell
Message:

Some null handling in conversion from CIL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/clightFromC.ml

    r2773 r2790  
    321321let ezero = Expr(Econst_int(I32, zero (convertIntNat 32)), Tint(I32, Signed))
    322322
     323let is_pointer = function
     324| Tpointer _ -> true
     325| _ -> false
     326
    323327let rec convertExpr env e =
    324328  let ty = convertTyp env e.etyp in
    325329  match e.edesc with
     330  | C.EConst(C.CInt(i, _, _)) when i = Int64.zero && is_pointer ty ->
     331      Expr(Ecast (ty, Expr (Econst_int (I8,zero (convertIntNat 8)), Tint (I8, Unsigned))), ty)
    326332  | C.EConst(C.CInt(i, k, _)) ->
    327333      let (_,sz) = convertIkind k in
     
    694700      match Ceval.constant_expr env ty e with
    695701      | Some(C.CInt(v, ik, _)) ->
    696           begin match convertIkind ik with
    697           | (_, I8) ->
    698               emit 1 (Init_int8(convertInt I8 v))
    699           | (_, I16) ->
    700               check_align 2;
    701               emit 2 (Init_int16(convertInt I16 v))
    702           | (_, I32) ->
    703               check_align 4;
    704               emit 4 (Init_int32(convertInt I32 v))
     702          begin match ty with
     703          | TPtr(_,_) ->
     704              (* The only integer constant that is a pointer is zero *)
     705              emit 2 Init_null
     706          | _ ->
     707            begin match convertIkind ik with
     708            | (_, I8) ->
     709                emit 1 (Init_int8(convertInt I8 v))
     710            | (_, I16) ->
     711                check_align 2;
     712                emit 2 (Init_int16(convertInt I16 v))
     713            | (_, I32) ->
     714                check_align 4;
     715                emit 4 (Init_int32(convertInt I32 v))
     716            end
    705717          end
    706718      | Some(C.CFloat(v, fk, _)) ->
Note: See TracChangeset for help on using the changeset viewer.