From 453b8d7693d3d0cc4eae6322d491030938bd4e8a Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 13 Nov 2026 12:32:41 +0100 Subject: [PATCH 1/4] Correction: Unpin the semicolon example for GNAT FSF 16 - Restore compilation and flow analysis with `--report=all` using the default toolchain. - Expect the termination diagnostic for the original loop. Co-Authored-By: Codex --- .../chapters/03_syntactic_guarantees.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst b/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst index 4d27b2d82..36651ac08 100644 --- a/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst +++ b/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst @@ -243,8 +243,8 @@ blocks of statements have explicit :ada:`begin` and :ada:`end` markers, which prevents mistakes that are possible in C. The SPARK (also Ada) version of the above C code is as follows: -.. code:: ada no_button gnat=12.2.0-1 gnatprove=12.1.0-1 project=Courses.SPARK_For_The_MISRA_C_Dev.Syntactic_Guarantees.Semicolon - :class: ada-compile, ada-prove-flow-report-all +.. code:: ada prove_flow_report_all_button compile_button project=Courses.SPARK_For_The_MISRA_C_Dev.Syntactic_Guarantees.Semicolon + :class: ada-expect-prove-error function Func return Integer; From f709f496a65ba95d892baf683aa57943feb4e44c Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 13 Nov 2026 12:32:51 +0100 Subject: [PATCH 2/4] Correction: Update the abstract-state example for GNAT FSF 16 - Qualify the comparison with `Element_Array` so GNAT and GNATprove report ordinary errors for using abstract state as a value. - Restore compilation and flow analysis with the default toolchain. Co-Authored-By: Codex --- .../intro-to-spark/chapters/04_State_Abstraction.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/content/courses/intro-to-spark/chapters/04_State_Abstraction.rst b/content/courses/intro-to-spark/chapters/04_State_Abstraction.rst index 592e2a974..986745e3f 100644 --- a/content/courses/intro-to-spark/chapters/04_State_Abstraction.rst +++ b/content/courses/intro-to-spark/chapters/04_State_Abstraction.rst @@ -1028,8 +1028,8 @@ Example #6 Let's consider yet another version of our abstract stack unit. -.. code:: ada no_button gnat=12.2.0-1 gnatprove=12.1.0-1 project=Courses.Intro_To_Spark.State_Abstraction.Example_06 - :class: ada-compile, ada-prove-flow, ada-expect-compile-error, ada-expect-prove-error +.. code:: ada compile_button prove_flow_button project=Courses.Intro_To_Spark.State_Abstraction.Example_06 + :class: ada-expect-compile-error, ada-expect-prove-error package Stack with Abstract_State => The_Stack @@ -1045,7 +1045,9 @@ Let's consider yet another version of our abstract stack unit. procedure Push (E : Element) with Post => not Is_Empty and - (if Is_Full'Old then The_Stack = The_Stack'Old else Peek = E); + (if Is_Full'Old then + Element_Array'(The_Stack) = Element_Array'(The_Stack)'Old + else Peek = E); function Peek return Element with Pre => not Is_Empty; function Is_Full return Boolean; From 310fb1857b3a1f708b03890381221588e7753dd9 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 13 Nov 2026 17:45:42 +0100 Subject: [PATCH 3/4] Documentation: Explain the semicolon proof result Add a short note after the semicolon example to explain the loop termination diagnostic and the `Loop_Variant` that resolves it. Validated with GNATprove 16: the original loop reports an unproved `Always_Terminates` check. Adding `pragma Loop_Variant (Decreases => 1)` proves the check. Co-Authored-By: Codex --- .../chapters/03_syntactic_guarantees.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst b/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst index 36651ac08..8b9655e44 100644 --- a/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst +++ b/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst @@ -259,6 +259,11 @@ above C code is as follows: return 0; end Func; +(Note that GNATprove cannot prove that the loop terminates. Adding +:ada:`pragma Loop_Variant (Decreases => 1)` in the :ada:`while True loop` +solves the problem.) + + Avoiding Complex Switch Statements ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 92f445e6507bf3d5b6cda07e4d35cddcaf6b904d Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 13 Nov 2026 18:18:07 +0100 Subject: [PATCH 4/4] Correction: Prove termination in semicolon example Add `pragma Loop_Variant (Decreases => 1)` to the loop and remove `ada-expect-prove-error` now that GNATprove proves termination. Explain in one sentence that a constant variant rules out a second iteration. Validated all 10 code blocks in the syntactic guarantees chapter with GNAT/GNATprove 16 and the course's 80-column limit. Co-Authored-By: Codex --- .../chapters/03_syntactic_guarantees.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst b/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst index 8b9655e44..a951ba6a1 100644 --- a/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst +++ b/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst @@ -244,7 +244,6 @@ prevents mistakes that are possible in C. The SPARK (also Ada) version of the above C code is as follows: .. code:: ada prove_flow_report_all_button compile_button project=Courses.SPARK_For_The_MISRA_C_Dev.Syntactic_Guarantees.Semicolon - :class: ada-expect-prove-error function Func return Integer; @@ -254,14 +253,15 @@ above C code is as follows: return 1; end if; while True loop + pragma Loop_Variant (Decreases => 1); return 0; end loop; return 0; end Func; -(Note that GNATprove cannot prove that the loop terminates. Adding -:ada:`pragma Loop_Variant (Decreases => 1)` in the :ada:`while True loop` -solves the problem.) +Note that the :ada:`Loop_Variant` pragma allows GNATprove to prove that the +loop terminates, as it requires its value to decrease between iterations, +which rules out a second iteration for the constant value :ada:`1`. Avoiding Complex Switch Statements