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/Cflow.mli | |
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/Cflow.mli')
-rw-r--r-- | cparser/Cflow.mli | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cparser/Cflow.mli b/cparser/Cflow.mli new file mode 100644 index 00000000..0de245ae --- /dev/null +++ b/cparser/Cflow.mli @@ -0,0 +1,24 @@ +(* *********************************************************************) +(* *) +(* The Compcert verified compiler *) +(* *) +(* Xavier Leroy, INRIA Paris-Rocquencourt *) +(* *) +(* Copyright Institut National de Recherche en Informatique et en *) +(* Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU General Public License as published by *) +(* the Free Software Foundation, either version 2 of the License, or *) +(* (at your option) any later version. This file is also distributed *) +(* under the terms of the INRIA Non-Commercial License Agreement. *) +(* *) +(* *********************************************************************) + +(* A simple control flow analysis for C statements. + Main purpose: emit warnings for _Noreturn functions. *) + +val function_returns: Env.t -> C.stmt -> bool * bool + (** Given a function body, returns two Booleans: + - the first says whether the function can return + - the second says whether the function can return by falling through + the end of its body. + Both are over-approximations. *) |