From 0ac4e3c6959cd90f86fcc608fa44606f35653697 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20B=C3=BChler?= <david.buhler@cea.fr>
Date: Mon, 11 Oct 2021 15:52:47 +0200
Subject: [PATCH] [kernel] Moves function onlyOnGccMsvc in Cabs2cil and do not
 export it.

Renames the function [allowed_machdep].
---
 src/kernel_internals/typing/cabs2cil.ml       | 20 +++++++++++++------
 src/kernel_services/ast_queries/cil.ml        |  6 ------
 src/kernel_services/ast_queries/cil.mli       |  7 -------
 .../value/domains/cvalue/cvalue_init.ml       |  3 +--
 .../oracle/array_zero_length.2.res.oracle     |  2 +-
 tests/value/oracle/empty_base.1.res.oracle    |  2 +-
 6 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/src/kernel_internals/typing/cabs2cil.ml b/src/kernel_internals/typing/cabs2cil.ml
index 52363c334d2..75665dec063 100644
--- a/src/kernel_internals/typing/cabs2cil.ml
+++ b/src/kernel_internals/typing/cabs2cil.ml
@@ -1349,12 +1349,20 @@ let canDropStatement (s: stmt) : bool =
   ignore (visitCilStmt vis s);
   !pRes
 
+let allowed_machdep machdep =
+  Format.asprintf
+    "only allowed for %s machdeps;@ see option -machdep or@ \
+     run '-machdep help' for the list of available machdeps"
+    machdep
+
 let fail_if_incompatible_sizeof ~ensure_complete op typ =
   if Cil.isFunctionType typ && Cil.theMachine.theMachine.sizeof_fun < 0 then
-    Kernel.error ~current:true "%s called on function %s" op (Cil.onlyOnGccMsvc false);
+    Kernel.error ~current:true "%s called on function %s" op
+      (allowed_machdep "GCC");
   let is_void = Cil.isVoidType typ in
   if is_void && Cil.theMachine.theMachine.sizeof_void < 0 then
-    Kernel.error ~current:true "%s on void type %s" op (Cil.onlyOnGccMsvc true);
+    Kernel.error ~current:true "%s on void type %s" op
+      (allowed_machdep "GCC/MSVC");
   if ensure_complete && not (Cil.isCompleteType typ) && not is_void then
     Kernel.error ~current:true
       "%s on incomplete type '%a'" op Cil_printer.pp_typ typ
@@ -3354,7 +3362,7 @@ let rec _pp_preInit fmt = function
 let empty_preinit() =
   if Cil.gccMode () || Cil.msvcMode () then
     CompoundPre (ref (-1), ref [| |])
-  else abort_context "empty initializers only allowed %s" (Cil.onlyOnGccMsvc true)
+  else abort_context "empty initializers %s" (allowed_machdep "GCC/MSVC")
 
 (* Set an initializer *)
 let rec setOneInit this o preinit =
@@ -5207,7 +5215,7 @@ and doType (ghost:bool) isFuncArg
              not (Cil.gccMode () || Cil.msvcMode ())
           then
             Kernel.error ~once:true ~current:true
-              "zero-length arrays %s" (Cil.onlyOnGccMsvc true);
+              "zero-length arrays %s" (allowed_machdep "GCC/MSVC");
           Some len'
       in
       let al' = doAttributes ghost al in
@@ -5473,7 +5481,7 @@ and makeCompType ghost (isstruct: bool)
           Kernel.error ~source
             "field `%s' declared with a type containing a flexible array \
              member %s."
-            n (Cil.onlyOnGccMsvc true)
+            n (allowed_machdep "GCC/MSVC")
       end
       else if not (Cil.isCompleteType ~allowZeroSizeArrays ftype)
       then begin
@@ -5617,7 +5625,7 @@ and makeCompType ghost (isstruct: bool)
     Kernel.error ~current:true ~once:true
       "empty %ss %s"
       (if comp.cstruct then "struct" else "union")
-      (Cil.onlyOnGccMsvc true);
+      (allowed_machdep "GCC/MSVC");
   List.iter check flds;
   if comp.cfields <> None then begin
     let old_fields = Option.get comp.cfields in
diff --git a/src/kernel_services/ast_queries/cil.ml b/src/kernel_services/ast_queries/cil.ml
index 9f2130864a1..e40b51a88db 100644
--- a/src/kernel_services/ast_queries/cil.ml
+++ b/src/kernel_services/ast_queries/cil.ml
@@ -2955,12 +2955,6 @@ let startsWith prefix s =
   let prefixLen = String.length prefix in
   String.length s >= prefixLen && String.sub s 0 prefixLen = prefix
 
-let onlyOnGccMsvc msvc =
-  Format.asprintf "only allowed for %s machdeps;@ \
-                   see option -machdep or@ \
-                   run '-machdep help' for the list of available machdeps"
-    (if msvc then "GCC/MSVC" else "GCC")
-
 let bytesSizeOfInt (ik: ikind): int =
   match ik with
   | IChar | ISChar | IUChar | IBool -> 1
diff --git a/src/kernel_services/ast_queries/cil.mli b/src/kernel_services/ast_queries/cil.mli
index 0bdc823d851..6b051a1e72e 100644
--- a/src/kernel_services/ast_queries/cil.mli
+++ b/src/kernel_services/ast_queries/cil.mli
@@ -2246,13 +2246,6 @@ val mapNoCopyList: ('a -> 'a list) -> 'a list -> 'a list
 (** sm: return true if the first is a prefix of the second string *)
 val startsWith: string -> string -> bool
 
-(** Append the "only allowed on GCC/MSVC machdeps" error message.
-    The bool parameter tells whether MSVC should be included in the message
-    (otherwise, print just GCC).
-    @since Frama-C+dev
-*)
-val onlyOnGccMsvc: bool -> string
-
 (* ************************************************************************* *)
 (** {2 An Interpreter for constructing CIL constructs} *)
 (* ************************************************************************* *)
diff --git a/src/plugins/value/domains/cvalue/cvalue_init.ml b/src/plugins/value/domains/cvalue/cvalue_init.ml
index 5a5a11d7d90..58725f9e485 100644
--- a/src/plugins/value/domains/cvalue/cvalue_init.ml
+++ b/src/plugins/value/domains/cvalue/cvalue_init.ml
@@ -102,10 +102,9 @@ let reject_empty_struct b offset typ =
     if ci.cfields = Some [] && not (Cil.acceptEmptyCompinfo ()) then
       Value_parameters.abort ~current:true
         "@[empty %ss@ are unsupported@ (type '%a',@ location %a%a)@ \
-         in C99 %s.@ Aborting.@]"
+         in C99 (only allowed on GCC/MSVC machdep).@ Aborting.@]"
         (if ci.cstruct then "struct" else "union")
         Printer.pp_typ typ Base.pretty b Printer.pp_offset offset
-        (Cil.onlyOnGccMsvc true)
   | _ -> ()
 
 
diff --git a/tests/value/oracle/array_zero_length.2.res.oracle b/tests/value/oracle/array_zero_length.2.res.oracle
index 5e6d5f9a5ed..d040ef54d2c 100644
--- a/tests/value/oracle/array_zero_length.2.res.oracle
+++ b/tests/value/oracle/array_zero_length.2.res.oracle
@@ -9,7 +9,7 @@
   declaration of array of 'zero-length arrays' ('char [0]`);
   zero-length arrays are not allowed in C99
 [kernel] tests/value/array_zero_length.i:13: User Error: 
-  empty initializers only allowed only allowed for GCC/MSVC machdeps; see option -machdep or
+  empty initializers only allowed for GCC/MSVC machdeps; see option -machdep or
   run '-machdep help' for the list of available machdeps
   11    char W[][0];
   12    
diff --git a/tests/value/oracle/empty_base.1.res.oracle b/tests/value/oracle/empty_base.1.res.oracle
index d1ff8c38bb4..71459a15f4f 100644
--- a/tests/value/oracle/empty_base.1.res.oracle
+++ b/tests/value/oracle/empty_base.1.res.oracle
@@ -6,7 +6,7 @@
   zero-length arrays only allowed for GCC/MSVC machdeps; see option -machdep or
   run '-machdep help' for the list of available machdeps
 [kernel] tests/value/empty_base.c:50: User Error: 
-  empty initializers only allowed only allowed for GCC/MSVC machdeps; see option -machdep or
+  empty initializers only allowed for GCC/MSVC machdeps; see option -machdep or
   run '-machdep help' for the list of available machdeps
   48    struct empty empty_array_of_empty[0];
   49    struct empty array_of_empty[1];
-- 
GitLab