diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2017-02-07 09:57:45 +0100 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2017-02-07 09:57:45 +0100 |
commit | 5a7fc8637ae82d9aaf71c0053078a950ddee3b89 (patch) | |
tree | c68de6d885db1ec3814dc115c427c5960b91783a /cparser/Cutil.ml | |
parent | 6b0dbab6d1315ae3b0df26d034bce771f743af85 (diff) | |
download | compcert-kvx-5a7fc8637ae82d9aaf71c0053078a950ddee3b89.tar.gz compcert-kvx-5a7fc8637ae82d9aaf71c0053078a950ddee3b89.zip |
More precise warnings about function returns
This commit introduces a control-flow static analysis over C abstract syntax (file cparser/Cflow.ml) and uses it to
- warn for non-void functions that can return by falling through the body
- warn more precisely for _Noreturn functions that can return
- introduce the "return 0" in "main" functions less often (cosmetic).
For the control-flow analysis, the following conservative approximations are made:
- any "goto" label is reachable
- all cases of a "switch" statement are reachable as soon as the "switch" is reachable (i.e. the switch expression takes all values needed to reach every case)
- the boolean expressions in "if", "while", "do"-"while" and "for" can take true and false values, unless they are compile-time constants.
Diffstat (limited to 'cparser/Cutil.ml')
-rw-r--r-- | cparser/Cutil.ml | 21 |
1 files changed, 0 insertions, 21 deletions
diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml index 8a59c147..735dd99b 100644 --- a/cparser/Cutil.ml +++ b/cparser/Cutil.ml @@ -1183,24 +1183,3 @@ let rec subst_stmt phi s = List.map subst_asm_operand inputs, clob) } - -let contains_return s = - let rec aux s = - match s.sdesc with - | Sskip - | Sbreak - | Scontinue - | Sdo _ - | Sdecl _ - | Sasm _ - | Sgoto _ -> false - | Sif(_, s1, s2) - | Sseq(s1, s2) -> aux s1 || aux s2 - | Sswitch (_, s) - | Slabeled (_, s) - | Swhile (_, s) - | Sdowhile(s, _ ) -> aux s - | Sfor(s1, _ , s2, s3) -> aux s1 || aux s2 || aux s3 - | Sreturn _ -> true - | Sblock sl -> List.fold_left (fun acc s -> acc || aux s) false sl in - aux s |