]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/varasm.c
Correct a function pre/postcondition [PR102403].
[thirdparty/gcc.git] / gcc / varasm.c
index 97c1e6fff254fee778b0281a5642756e3819924e..2d261b353bf9318e0478f61b6ca8a1bdbdef2d1d 100644 (file)
@@ -792,7 +792,7 @@ default_function_rodata_section (tree decl, bool relocatable)
       /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo or
         .gnu.linkonce.d.rel.ro.local.foo if the jump table is relocatable.  */
       else if (DECL_COMDAT_GROUP (decl)
-              && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
+              && startswith (name, ".gnu.linkonce.t."))
        {
          size_t len;
          char *rname;
@@ -817,7 +817,7 @@ default_function_rodata_section (tree decl, bool relocatable)
        }
       /* For .text.foo we want to use .rodata.foo.  */
       else if (flag_function_sections && flag_data_sections
-              && strncmp (name, ".text.", 6) == 0)
+              && startswith (name, ".text."))
        {
          size_t len = strlen (name) + 1;
          char *rname = (char *) alloca (len + strlen (sname) - 5);
@@ -2509,7 +2509,7 @@ incorporeal_function_p (tree decl)
       name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
       /* Atomic or sync builtins which have survived this far will be
         resolved externally and therefore are not incorporeal.  */
-      if (strncmp (name, "__builtin_", 10) == 0)
+      if (startswith (name, "__builtin_"))
        return true;
     }
   return false;
@@ -5531,14 +5531,20 @@ output_constructor_regular_field (oc_local_state *local)
          && (!TYPE_DOMAIN (TREE_TYPE (local->field))
              || !TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field)))))
        {
-         fieldsize = array_size_for_constructor (local->val);
+         unsigned HOST_WIDE_INT fldsize
+           = array_size_for_constructor (local->val);
+         fieldsize = int_size_in_bytes (TREE_TYPE (local->val));
+         /* In most cases fieldsize == fldsize as the size of the initializer
+            determines how many elements the flexible array member has.  For
+            C++ fldsize can be smaller though, if the last or several last or
+            all initializers of the flexible array member have side-effects
+            and the FE splits them into dynamic initialization.  */
+         gcc_checking_assert (fieldsize >= fldsize);
          /* Given a non-empty initialization, this field had better
             be last.  Given a flexible array member, the next field
             on the chain is a TYPE_DECL of the enclosing struct.  */
          const_tree next = DECL_CHAIN (local->field);
          gcc_assert (!fieldsize || !next || TREE_CODE (next) != FIELD_DECL);
-         tree size = TYPE_SIZE_UNIT (TREE_TYPE (local->val));
-         gcc_checking_assert (compare_tree_int (size, fieldsize) == 0);
        }
       else
        fieldsize = tree_to_uhwi (DECL_SIZE_UNIT (local->field));
@@ -6737,22 +6743,22 @@ default_section_type_flags (tree decl, const char *name, int reloc)
     flags |= SECTION_TLS | SECTION_WRITE;
 
   if (strcmp (name, ".bss") == 0
-      || strncmp (name, ".bss.", 5) == 0
-      || strncmp (name, ".gnu.linkonce.b.", 16) == 0
+      || startswith (name, ".bss.")
+      || startswith (name, ".gnu.linkonce.b.")
       || strcmp (name, ".persistent.bss") == 0
       || strcmp (name, ".sbss") == 0
-      || strncmp (name, ".sbss.", 6) == 0
-      || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
+      || startswith (name, ".sbss.")
+      || startswith (name, ".gnu.linkonce.sb."))
     flags |= SECTION_BSS;
 
   if (strcmp (name, ".tdata") == 0
-      || strncmp (name, ".tdata.", 7) == 0
-      || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
+      || startswith (name, ".tdata.")
+      || startswith (name, ".gnu.linkonce.td."))
     flags |= SECTION_TLS;
 
   if (strcmp (name, ".tbss") == 0
-      || strncmp (name, ".tbss.", 6) == 0
-      || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
+      || startswith (name, ".tbss.")
+      || startswith (name, ".gnu.linkonce.tb."))
     flags |= SECTION_TLS | SECTION_BSS;
 
   if (strcmp (name, ".noinit") == 0)