]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cobol: Eliminate padding bytes from cbl_declarative_t. [PR119377]
authorRobert Dubner <rdubner@symas.com>
Sun, 11 May 2025 17:43:32 +0000 (13:43 -0400)
committerRobert Dubner <rdubner@symas.com>
Tue, 29 Jul 2025 16:06:38 +0000 (12:06 -0400)
By changing the type of a variable in the cbl_declarative_t structure from "bool"
to "uint32_t", three uninitialized padding bytes were turned into initialized
bytes.  This eliminates the valgrind error caused by those uninitialized values.

This is an interim fix, which expediently eliminates the valgrind problem. The
underlying design flaw, which involves turning a host-side C++ structure into
a run-time data block, is slated for complete replacement in the next few weeks.

libgcobol/ChangeLog:

PR cobol/119377
* common-defs.h: (struct cbl_declaratives_t): Change "bool global" to
"uint32_t global".

(cherry picked from commit d7d24f9cc55d5cf0a70a984d4e63e8a307710d9e)

libgcobol/common-defs.h

index 026f377e74b2915454fd94deeae7db844ac0152d..e3471c5ccc3db907f807d28d594f23ea741028ae 100644 (file)
@@ -458,11 +458,25 @@ struct cbl_enabled_exception_t {
 struct cbl_declarative_t {
   enum { files_max = 16 };
   size_t section; // implies program
-  bool global;
+  uint32_t global;  // See the note below
   ec_type_t type;
   uint32_t nfile, files[files_max];
   cbl_file_mode_t mode;
 
+/*  The ::global member originally was "bool global".  A bool, however, occupies
+    only one byte of storage.  The structure, in turn, is constructed on
+    four-byte boundaries for members, so there were three padding bytes between
+    the single byte of global and the ::type member.
+
+    When used to create a "blob", where the structure was treated as a stream
+    of bytes that were used to create a constructor for an array of bytes,
+    valgrind noticed that those three padding bytes were not initialized, and
+    generated the appropriate error message.  This made it hard to find other
+    problems.
+
+    Changing the declaration from "bool" to "uint32_t" seems to have eliminated
+    the valgrind error without affecting overall performance.  */
+
   cbl_declarative_t( cbl_file_mode_t mode = file_mode_none_e )
     : section(0), global(false)
     , type(ec_none_e)