[haiku-development] hrev45320: Yet another non-obvious effect of -ftree-vrp "optimization"

  • From: "Siarzhuk Zharski" <zharik@xxxxxx>
  • To: "Haiku Development" <haiku-development@xxxxxxxxxxxxx>
  • Date: Thu, 14 Mar 2013 14:12:02 +0100 (CET)

Dear Colleagues,

during last week I have observed that my gcc4 hybrid builds of Haiku cannot 
start the application server. The app server has just failed into gdb and left 
me no other option as pressing the Reboot key.

The backtrace of this fail was following:
        strlen + 0x33
        strdup + 0x19
        Desktop::Desktop(unsigned int, char const*) + 0x55
        AppServer::_CreateDesktop(unsigned int, char const*) + 0x48
        AppServer::_DispatchMessage(long, BPrivate::LinkReceiver&) + 0x170
        MessageLooper::_MessageLooper() + 0x26
        MessageLooper::_message_thread(void*) + 0xc
        AppServer::RunLooper() + 0x2e
        main + 0x59
        _start + 0x4e
        runtime_loader + 0xde

Corresponding code snippet:
    407 Desktop::Desktop(uid_t userID, const char* targetScreen)
    408         :
    409         MessageLooper("desktop"),
    410 
    411         fUserID(userID),
    412         fTargetScreen(strdup(targetScreen)),
    413         fSettings(NULL),

If you check our implementation of strdup() you see the following:

     17         // unlike the standard strdup() function, the BeOS 
implementation
     18         // handles NULL strings gracefully
     19         if (string == NULL)
     20                 return NULL;
     21 
     22         length = strlen(string) + 1;

in other words we should be on the safe side providing any valid string pointer 
without checking it for NULL, right? ;-) But not for Haiku GCC4 4.6.3 with 
-ftree-vrp otion.
The situation is looking like this check is removed for some non-obvious 
reasons. I suspect, that because NULL-input case is not specified in standard 
for strdup the compiler make some assumptions that strdup never be called with 
NULL parameter so this check is useless. Are there other ideas?

So, just for your information, Colleagues. ;-)

---
Kind Regards,
 S.Zharski

Other related posts: