This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Code generation problem in gcc 2.95.x with -g


Hi,
if I compile the code below, with g++ -c -g a.C I get a segmentation
fault in the access to my_index_table[index] in line 15. Unfortunately
this only happens within my application. If I try to reproduce the
problem in a small testbed, no problem occurs. The problem is, that if
the "inline" is present in the function definition, an my_index_table is
relocated incorrectly. If I watch it in the debugger, the
my_index_table's address in the load instruction differs from what
"print &my_index_table" says. The problem occurs both on Linux/Intel as
on Solaris/Sparc. If the "inline" in line 11 is omitted, everything
works fine. I hope (but am not sure) that I provided enough debugging
info. Feel free to contact me if you need any more info. The problem
occurs both with gcc 2.95.2 and 2.95.3. I haven't tried gcc 3 yet.

Thanks

Dominik


#include <cstdio>
#include <iostream>
using namespace std;

#define TABLE_INCREMENT  4096
extern char     line[];
extern bool ReadLine(istream& f);
extern "C" void *malloc(unsigned long);
static unsigned long*   my_index_table;            // Index translation
table
#ifndef PROBLEM
inline
#endif
unsigned long LookupIndex(unsigned index)
{
    return my_index_table[index];
}

bool BddReadBdds(istream& f, unsigned number, unsigned long var_set,
                 unsigned long* bdd_array, unsigned* count)
{
    unsigned i = 200;
    my_index_table = (unsigned long*) malloc(i * sizeof (unsigned
long));
    for (;;)
    {
        if (ReadLine(f))
        {
            return true;
        }
        unsigned node;
        unsigned index;
        unsigned edge_0;
        unsigned edge_1;
        if (   sscanf(line, "%u %u %u %u", &node, &index, &edge_0,
&edge_1)
            != 4)
        {
            return true;
        }
        LookupIndex(index);
    }
#ifdef __GNUC__
    return true;        // never executed, keeps GNU C++ compiler silent
#endif
}


-- 
Dominik Strasser	| Phone:  +49 89 636-43691
SIEMENS AG		| Fax:    +49 89 636-42284
CT SE 4			| E-Mail:Dominik.Strasser@mchp.siemens.de
Otto-Hahn-Ring 6	|
D-81739 Muenchen	| Room: 53-263


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]