Formal semantics and other research around Spark2014

Size: px
Start display at page:

Download "Formal semantics and other research around Spark2014"

Transcription

1 Formal semantics and other research around Spark2014 Virginia Aponte, Pierre Courtieu, Tristan Crolard (CPR Team - Cnam) Zhi Zhang (SAnToS, KSU) November 2014 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

2 In this talk 1 Ada and SPARK 2 Motivations & Current State 3 Run-Time Checks 4 Nested and recursive procedures 5 A prototype SPARK frontend for CompCert Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

3 Ada is not Pascal type MY_INT is new INTEGER range 0..9; procedure F(U: in out MY_INT) is TMP : MY_INT := 0; RES : MY_INT := U; while RES > TMP loop RES := RES - 1; TMP := TMP; end loop; U := RES; G(U,U); - warning: overlap end F; Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

4 Ada is not Pascal type MY_INT is new INTEGER range 0..9; procedure F(U: in out MY_INT) is TMP : MY_INT := 0; RES : MY_INT := U; while RES > TMP loop RES := RES - 1; TMP := TMP; end loop; U := RES; G(U,U); - warning: overlap end F; strong typing Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

5 Ada is not Pascal type MY_INT is new INTEGER range 0..9; procedure F(U: in out MY_INT) is TMP : MY_INT := 0; RES : MY_INT := U; while RES > TMP loop RES := RES - 1; TMP := TMP; end loop; U := RES; G(U,U); - warning: overlap end F; strong typing precise typing Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

6 Ada is not Pascal type MY_INT is new INTEGER range 0..9; procedure F(U: in out MY_INT) is TMP : MY_INT := 0; RES : MY_INT := U; while RES > TMP loop RES := RES - 1; TMP := TMP; end loop; U := RES; G(U,U); - warning: overlap end F; strong typing precise typing controlled effects Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

7 Ada is not Pascal type MY_INT is new INTEGER range 0..9; procedure F(U: in out MY_INT) is TMP : MY_INT := 0; RES : MY_INT := U; while RES > TMP loop RES := RES - 1; TMP := TMP; end loop; U := RES; G(U,U); - warning: overlap end F; OK statically Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

8 Ada is not Pascal type MY_INT is new INTEGER range 0..9; procedure F(U: in out MY_INT) is TMP : MY_INT := 0; RES : MY_INT := U; while RES > TMP loop RES := RES - 1; TMP := TMP; end loop; U := RES; G(U,U); - warning: overlap end F; OK statically OK statically Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

9 Ada is not Pascal type MY_INT is new INTEGER range 0..9; procedure F(U: in out MY_INT) is TMP : MY_INT := 0; RES : MY_INT := U; while RES > TMP loop RES := RES - 1; TMP := TMP; end loop; U := RES; G(U,U); - warning: overlap end F; OK statically OK statically dynamic! Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

10 Ada is not Pascal type MY_INT is new INTEGER range 0..9; procedure F(U: in out MY_INT) is TMP : MY_INT := 0; RES : MY_INT := U; while RES > TMP loop RES := RES - 1; TMP := TMP; end loop; U := RES; G(U,U); - warning: overlap end F; OK statically OK statically dynamic! runtime checks (RC) Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

11 Runtime checks Tests at runtime, exception raised when failing implicit tests: range, overflows, division by zero, array bounds,... explicit annotations always executable (gnat -gnata) used for testing mostly procedure F(U: in out MY_INT) with Pre => U >=0, Post => U<= U Old ; Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

12 Annotations In the specification (à la Hoare) In the code (à la Hoare) On types For flow analysis (SPARK only) etc procedure F(U: in out MY_INT) with Pre => U >=0, Post => U<= U Old ; Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

13 Annotations In the specification (à la Hoare) In the code (à la Hoare) On types For flow analysis (SPARK only) etc while RES > TMP loop Pragma Loop_Invariant ((RES <= U Loop_Entry) and (for all I in 0..t range => t[i]>0)) ;... end loop; Pragma Assert (RES <= TMP); Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

14 Annotations In the specification (à la Hoare) In the code (à la Hoare) On types For flow analysis (SPARK only) etc type Stack is private with Type_Invariant => Is_Unduplicated(Stack); Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

15 Annotations In the specification (à la Hoare) In the code (à la Hoare) On types For flow analysis (SPARK only) etc procedure F(U: out MY_INT2) with Global => (Input => (X,Y)), Depends => (U => (X,Y)); Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

16 SPARK is not Ada Developed by ALTRAN and now AdaCore too Dedicated to static analysis No dedicated compiler, strict subset of Ada Access types Effects in expressions Aliasing: warning not allowed (since no pointer) Exception handler... runtime checks static analysis Verification conditions à la Hoare (VCs) Ensures: No check would fail at runtime neither implicit (type/array bounds, initialization, div by zero, etc) nor explicit (assertion, loop invariant etc) Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

17 Plan 1 Ada and SPARK 2 Motivations & Current State 3 Run-Time Checks 4 Nested and recursive procedures 5 A prototype SPARK frontend for CompCert Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

18 Motivations Qualification of SPARK (DO-178C) AST validator w.r.t. run-time checks (RC) Link with other formalized tools (KSU) CompCert, certified compilation (Lockheed Martin) Semantics for Ada? ((very) long term) Proving invariant patterns Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

19 Previous works Ian O Neil. The formal semantics of SPARK83. Technical report. (format: Z) Eduardo Brito. PhD. A Formal Approach for a Subset of the SPARK Programming Language (format: Natural Semantics style) Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

20 Work in progress Team work, 2 internships of Zhi Zhang Big step semantics on untyped terms (ASTs) Typing = Property on (untyped-)terms Judgments: e, σ v or e, σ p, σ σ or p, σ = runtime error Abnormal (1+TRUE, uninitialized variable, etc) = execution blocked Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

21 Return states and error propagation Inductive Return (A : Type) : Type := Normal : A Return A (* σ, v *) Run_Time_Error : error_type Return A (* (+ msg) *) Seq 1 c 1, σ c 1 ; c 2, σ c 1, σ σ c 2, σ Seq 2 c 1 ; c 2, σ c 1, σ σ c 2, σ σ Seq 3 c 1 ; c 2, σ σ Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

22 Return states and error propagation Inductive eval_stmt: symboltable stack statement Return stack Prop :=... Eval_S_Sequence_RTE: st s c1 msg c2, eval_stmt st s c1 (Run_Time_Error msg) eval_stmt st s (S_Sequence c1 c2) (Run_Time_Error msg) Eval_S_Sequence: st s c1 s1 c2 s2, eval_stmt st s c1 (Normal s1) eval_stmt st s1 c2 s2 eval_stmt st s (S_Sequence c1 c2) s2 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

23 Error Propagation Eval_S_If_RTE: st s b msg c1 c2, eval_expr st s b (Run_Time_Error msg) eval_stmt st s (S_If b c1 c2) (Run_Time_Error msg) Eval_S_If_True: st s b c1 s1 c2, eval_expr st s b (Normal (BasicV (Bool true))) eval_stmt st s c1 s1 eval_stmt st s (S_If b c1 c2) s1... Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

24 Work in progress Subset of SPARK covered: Integers + subtypes + derived types Arrays and records (nested: current work by Z. Zhang) Procedures (recursive & nested), in, out, in out, No function Run-Time checks: a few, no annotation yet Prototype of a compiler to Cminor of CompCert (demo!) ia32, ppc, Arm No procedure contract yet Proved parts: Type checking/initialization (on a smaller subset) Run-Time checks (Z. Zhang) No compilation proof (starting now) Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

25 Plan 1 Ada and SPARK 2 Motivations & Current State 3 Run-Time Checks 4 Nested and recursive procedures 5 A prototype SPARK frontend for CompCert Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

26 GNAT/SPARK 2014 program + Pre Post Assert Loop_Invariant... Ada GNAT front-end AST (RC) GNAT back-end (gcc) gnatprove Why exec x86, ARM,... VCs alt-ergo, Z3,... Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

27 Correctness GNAT-gnatprove prog GNAT front-end AST + RC GNAT back-end exec Usual commutation diagram? gnatprove VCs p :AST+RC, gnatprove(p) s, GNAT(p), s Not sufficient Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

28 Correctness GNAT-gnatprove prog GNAT front-end AST + RC If RC incomplete? GNAT back-end exec? gnatprove VCs Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

29 Correctness GNAT-gnatprove prog GNAT front-end AST + RC GNAT back-end exec? gnatprove VCs If RC incomplete? Neither detected at runtime nor during anlysis erroneous program ou bounded errors Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

30 Correctness GNAT-gnatprove prog GNAT front-end AST + RC GNAT back-end exec? gnatprove VCs If RC incomplete? Neither detected at runtime nor during anlysis erroneous program ou bounded errors Correctness of the (result of the) front-end Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

31 Validating Run-time Checks (Z. Zhang) Two semantics: Semantics S 1 with on the fly checks Checks everything (no RCin AST) Reference, validated by experts Semantics S 2 with on demand checks Checks only RC Real + check_rc: AST+RC -> boolean + proof: t s.t. check_rc t = true, S 1 and S 2 coincide on t. S 2 may be optimized Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

32 With implicit on the fly run-time checks binop RTE1 e 1, σ e 1 e 2, σ e 1, σ v 1 e 2, σ binop RTE2 e 1 e 2, σ binop 2 e 1, σ v 1 e 2, σ v 2 RC(v 1, v 2, ) e 1 e 2, σ binop 1 e 1, σ v 1 e 2, σ v 2 RC(v 1, v 2, ) e 1 e 2, σ v 1 v 2 RC: predicate validated by ADA experts (division by zero, etc) Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

33 With explicit checks binop RTE1 e 1, σ e 1 C e 2, σ e 1, σ v 1 e 2, σ binop RTE2 e 1 C e 2, σ binop 1 e 1, σ v 1 e 2, σ v 2 C(v 1, v 2 ) e 1 C e 2, σ v 1 v 2 binop 2 e 1, σ v 1 e 2, σ v 2 C(v 1, v 2 ) e 1 C e 2, σ C: tags in the AST, generated by GNAT (front-end) C RC \ {optimization} Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

34 On the fly vs On demand Inductive eval_stmt: symboltable stack statement Return stack Prop :=... Inductive eval_stmt_x: symboltable stack statement_x Return stack Prop :=... Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

35 On the fly vs On demand: binary operations Eval_E_Binary_Operation_RTE_Bin: st s e1 v1 e2 v2 msg op, eval_expr st s e1 (Normal v1) eval_expr st s e2 (Normal v2) do_run_time_check_on_binop op v1 v2 (Exception msg) eval_expr st s (E_Binary_Operation op e1 e2) (Run_Time_Error msg) Eval_E_Binary_Operation_RTE_Bin_X: st s e1 v1 e2 v2 checkflags op msg, eval_expr_x st s e1 (Normal v1) eval_expr_x st s e2 (Normal v2) do_flagged_checks_on_binop checkflags op v1 v2 (Exception msg) eval_expr_x st s (E_Binary_Operation_X op e1 e2 checkflags) (Run_Time_Error msg) Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

36 On the fly vs On demand: binary operations Eval_E_Binary_Operation: st s e1 v1 e2 v2 op v, eval_expr st s e1 (Normal v1) eval_expr st s e2 (Normal v2) do_run_time_check_on_binop op v1 v2 Success Val.binary_operation op v1 v2 = Some v eval_expr st s (E_Binary_Operation op e1 e2) (Normal v) Eval_E_Binary_Operation_X: st s e1 v1 e2 v2 checkflags op v, eval_expr_x st s e1 (Normal v1) eval_expr_x st s e2 (Normal v2) do_flagged_checks_on_binop checkflags op v1 v2 Success Val.binary_operation op v1 v2 = Some v eval_expr_x st s (E_Binary_Operation_X op e1 e2 checkfla (Normal v) Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

37 On the fly vs On demand: Range check for assignment Eval_S_Assignment_Range_RTE: st s e v x t l u, eval_expr st s e (Normal (BasicV (Int v))) extract_subtype_range st x (Range l u) do_range_check v l u (Exception RTE_Range) eval_stmt st s (S_Assignment x e) (Run_Time_Error RTE_Range) Eval_S_Assignment_RTE_X: e st s msg x, (List.In Do_Range_Check (exp_check_flags e)) eval_expr_x st s e... Eval_S_Assignment_Range_RTE_X: e flgs st s v x t l u, exp_check_flags e = Do_Range_Check flgs eval_expr_x st s (update_exp_check_flags e flgs) (Normal (BasicV (Int v))) extract_subtype_range_x st x (Range_X l u)... Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

38 On the fly vs On demand: Range check for assignment Eval_S_Assignment_Range: st s e v x t l u s1, eval_expr st s e (Normal (BasicV (Int v))) fetch_exp_type x st = Some t extract_subtype_range st t (Range l u) do_range_check v l u Success storeupdate st s x (BasicV (Int v)) s1 eval_stmt st s (S_Assignment x e) s1 Eval_S_Assignment_Range_X: e cks1 cks2 st s v x t l u s1, exp_check_flags e = Do_Range_Check flgs eval_expr_x st s (update_exp_check_flags e flgs) (Normal (BasicV (Int v))) extract_subtype_range_x st x (Range_X l u) do_range_check v l u Success storeupdate_x st s x (BasicV (Int v)) s1 eval_stmt_x st s (S_Assignment_X x e) s1 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

39 Properties of the ast validator Definition check_generator: statement statement_x. Lemma statement_checks_soundness: st s stmt s st, eval_stmt st s stmt s check_generator stmt = stmt eval_stmt_x st s stmt s. Definition check_rc stmt_x = check_generator(noflags stmt_x) = stmt_x. Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

40 Run-Time Checks covered Very few, proof of concept Division by zero (integers) Overflows (integers,arrays) Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

41 Table des matieres 1 Ada and SPARK 2 Motivations & Current State 3 Run-Time Checks 4 Nested and recursive procedures 5 A prototype SPARK frontend for CompCert Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

42 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

43 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); X2 X 1 3 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

44 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

45 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

46 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

47 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

48 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

49 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

50 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; L(X2); Put(X2); G(3); Dynamic context Y 3 Y 2 Y 1 X2 2 X 3 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

51 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; L(X2); Put(X2); G(3); Dynamic context Y 3 Y 2 Y 1 X2 6 X 3 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

52 Nested recursive procedures: P-machine procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); X2 X 6 3 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

53 Nested recursive procedures procedure G(X:INTEGER) is VG: INTEGER; procedure L(Y:INTEGER) is VL: INTEGER..L(e).. end L;... end G; Static context VL Y VG X Dynamic context VL Y VG X Dynamic environment static one But Dynamic environment static visible one How to present a reference semantics? Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

54 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

55 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); X2 X 1 3 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

56 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

57 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

58 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

59 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

60 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

61 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

62 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

63 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); Y X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

64 Nested recursive procedures: Reference procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; Dynamic context L(X2); Put(X2); G(3); X2 X 6 3 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

65 Nested recursive procedure fetch_proc p st = (proc_lvl,pb) eval_stmt st s (S_Procedure_Call p args) s4 procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; s Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

66 Nested recursive procedure fetch_proc p st = (proc_lvl,pb) copy_in st s (parameters pb) args (Normal f) eval_stmt st s (S_Procedure_Call p args) s4 procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; s f Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

67 Nested recursive procedure fetch_proc p st = (proc_lvl,pb) copy_in st s (parameters pb) args (Normal f) cut_until s proc_lvl pfx s1 eval_stmt st s (S_Procedure_Call p args) s4 procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; pfx s1 f Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

68 Nested recursive procedure fetch_proc p st = (proc_lvl,pb) copy_in st s (parameters pb) args (Normal f) cut_until s proc_lvl pfx s1 eval_decl st s1 f (declarative_part pb) (Normal f1) eval_stmt st s (S_Procedure_Call p args) s4 procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; pfx s1 f1 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

69 Nested recursive procedure fetch_proc p st = (proc_lvl,pb) copy_in st s (parameters pb) args (Normal f) cut_until s proc_lvl pfx s1 eval_decl st s1 f (declarative_part pb) (Normal f1) eval_stmt st (f1 ++ s1) (statements pb) (Normal s2) eval_stmt st s (S_Procedure_Call p args) s4 procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if;... 2 pfx f1++s1 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

70 Nested recursive procedure fetch_proc p st = (proc_lvl,pb) copy_in st s (parameters pb) args (Normal f) cut_until s proc_lvl pfx s1 eval_decl st s1 f (declarative_part pb) (Normal f1) eval_stmt st (f1 ++ s1) (statements pb) (Normal s2) eval_stmt st s (S_Procedure_Call p args) s4 procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if;... 2 pfx s2 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

71 Nested recursive procedure fetch_proc p st = (proc_lvl,pb) copy_in st s (parameters pb) args (Normal f) cut_until s proc_lvl pfx s1 eval_decl st s1 f (declarative_part pb) (Normal f1) eval_stmt st (f1 ++ s1) (statements pb) (Normal s2) s2 = locls ++ parms ++ s3 eval_stmt st s (S_Procedure_Call p args) s4 procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; pfx s3 parms Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

72 Nested recursive procedure fetch_proc p st = (proc_lvl,pb) copy_in st s (parameters pb) args (Normal f) cut_until s proc_lvl pfx s1 eval_decl st s1 f (declarative_part pb) (Normal f1) eval_stmt st (f1 ++ s1) (statements pb) (Normal s2) s2 = locls ++ parms ++ s3 copy_out st (pfx ++ s3) parms (parameters pb) args s4 eval_stmt st s (S_Procedure_Call p args) s4 procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; copy_out 3 pfx++s3 3 parms Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

73 Nested recursive procedure fetch_proc p st = (proc_lvl,pb) copy_in st s (parameters pb) args (Normal f) cut_until s proc_lvl pfx s1 eval_decl st s1 f (declarative_part pb) (Normal f1) eval_stmt st (f1 ++ s1) (statements pb) (Normal s2) s2 = locls ++ parms ++ s3 copy_out st (pfx ++ s3) parms (parameters pb) args s4 eval_stmt st s (S_Procedure_Call p args) s4 procedure G (X: in Integer) is X2: Integer := 1; procedure L (Y: in Integer) is X2 := X2 * Y; if Y < X then L(Y+1); end if; s4 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

74 Equivalence with P-machine (T. Crolard) P-M. p, σ 1 σ 2 p, σ 1 Ref. σ 2 Coq development Small toy language Correctness P-Machine vs Ref. Semantics Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

75 Equivalence with P-machine (T. Crolard) P-M. p, σ 1 σ 2 Ref. w. names p, σ 1 σ 2 compil+ p, σ 1 Ref. σ 2 Ref. ˆp, ˆσ 1 ˆσ 2 Coq development Small toy language Correctness P-Machine vs Ref. Semantics + compilation P-machine with var. names P-machine (offsets) Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

76 Equivalence with P-machine (T. Crolard) P-M. p, σ 1 σ 2 Ref. w. names p, σ 1 σ 2 compil+ p, σ 1 Ref. σ 2 Ref. ˆp, ˆσ 1 ˆσ 2 One functorized semantics, three stack modules 1376 LOC statements, 1777 LOC proofs Completeness under way (T.Crolard, M.V. Aponte, J.Lawall) Extend it to the whole SPARK semantics? Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

77 CompCert frontend program + Pre Post Assert Loop_Invariant... Ada GNAT front-end to be proved correct AST (RC) CompCert back-end correct GNAT back-end (gcc) gnatprove Why exec VCs x86, ARM,... alt-ergo, Z3,... Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

78 Why CompCert? Having a (partially) proved compilation chain Testing semantics for pure SPARK? How flexible is CompCert? Nested (recursive) procedures are fun ( see later), despite easier than in Ada Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

79 Target language: Cminor C#minor too loose memory model RTL to low level Cminor all what we need Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

80 Cminor Function frame Each function leaves in a separate frame Local temporary variables (parameters + some local variables) Local stack (other variables) Initially: empty stack, all arguments in temporary variables C frontend: prelude to copy some variables in the stack... Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

81 Nested procedures in Cminor L procedure G (X: in out Integer) is X2: Integer := 1; procedure L (Y: in Integer) is Y2: Integer := 1; X2 := X2 * Y; if Y < X then L(Y+1); end if; L(X2); X := X2; Y Y2 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

82 Nested procedures in Cminor procedure G (X: in out Integer) is X2: Integer := 1; procedure L (Y: in Integer) is Y2: Integer := 1; X2 := X2 * Y; if Y < X then L(Y+1); end if; L(X2); X := X2; & Y Y2 L G & = ptr to G s stack X X2 Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

83 Nested procedures in Cminor procedure G (X: in out Integer) is X2: Integer := 1; procedure L (Y: in Integer) is Y2: Integer := 1; X2 := X2 * Y; if Y < X then L(Y+1); end if; L(X2); X := X2; & Y Y2 L G & = ptr to G s stack Needed copies on stack: prelude X X2 X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

84 Nested procedures in Cminor procedure G (X: in out Integer) is X2: Integer := 1; procedure L (Y: in Integer) is Y2: Integer := 1; X2 := X2 * Y; if Y < X then L(Y+1); end if; L(X2); X := X2; & Y Y2 L G & = ptr to G s stack Needed copies on stack: prelude out parameters: postlude &X X2 X2 X Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

85 Example "G"( X ) : int -> void { stack 8; var X2 ; int32[&0 + 0] = int32[ X ]; int32[&0 + 4] = 1; "L"(&0, int32[&0 + 4]) : int -> int -> void; int32[&0 + 0] = int32[&0 + 4]; int32[ X ] = int32[&0 + 0]; } "L"( CHAIN, Y ) : int -> int -> void { stack 12; var Y2 ; int32[&0] = CHAIN ; int32[&0 + 4] = Y ; int32[&0 + 8] = 1; int32[int32[&0] + 4] = int32[int32[&0] + 4] * int32[&0 + 4]; if (int32[&0 + 4] < int32[int32[&0] + 0]!= 0) { "L"(int32[&0], int32[&0 + 4] + 1) : int -> int -> void; } } Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

86 Demo CompCert Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

87 Future Works Annotations, contracts Prove CompCert compilation Prove loop invariants patterns [FM2012] (M-V. Aponte) Test and proof, a.k.a. mixing memory models of SPARK and Ada etc Thanks! Aponte, Courtieu, Crolard, Zhang Formal semantics for SPARK & more November / 41

Spark verification features

Spark verification features Spark verification features Paul Jackson School of Informatics University of Edinburgh Formal Verification Spring 2018 Adding specification information to programs Verification concerns checking whether

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility Informal Semantics of Data semantic specification names (identifiers) attributes binding declarations scope rules visibility 1 Ways to Specify Semantics Standards Documents (Language Definition) Language

More information

GNATprove a Spark2014 verifying compiler Florian Schanda, Altran UK

GNATprove a Spark2014 verifying compiler Florian Schanda, Altran UK 1 GNATprove a Spark2014 verifying compiler Florian Schanda, Altran UK Tool architecture User view Source gnatprove Verdict 2 Tool architecture More detailed view... Source Encoding CVC4 gnat2why gnatwhy3

More information

COS 320. Compiling Techniques

COS 320. Compiling Techniques Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly

More information

Type checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39

Type checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39 Type checking Jianguo Lu November 27, 2014 slides adapted from Sean Treichler and Alex Aiken s Jianguo Lu November 27, 2014 1 / 39 Outline 1 Language translation 2 Type checking 3 optimization Jianguo

More information

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 27, 2017

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 27, 2017 Verified Characteristic Formulae for CakeML Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 27, 2017 Goal: write programs in a high-level (ML-style) language, prove them correct interactively,

More information

Programming Languages Lecture 15: Recursive Types & Subtyping

Programming Languages Lecture 15: Recursive Types & Subtyping CSE 230: Winter 2008 Principles of Programming Languages Lecture 15: Recursive Types & Subtyping Ranjit Jhala UC San Diego News? Formalize first-order type systems Simple types (integers and booleans)

More information

GNAT Pro Innovations for High-Integrity Development

GNAT Pro Innovations for High-Integrity Development GNAT Pro Innovations for High-Integrity Development José F. Ruiz Senior Software Engineer Ada Europe 2010, Valencia 2010-06-15 www.adacore.com Index Development environment Tools Static

More information

Why. an intermediate language for deductive program verification

Why. an intermediate language for deductive program verification Why an intermediate language for deductive program verification Jean-Christophe Filliâtre CNRS Orsay, France AFM workshop Grenoble, June 27, 2009 Jean-Christophe Filliâtre Why tutorial AFM 09 1 / 56 Motivations

More information

Deductive Verification in Frama-C and SPARK2014: Past, Present and Future

Deductive Verification in Frama-C and SPARK2014: Past, Present and Future Deductive Verification in Frama-C and SPARK2014: Past, Present and Future Claude Marché (Inria & Université Paris-Saclay) OSIS, Frama-C & SPARK day, May 30th, 2017 1 / 31 Outline Why this joint Frama-C

More information

Verasco: a Formally Verified C Static Analyzer

Verasco: a Formally Verified C Static Analyzer Verasco: a Formally Verified C Static Analyzer Jacques-Henri Jourdan Joint work with: Vincent Laporte, Sandrine Blazy, Xavier Leroy, David Pichardie,... June 13, 2017, Montpellier GdR GPL thesis prize

More information

Relation Overriding. Syntax and Semantics. Simple Semantic Domains. Operational Semantics

Relation Overriding. Syntax and Semantics. Simple Semantic Domains. Operational Semantics SE3E03, 2006 1.59 61 Syntax and Semantics Syntax Shape of PL constructs What are the tokens of the language? Lexical syntax, word level How are programs built from tokens? Mostly use Context-Free Grammars

More information

Hybrid Verification in SPARK 2014: Combining Formal Methods with Testing

Hybrid Verification in SPARK 2014: Combining Formal Methods with Testing IEEE Software Technology Conference 2015 Hybrid Verification in SPARK 2014: Combining Formal Methods with Testing Steve Baird Senior Software Engineer Copyright 2014 AdaCore Slide: 1 procedure Array_Indexing_Bug

More information

Reminder of the last lecture. Aliasing Issues: Call by reference, Pointer programs. Introducing Aliasing Issues. Home Work from previous lecture

Reminder of the last lecture. Aliasing Issues: Call by reference, Pointer programs. Introducing Aliasing Issues. Home Work from previous lecture Reminder of the last lecture Aliasing Issues: Call by reference, Pointer programs Claude Marché Cours MPRI 2-36-1 Preuve de Programme 18 janvier 2017 Additional features of the specification language Abstract

More information

A concrete memory model for CompCert

A concrete memory model for CompCert A concrete memory model for CompCert Frédéric Besson Sandrine Blazy Pierre Wilke Rennes, France P. Wilke A concrete memory model for CompCert 1 / 28 CompCert real-world C to ASM compiler used in industry

More information

SPARK 2014 User s Guide

SPARK 2014 User s Guide SPARK 2014 User s Guide Release 19.0w AdaCore and Altran UK Ltd Apr 27, 2018 Copyright (C) 2011-2017, AdaCore and Altran UK Ltd Permission is granted to copy, distribute and/or modify this document under

More information

Safe Dynamic Memory Management in Ada and SPARK

Safe Dynamic Memory Management in Ada and SPARK Safe Dynamic Memory Management in Ada and SPARK Maroua Maalej, Tucker Taft, Yannick Moy AdaCore Ada-Europe June 19, 2018 Safe Dynamic Memory Management in Ada and SPARK Maroua Maalej 1/28 Why Try To Verify

More information

CS 314 Principles of Programming Languages. Lecture 13

CS 314 Principles of Programming Languages. Lecture 13 CS 314 Principles of Programming Languages Lecture 13 Zheng Zhang Department of Computer Science Rutgers University Wednesday 19 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:

More information

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem: Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd

More information

Programming Languages Lecture 14: Sum, Product, Recursive Types

Programming Languages Lecture 14: Sum, Product, Recursive Types CSE 230: Winter 200 Principles of Programming Languages Lecture 4: Sum, Product, Recursive Types The end is nigh HW 3 No HW 4 (= Final) Project (Meeting + Talk) Ranjit Jhala UC San Diego Recap Goal: Relate

More information

Deductive Program Verification with Why3, Past and Future

Deductive Program Verification with Why3, Past and Future Deductive Program Verification with Why3, Past and Future Claude Marché ProofInUse Kick-Off Day February 2nd, 2015 A bit of history 1999: Jean-Christophe Filliâtre s PhD Thesis Proof of imperative programs,

More information

Simulink 모델과 C/C++ 코드에대한매스웍스의정형검증툴소개 The MathWorks, Inc. 1

Simulink 모델과 C/C++ 코드에대한매스웍스의정형검증툴소개 The MathWorks, Inc. 1 Simulink 모델과 C/C++ 코드에대한매스웍스의정형검증툴소개 2012 The MathWorks, Inc. 1 Agenda Formal Verification Key concept Applications Verification of designs against (functional) requirements Design error detection Test

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages Lesson 14 Type Checking Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172 1 Type Checking We return to the issue of type safety we discussed informally,

More information

SPARKSkein A Formal and Fast Reference Implementation of Skein

SPARKSkein A Formal and Fast Reference Implementation of Skein SPARKSkein A Formal and Fast Reference Implementation of Skein Rod Chapman, Altran Praxis Copyright Altran Praxis Agenda The big idea What is Skein? Coding SPARKSkein Results The release Conclusions and

More information

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing

More information

Program Verification (6EC version only)

Program Verification (6EC version only) Program Verification (6EC version only) Erik Poll Digital Security Radboud University Nijmegen Overview Program Verification using Verification Condition Generators JML a formal specification language

More information

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Summary 1. Predictive Parsing 2. Large Step Operational Semantics (Natural) 3. Small Step Operational Semantics

More information

An Operational and Axiomatic Semantics for Non-determinism and Sequence Points in C

An Operational and Axiomatic Semantics for Non-determinism and Sequence Points in C An Operational and Axiomatic Semantics for Non-determinism and Sequence Points in C Robbert Krebbers Radboud University Nijmegen January 22, 2014 @ POPL, San Diego, USA 1 / 16 What is this program supposed

More information

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d) CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)

More information

CIS 890: Safety Critical Systems

CIS 890: Safety Critical Systems CIS 890: Safety Critical Systems Lecture: SPARK -- Analysis Tools Copyright 2007, John Hatcliff. The syllabus and all lectures for this course are copyrighted materials and may not be used in other course

More information

Lecture 15 CIS 341: COMPILERS

Lecture 15 CIS 341: COMPILERS Lecture 15 CIS 341: COMPILERS Announcements HW4: OAT v. 1.0 Parsing & basic code generation Due: March 28 th No lecture on Thursday, March 22 Dr. Z will be away Zdancewic CIS 341: Compilers 2 Adding Integers

More information

Implementation Guidance for the Adoption of SPARK

Implementation Guidance for the Adoption of SPARK Implementation Guidance for the Adoption of SPARK Release 1.0 AdaCore and Thales Jan 26, 2017 Copyright (C) 2016-2017, AdaCore and Thales Licensed under Creative Commons Attribution 4.0 International CONTENTS

More information

Advanced Systems Programming

Advanced Systems Programming Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short

More information

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End

More information

A Mechanically Verified Code Generator

A Mechanically Verified Code Generator A Mechanically Verified Code Generator William D. Young Technical Report 37 January, 1989 Computational Logic Inc. 1717 W. 6th St. Suite 290 Austin, Texas 78703 (512) 322-9951 This work was supported in

More information

Formal verification of program obfuscations

Formal verification of program obfuscations Formal verification of program obfuscations Sandrine Blazy joint work with Roberto Giacobazzi and Alix Trieu IFIP WG 2.11, 2015-11-10 1 Background: verifying a compiler Compiler + proof that the compiler

More information

Work-in-progress: "Verifying" the Glasgow Haskell Compiler Core language

Work-in-progress: Verifying the Glasgow Haskell Compiler Core language Work-in-progress: "Verifying" the Glasgow Haskell Compiler Core language Stephanie Weirich Joachim Breitner, Antal Spector-Zabusky, Yao Li, Christine Rizkallah, John Wiegley June 2018 Let's prove GHC correct

More information

Translation Validation for a Verified OS Kernel

Translation Validation for a Verified OS Kernel To appear in PLDI 13 Translation Validation for a Verified OS Kernel Thomas Sewell 1, Magnus Myreen 2, Gerwin Klein 1 1 NICTA, Australia 2 University of Cambridge, UK L4.verified sel4 = a formally verified

More information

Adam Chlipala University of California, Berkeley ICFP 2006

Adam Chlipala University of California, Berkeley ICFP 2006 Modular Development of Certified Program Verifiers with a Proof Assistant Adam Chlipala University of California, Berkeley ICFP 2006 1 Who Watches the Watcher? Program Verifier Might want to ensure: Memory

More information

Chapter 1. Introduction

Chapter 1. Introduction 1 Chapter 1 Introduction An exciting development of the 21st century is that the 20th-century vision of mechanized program verification is finally becoming practical, thanks to 30 years of advances in

More information

Aliasing restrictions of C11 formalized in Coq

Aliasing restrictions of C11 formalized in Coq Aliasing restrictions of C11 formalized in Coq Robbert Krebbers Radboud University Nijmegen December 11, 2013 @ CPP, Melbourne, Australia Aliasing Aliasing: multiple pointers referring to the same object

More information

Implementing Subprograms

Implementing Subprograms 1 Implementing Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University CS315 Programming Languages Pinar Duygulu The General Semantics of Calls and Returns 2 The subprogram call and return

More information

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming t ::= x x. t t t Call-by-value big-step Operational Semantics terms variable v ::= values abstraction x.

More information

COMP520 - GoLite Type Checking Specification

COMP520 - GoLite Type Checking Specification COMP520 - GoLite Type Checking Specification Vincent Foley March 5, 2017 1 Introduction This document presents the typing rules for all the language constructs (i.e. declarations, statements, expressions)

More information

Sanitizing Sensitive Data: How to get it Right (or at least Less Wrong ) Roderick Chapman, 22nd September 2017

Sanitizing Sensitive Data: How to get it Right (or at least Less Wrong ) Roderick Chapman, 22nd September 2017 Sanitizing Sensitive Data: How to get it Right (or at least Less Wrong ) Roderick Chapman, 22nd September 2017 Contents The problem Technical issues Design goals Language support A policy for sanitization

More information

INFORMATION AND COMMUNICATION TECHNOLOGIES (ICT) PROGRAMME. Project FP7-ICT-2009-C CerCo. Report n. D2.2 Prototype implementation

INFORMATION AND COMMUNICATION TECHNOLOGIES (ICT) PROGRAMME. Project FP7-ICT-2009-C CerCo. Report n. D2.2 Prototype implementation INFORMATION AND COMMUNICATION TECHNOLOGIES (ICT) PROGRAMME Project FP7-ICT-2009-C-243881 CerCo Report n. D2.2 Prototype implementation Version 1.0 Main Authors: Nicolas Ayache, Roberto M. Amadio, Yann

More information

How much is a mechanized proof worth, certification-wise?

How much is a mechanized proof worth, certification-wise? How much is a mechanized proof worth, certification-wise? Xavier Leroy Inria Paris-Rocquencourt PiP 2014: Principles in Practice In this talk... Some feedback from the aircraft industry concerning the

More information

Mutable References. Chapter 1

Mutable References. Chapter 1 Chapter 1 Mutable References In the (typed or untyped) λ-calculus, or in pure functional languages, a variable is immutable in that once bound to a value as the result of a substitution, its contents never

More information

A Verified Implementation of the Bounded List Container

A Verified Implementation of the Bounded List Container A Verified Implementation of the Bounded List Container Raphaël Cauderlier, Mihaela Sighireanu March 26, 2018 1 / 32 Outline 1 Introduction 2 Bounded Doubly-Linked Lists 3 Verification 4 Conclusion 2 /

More information

Semantic Processing. Semantic Errors. Semantics - Part 1. Semantics - Part 1

Semantic Processing. Semantic Errors. Semantics - Part 1. Semantics - Part 1 Semantic Processing The Lexer and Parser Found lexical and syntax errors Built Abstract Syntax Tree Now!Find semantic errors.!build information about the program. Later!Generate IR Code!Optimize IR Code!Generate

More information

A CRASH COURSE IN SEMANTICS

A CRASH COURSE IN SEMANTICS LAST TIME Recdef More induction NICTA Advanced Course Well founded orders Slide 1 Theorem Proving Principles, Techniques, Applications Slide 3 Well founded recursion Calculations: also/finally {P}... {Q}

More information

A3. Programming Languages for Writing Safety-Critical Software

A3. Programming Languages for Writing Safety-Critical Software A3. Programming Languages for Writing Safety-Critical Software (a) Overview. (b) SPARK Ada. Critical Systems, CS 411, Lent term 2002, Sec. A3 A3-1 (a) Overview Important Factors for Programming Languages

More information

Formal Verification in Aeronautics: Current Practice and Upcoming Standard. Yannick Moy, AdaCore ACSL Workshop, Fraunhofer FIRST

Formal Verification in Aeronautics: Current Practice and Upcoming Standard. Yannick Moy, AdaCore ACSL Workshop, Fraunhofer FIRST Formal Verification in Aeronautics: Current Practice and Upcoming Standard Yannick Moy, AdaCore ACSL Workshop, Fraunhofer FIRST Outline Project Hi-Lite Industrial Applications DO-178C DO-178B 1992 2012

More information

LECTURE 3. Compiler Phases

LECTURE 3. Compiler Phases LECTURE 3 Compiler Phases COMPILER PHASES Compilation of a program proceeds through a fixed series of phases. Each phase uses an (intermediate) form of the program produced by an earlier phase. Subsequent

More information

Program certification with computational

Program certification with computational Program certification with computational effects Burak Ekici j.w.w. Jean-Guillaume Dumas, Dominique Duval, Damien Pous y LJK, University Joseph Fourier, Grenoble y LIP, ENS-Lyon November 5, 2014 JNCF 14,

More information

Introduction to Axiomatic Semantics

Introduction to Axiomatic Semantics Introduction to Axiomatic Semantics Meeting 10, CSCI 5535, Spring 2009 Announcements Homework 3 due tonight Homework 2 is graded 13 (mean), 14 (median), out of 21 total, but Graduate class: final project

More information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 17: Types and Type-Checking 25 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 What Are Types? Types describe the values possibly

More information

AdaCore technologies

AdaCore technologies AdaCore technologies for CENELEC EN 50128 2011 Eric Perlade Technical Account Manager RSSRail 2017 CENELEC EN 50128:2011 CENELEC EN 50128 Main standards applicable to railway systems Complete System 50126

More information

CSC313 High Integrity Systems/CSCM13 Critical Systems. CSC313/CSCM13 Chapter 1 1/ 38

CSC313 High Integrity Systems/CSCM13 Critical Systems. CSC313/CSCM13 Chapter 1 1/ 38 CSC313 High Integrity Systems/CSCM13 Critical Systems CSC313/CSCM13 Chapter 1 1/ 38 CSC313 High Integrity Systems/ CSCM13 Critical Systems Course Notes Chapter 1: Programming Languages for Writing Safety-Critical

More information

Programming Languages

Programming Languages CSE 230: Winter 2008 Principles of Programming Languages Ocaml/HW #3 Q-A Session Push deadline = Mar 10 Session Mon 3pm? Lecture 15: Type Systems Ranjit Jhala UC San Diego Why Typed Languages? Development

More information

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8 Subroutines and Control Abstraction Textbook, Chapter 8 1 Subroutines and Control Abstraction Mechanisms for process abstraction Single entry (except FORTRAN, PL/I) Caller is suspended Control returns

More information

Enhance Verification using Ghost Code

Enhance Verification using Ghost Code Enhance Verification using Ghost Code Claire Dross SSAS Workshop 2018 Ghost Code, What Is It? 2 Ghost Code General Definition Ghost code does not affect normal execution of a program. Regular Code Ghost

More information

Part II. Hoare Logic and Program Verification. Why specify programs? Specification and Verification. Code Verification. Why verify programs?

Part II. Hoare Logic and Program Verification. Why specify programs? Specification and Verification. Code Verification. Why verify programs? Part II. Hoare Logic and Program Verification Part II. Hoare Logic and Program Verification Dilian Gurov Props: Models: Specs: Method: Tool: safety of data manipulation source code logic assertions Hoare

More information

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 CS 314, LS,BR,LTM: Scope and Memory 1 Review Functions as first-class objects What can you do with an integer?

More information

Deductive Program Verification with Why3

Deductive Program Verification with Why3 Deductive Program Verification with Why3 Jean-Christophe Filliâtre CNRS Mathematical Structures of Computation Formal Proof, Symbolic Computation and Computer Arithmetic Lyon, February 2014 definition

More information

Semantic Analysis. Lecture 9. February 7, 2018

Semantic Analysis. Lecture 9. February 7, 2018 Semantic Analysis Lecture 9 February 7, 2018 Midterm 1 Compiler Stages 12 / 14 COOL Programming 10 / 12 Regular Languages 26 / 30 Context-free Languages 17 / 21 Parsing 20 / 23 Extra Credit 4 / 6 Average

More information

18-642: Code Style for Compilers

18-642: Code Style for Compilers 18-642: Code Style for Compilers 9/6/2018 2017-2018 Philip Koopman Programming can be fun, so can cryptography; however they should not be combined. Kreitzberg and Shneiderman 2017-2018 Philip Koopman

More information

Operational Semantics of Cool

Operational Semantics of Cool Operational Semantics of Cool Key Concepts semantics: the meaning of a program, what does program do? how the code is executed? operational semantics: high level code generation steps of calculating values

More information

Formal verification of an optimizing compiler

Formal verification of an optimizing compiler Formal verification of an optimizing compiler Xavier Leroy INRIA Rocquencourt RTA 2007 X. Leroy (INRIA) Formal compiler verification RTA 2007 1 / 58 The compilation process General definition: any automatic

More information

Work-in-progress: Verifying the Glasgow Haskell Compiler Core language

Work-in-progress: Verifying the Glasgow Haskell Compiler Core language Work-in-progress: Verifying the Glasgow Haskell Compiler Core language Stephanie Weirich Joachim Breitner, Antal Spector-Zabusky, Yao Li, Christine Rizkallah, John Wiegley May 2018 Verified compilers and

More information

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result. Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs

More information

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 13: Types and Type-Checking 19 Feb 07 Semantic Analysis Last time: Semantic errors related to scopes Symbol tables Name resolution This lecture:

More information

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator CS 412/413 Introduction to Compilers and Translators Andrew Myers Cornell University Administration Design reports due Friday Current demo schedule on web page send mail with preferred times if you haven

More information

Proof Carrying Code(PCC)

Proof Carrying Code(PCC) Discussion p./6 Proof Carrying Code(PCC Languaged based security policy instead of OS-based A mechanism to determine with certainity that it is safe execute a program or not Generic architecture for providing

More information

COMP520 - GoLite Type Checking Specification

COMP520 - GoLite Type Checking Specification COMP520 - GoLite Type Checking Specification Vincent Foley April 8, 2018 1 Introduction This document presents the typing rules for all the language constructs (i.e. declarations, statements, expressions)

More information

Why3 where programs meet provers

Why3 where programs meet provers Why3 where programs meet provers Jean-Christophe Filliâtre CNRS KeY Symposium 2017 Rastatt, Germany October 5, 2017 history started in 2001, as an intermediate language in the process of verifying C and

More information

Verified compilers. Guest lecture for Compiler Construction, Spring Magnus Myréen. Chalmers University of Technology

Verified compilers. Guest lecture for Compiler Construction, Spring Magnus Myréen. Chalmers University of Technology Guest lecture for Compiler Construction, Spring 2015 Verified compilers Magnus Myréen Chalmers University of Technology Mentions joint work with Ramana Kumar, Michael Norrish, Scott Owens and many more

More information

Recursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem

Recursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem Recursion Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem What is Recursion? A problem is decomposed into smaller sub-problems, one or more of which are simpler versions of

More information

Background. From my PhD (2009): Verified Lisp interpreter in ARM, x86 and PowerPC machine code

Background. From my PhD (2009): Verified Lisp interpreter in ARM, x86 and PowerPC machine code Certification of high-level and low-level programs, IHP, Paris, 2014 CakeML A verified implementation of ML Ramana Kumar Magnus Myreen Michael Norrish Scott Owens Background From my PhD (2009): Verified

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Statically vs. Dynamically typed languages

More information

Defining Languages GMU

Defining Languages GMU Defining Languages CS463 @ GMU How do we discuss languages? We might focus on these qualities: readability: how well does a language explicitly and clearly describe its purpose? writability: how expressive

More information

Portable Software Fault Isolation

Portable Software Fault Isolation Portable Software Fault Isolation Joshua A. Kroll Computer Science Department Princeton University Princeton, NJ kroll@cs.princeton.edu Gordon Stewart Computer Science Department Princeton University Princeton,

More information

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242 Spring 2013 Foundations Yu Zhang Acknowledgement: modified from Stanford CS242 https://courseware.stanford.edu/pg/courses/317431/ Course web site: http://staff.ustc.edu.cn/~yuzhang/fpl Reading Concepts

More information

CSC313 High Integrity Systems/CSCM13 Critical Systems. CSC313/CSCM13 Chapter 2 1/ 221

CSC313 High Integrity Systems/CSCM13 Critical Systems. CSC313/CSCM13 Chapter 2 1/ 221 CSC313 High Integrity Systems/CSCM13 Critical Systems CSC313/CSCM13 Chapter 2 1/ 221 CSC313 High Integrity Systems/ CSCM13 Critical Systems Course Notes Chapter 2: SPARK Ada Sect. 2 (f) Anton Setzer Dept.

More information

Proving Properties on Programs From the Coq Tutorial at ITP 2015

Proving Properties on Programs From the Coq Tutorial at ITP 2015 Proving Properties on Programs From the Coq Tutorial at ITP 2015 Reynald Affeldt August 29, 2015 Hoare logic is a proof system to verify imperative programs. It consists of a language of Hoare triples

More information

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University CS558 Programming Languages Winter 2018 Lecture 4a Andrew Tolmach Portland State University 1994-2018 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

More information

JML Class Specifications The Java Modeling Language (Part 2) A Java Class

JML Class Specifications The Java Modeling Language (Part 2) A Java Class JML Class Specifications The Java Modeling Language (Part 2) Wolfgang Schreiner Wolfgang.Schreiner@risc.jku.at Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria

More information

The Substitution Model

The Substitution Model The Substitution Model Prof. Clarkson Fall 2017 Today s music: Substitute by The Who Review Previously in 3110: simple interpreter for expression language abstract syntax tree (AST) evaluation based on

More information

Building Better and Safer Programs Using SPARK and Ada. William Wong 23 March 2019

Building Better and Safer Programs Using SPARK and Ada. William Wong 23 March 2019 Building Better and Safer Programs Using SPARK and Ada William Wong 23 March 2019 Intent of This Presentation - Highlight Ada and SPARK programming features Provide a general overview of major features

More information

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context Types 1 / 15 Outline Introduction Concepts and terminology The case for static typing Implementing a static type system Basic typing relations Adding context 2 / 15 Types and type errors Type: a set of

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages 1 / 26 CSE 307: Principles of Programming Languages Names, Scopes, and Bindings R. Sekar 2 / 26 Topics Bindings 1. Bindings Bindings: Names and Attributes Names are a fundamental abstraction in languages

More information

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules. Outline Type Checking General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time

More information

Œuf: Minimizing the Coq Extraction TCB

Œuf: Minimizing the Coq Extraction TCB Œuf: Minimizing the Coq Extraction TCB Eric Mullen University of Washington, USA USA Abstract Zachary Tatlock University of Washington, USA USA Verifying systems by implementing them in the programming

More information

Green Hills Software, Inc.

Green Hills Software, Inc. Green Hills Software, Inc. A Safe Tasking Approach to Ada95 Jim Gleason Engineering Manager Ada Products 5.0-1 Overview Multiple approaches to safe tasking with Ada95 No Tasking - SPARK Ada95 Restricted

More information

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages Lecture 08 Control Semantics & Continuations Semantics of Control Flow Sequencers: commands that cause control transfers:! goto! return! exit! break! continue! resultis

More information

Ada 2012, SPARK 2014, and Combining Proof and Test!

Ada 2012, SPARK 2014, and Combining Proof and Test! Presentation cover page EU Ada 2012, SPARK 2014, and Combining Proof and Test! Tucker Taft AdaCore Inc Languages and Tools for High Integrity Bergen, Norway February, 2014 www.adacore.com Cost of testing

More information

Intermediate Representations & Symbol Tables

Intermediate Representations & Symbol Tables Intermediate Representations & Symbol Tables Copyright 2014, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission

More information

The Java Modeling Language (Part 2)

The Java Modeling Language (Part 2) The Java Modeling Language (Part 2) Wolfgang Schreiner Wolfgang.Schreiner@risc.jku.at Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria http://www.risc.jku.at

More information