GNU C - maybe related to my bugreport 21513 but different.

Error:
src/aie_sql_meta.c: In Funktion aie_sql_meta_create_index:
src/aie_sql_meta.c:258: Warnung: tableid koennte in dieser Funktion
uninitialisiert verwendet werden
src/aie_sql_meta.c:259: Warnung: index_typ koennte in dieser Funktion
uninitialisiert verwendet werden
make: *** [obj/aie_sql_meta.o] Fehler 1

       int tableid;
       int index_typ;
could be unitilized in this function. It can but if not it's not used.
Difference to GCC 3.4.3. It is set but within another function. The function
itself resides in the same sourcefile so imo gcc would be able to figure out
that they are either initilized or not used. Especially when compiled with the
compiler switch -funit-at-a-time . btw if the initialisation would be in another
C sourcefile then the warning is ok imo because the compiler cannot know the
content - as tody - of two sourcefiles at the same time.

The function is to create a SQL Index out of a predefined structure. The two
variables are set within the function aie_sql_meta_get_index_def_from_id - see
below. 

The function it is as follows:

bool aie_sql_meta_create_index(int indexid, struct aie_sql_meta_db
                                                   *aie_sql_meta_db)
{
   bool rc = true;
   const char *index_name = aie_sql_meta_get_index_name_from_id(indexid, 
                                                            aie_sql_meta_db); 
    if (__builtin_expect((index_name != NULL),true))
    {
       unsigned int size_index_def = 0;
       int tableid;
       int index_typ;
       struct aie_sql_index_def *index_def =
            aie_sql_meta_get_index_def_from_id(indexid, &tableid, &index_typ,
                                               &size_index_def,
                                               aie_sql_meta_db); 
       if (__builtin_expect(((index_def == NULL) ||
                             (size_index_def <= 0) ||
                             (tableid <= 0)),false))
       {
          sys_log("%s(%d):Fehler Meta SQL Table Def Create index "
                                     "IndexID[%d] index [%s] TableID[%d]!", 
                                                                  __FILE__,
                                                                  __LINE__,
                                                                  indexid,
                                                                  index_name,
                                                                  tableid);
          rc = false;
       }
       else
       {
          const char *table_name = aie_sql_meta_get_table_name_from_id(tableid, 
                                                              aie_sql_meta_db); 
          if (__builtin_expect((table_name != NULL),true))
          {
             if (__builtin_expect(
                   (!aie_sql_create_index(aie_sql_meta_db->aie_sql_data,
                                          table_name, 
                                          index_name, 
                                          index_typ,
                                          true,
                                           index_def,
                                           size_index_def)),false))
             {
                sys_log("%s(%d):Fehler Meta SQL Create index "
                        "IndexID[%d] index [%s] Tableid[%d]!", 
                                                                  __FILE__,
                                                                  __LINE__,
                                                                  indexid,
                                                                  index_name,
                                                                  tableid);
                rc = false;
             }
          }
          else
          {
             sys_log("%s(%d):Fehler Meta SQL Create index Table nicht gefunden "
                             "IndexID[%d] index [%s] Tableid[%d]!", 
                                                                  __FILE__,
                                                                  __LINE__,
                                                                  indexid,
                                                                  index_name,
                                                                  tableid);
             rc = false;
          }
       }
    }
    else
    {
       sys_log("%s(%d): Create Table ID[%d] Table ID nicht gefunden!",
                                                                  __FILE__,
                                                                  __LINE__,
                                                                  indexid);
       rc = false;
    }
    return(rc);
}


struct aie_sql_index_def *aie_sql_meta_get_index_def_from_id(int indexid,
                                                         int *tableid, 
                                                         int *index_typ, 
                                                unsigned int *size_index_def, 
                                                struct aie_sql_meta_db 
                                                       *aie_sql_meta_db)
{
   struct aie_sql_index_def *aie_index_def = NULL;
   if (__builtin_expect((aie_sql_meta_db != NULL), true))
   {
      struct aie_sql_db *sql_db = aie_sql_meta_db->sql_db;
      unsigned int size_sql_db = aie_sql_meta_db->size_sql_db;
      if (__builtin_expect(((sql_db != NULL)  && (size_sql_db > 0)), true))
      {
         register unsigned int z = 0;
         for(z = 0;z < size_sql_db;z++)
         {
            struct aie_sql_index *tbl_index;
            if (__builtin_expect(((tbl_index = sql_db->index) != NULL),true))
            {
                unsigned int size_index = sql_db->size_index;
                if (__builtin_expect((size_index > 0),true))
                {
                   register unsigned int y = 0;
                   for(y = 0; y < size_index; y++)
                   {
                      if (__builtin_expect((tbl_index->indexid == indexid), 
                                                                        false))
                      {
                         if (__builtin_expect((tableid != NULL),true))
                         {
                            *tableid = tbl_index->tableid;
                         }
                         if (__builtin_expect((index_typ != NULL),true))
                         {
                            *index_typ = tbl_index->index_typ;
                         }
                         if (__builtin_expect((size_index_def != NULL),true))
                         {
                            *size_index_def = tbl_index->size_index_def;
                         }
                         aie_index_def = tbl_index->index_def;
                         break;
                      }
                      tbl_index++;
                   }

                }
                else
                {
                  sys_log("%s(%d): Warnung DB %d Indizies == 0", __FILE__, 
                                                                 __LINE__,
                                                                 sql_db->dbid);
                }
            }
            else
            {
               //sys_log("%s(%d): Warnung DB %d keine Indizies!", __FILE__, 
                //                                                __LINE__,
                //                                              sql_db->dbid);
            }
            sql_db++;
         }
      }
      else
      {
         sys_log("%s(%d): Mata Date - Keine DB Info", __FILE__, __LINE__);
      }
   }
   else
   {
      sys_log("%s(%d): Mata Date Ptr == NULL!", __FILE__, __LINE__);
   }
   return(aie_index_def);
}

Solution: Waste a byte and maybe a CPU cycle and initilize it when defined.

-- 
           Summary: 4.0/4.1 Regression __builtin_expect
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alexander_herrmann at yahoo dot com dot au
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21531

Reply via email to