avoid array bounds warnings from GCC 4.3

These warnings are due to GCC being smart enough to do interprocedural
constant propagation but not smart enough to avoid false positives in
all cases when looking for array bounds errors.
This commit is contained in:
Joel Dice 2009-10-17 18:09:54 -06:00
parent 7b0378c180
commit 963bfb3e3f

View File

@ -52,27 +52,28 @@ class MutexResource {
pthread_mutex_t* m; pthread_mutex_t* m;
}; };
const int InvalidSignal = -1;
const int VisitSignal = SIGUSR1; const int VisitSignal = SIGUSR1;
const unsigned VisitSignalIndex = 0;
const int SegFaultSignal = SIGSEGV; const int SegFaultSignal = SIGSEGV;
const unsigned SegFaultSignalIndex = 1;
const int InterruptSignal = SIGUSR2;
const unsigned InterruptSignalIndex = 2;
#ifdef __APPLE__ #ifdef __APPLE__
const int AltSegFaultSignal = SIGBUS; const int AltSegFaultSignal = SIGBUS;
#else const unsigned AltSegFaultSignalIndex = 3;
const int AltSegFaultSignal = InvalidSignal;
#endif #endif
const int InterruptSignal = SIGUSR2;
const unsigned VisitSignalIndex = 0; const int signals[] = { VisitSignal,
const unsigned SegFaultSignalIndex = 1; SegFaultSignal,
const unsigned AltSegFaultSignalIndex = 2; InterruptSignal
const unsigned InterruptSignalIndex = 3; #ifdef __APPLE__
, AltSegFaultSignal
#endif
};
class MySystem; class MySystem;
MySystem* system; MySystem* system;
const int signals[] = { VisitSignal, SegFaultSignal, AltSegFaultSignal,
InterruptSignal };
void void
handleSignal(int signal, siginfo_t* info, void* context); handleSignal(int signal, siginfo_t* info, void* context);
@ -558,8 +559,16 @@ class MySystem: public System {
} }
virtual void* tryAllocateExecutable(unsigned sizeInBytes) { virtual void* tryAllocateExecutable(unsigned sizeInBytes) {
void* p = mmap(0, sizeInBytes, PROT_EXEC | PROT_READ #if (! defined __APPLE__) && (defined __x86_64__)
| PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); // map to the lower 32 bits of memory when possible so as to avoid
// expensive relative jumps
const unsigned Extra = MAP_32BIT;
#else
const unsigned Extra = 0;
#endif
void* p = mmap(0, sizeInBytes, PROT_EXEC | PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON | Extra, -1, 0);
if (p == MAP_FAILED) { if (p == MAP_FAILED) {
return 0; return 0;
@ -608,11 +617,12 @@ class MySystem: public System {
virtual Status handleSegFault(SignalHandler* handler) { virtual Status handleSegFault(SignalHandler* handler) {
Status s = registerHandler(handler, SegFaultSignalIndex); Status s = registerHandler(handler, SegFaultSignalIndex);
if (s == 0 and AltSegFaultSignal != InvalidSignal) { #ifdef __APPLE__
if (s == 0) {
return registerHandler(handler, AltSegFaultSignalIndex); return registerHandler(handler, AltSegFaultSignalIndex);
} else {
return s;
} }
#endif
return s;
} }
virtual Status visit(System::Thread* st, System::Thread* sTarget, virtual Status visit(System::Thread* st, System::Thread* sTarget,
@ -820,13 +830,17 @@ handleSignal(int signal, siginfo_t* info, void* context)
} break; } break;
case SegFaultSignal: case SegFaultSignal:
case AltSegFaultSignal: { #ifdef __APPLE__
case AltSegFaultSignal:
if (signal == SegFaultSignal) { if (signal == SegFaultSignal) {
index = SegFaultSignalIndex; index = SegFaultSignalIndex;
} else { } else {
index = AltSegFaultSignalIndex; index = AltSegFaultSignalIndex;
} }
#else
index = SegFaultSignalIndex;
#endif
{
bool jump = system->handlers[index]->handleSignal bool jump = system->handlers[index]->handleSignal
(&ip, &base, &stack, &thread); (&ip, &base, &stack, &thread);