Skip to content

Commit 15c6b55

Browse files
committed
Add example of translated goto function
Add an example C program and its equivalent goto-functions as produced by cbmc in the goto-programs folder documentation.
1 parent eef01a1 commit 15c6b55

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/goto-programs/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,49 @@ then it performs 'linking' of the temporary into a passed destination
524524
Details about linking of `::goto_modelt` instances can be found
525525
[here](\ref section-linking-goto-models).
526526

527+
\subsection subsection-goto-function-example Example goto-program
528+
529+
The following C program, in a file named `mult.c`:
530+
531+
```
532+
unsigned mult(unsigned a, unsigned b)
533+
{
534+
int acc, i;
535+
for (i = 0; i < b; i++)
536+
acc += a;
537+
return acc;
538+
}
539+
```
540+
541+
is translated by `cbmc --show-goto-functions mult.c` into:
542+
543+
```
544+
mult /* mult */
545+
// 0 file third.c line 2 function mult
546+
signed int acc;
547+
// 1 file third.c line 2 function mult
548+
signed int i;
549+
// 2 file third.c line 3 function mult
550+
i = 0;
551+
// 3 file third.c line 3 function mult
552+
1: IF !((unsigned int)i < b) THEN GOTO 2
553+
// 4 file third.c line 4 function mult
554+
acc = (signed int)((unsigned int)acc + a);
555+
// 5 file third.c line 3 function mult
556+
i = i + 1;
557+
// 6 file third.c line 3 function mult
558+
GOTO 1
559+
// 7 file third.c line 5 function mult
560+
2: mult#return_value = (unsigned int)acc;
561+
// 8 file third.c line 5 function mult
562+
dead i;
563+
// 9 file third.c line 5 function mult
564+
dead acc;
565+
// 10 file third.c line 6 function mult
566+
END_FUNCTION
567+
```
568+
569+
(The above result was produced using `cbmc version 5.11`)
527570

528571
\section section-linking-goto-models Linking Goto Models
529572

0 commit comments

Comments
 (0)