File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,8 @@ let useComputedGoto = ref false
8888
8989let useCaseRange = ref false
9090
91+ let addReturnOnNoreturnFallthrough = ref false
92+
9193module M = Machdep
9294(* Cil.initCil will set this to the current machine description.
9395 Makefile.cil generates the file src/machdep.ml,
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ type cstd = C90 | C99 | C11
5757val cstd_of_string : string -> cstd
5858val cstd : cstd ref
5959val gnu89inline : bool ref
60+ val addReturnOnNoreturnFallthrough : bool ref
6061
6162(* * This module defines the abstract syntax of CIL. It also provides utility
6263 functions for traversing the CIL data structures, and pretty-printing
Original file line number Diff line number Diff line change @@ -6437,8 +6437,14 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
64376437 ignore (warn " Body of function %s falls-through and cannot find an appropriate return value" ! currentFunctionFDEC.svar.vname);
64386438 None
64396439 in
6440- if not (hasAttribute " noreturn"
6441- ! currentFunctionFDEC.svar.vattr) then
6440+ if
6441+ (* By default, (addReturnOnNoreturnFallthrough = false), CIL does not add a return statement
6442+ in functions marked noreturn. However, unlike functions that are detected to never fall through,
6443+ the end of these functions can possibly be reached (perhaps in buggy program code), so with
6444+ the option set to true, always add the return statement. *)
6445+ ! addReturnOnNoreturnFallthrough
6446+ || not (hasAttribute " noreturn" ! currentFunctionFDEC.svar.vattr)
6447+ then
64426448 ! currentFunctionFDEC.sbody.bstmts < -
64436449 ! currentFunctionFDEC.sbody.bstmts
64446450 @ [mkStmt (Return (retval, endloc))]
You can’t perform that action at this time.
0 commit comments