VS2005 x64 VC++ codegen BUG

Discussion in 'Windows 64bit' started by Sergey Kashyrin, Mar 29, 2006.

  1. Hi,

    Here is the small program which is useless but can be compiled. Options are
    (x64 version !!!) :

    cl /c /Ox /Fatest /MD test.cpp

    You can look at assembler code and see
    mov rax, -7550501021876119059 ; 97373b532ad999edH
    ...
    add rcx, rax
    mov ebx, DWORD PTR [rsi+rcx*4+20]

    It's incorrect "fhash" function inlining and implementation.


    The first move looks like garbage and the last will fail (sigment violation)

    The code is correct if optimizer is OFF (i.e. /Od) but in this case compiler
    does not force "inline" for "fhash" function.

    32-bit mode is ok with all options but it did not "inline" fhash function.

    Regards,
    Sergey

    -------------------------- test.cpp -------------------------------------
    #include <string.h>

    const int NTBLHASH = 10007;

    struct LTABL {
    struct {
    char c1[6];
    char c2[6];
    } location;
    char key[16];
    struct {
    char num[3];
    char id[13];
    char rest[239];
    } record;
    char NONEXIST;
    };

    struct LTABLR {
    int next;
    LTABL tabl;
    };

    class TBLpool {
    public:
    int sz_mem;
    int size;
    int nfree;
    int nused;

    private:
    int ifree;
    int hash[NTBLHASH];
    LTABLR rec[1];

    int fhash(unsigned char * key) {
    __int64 h = *key++;
    for(int i = 0; i < 15; ++i) {
    h <<= 2;
    h ^= *key++;
    }
    int ret = (int)(h % NTBLHASH);
    return ret;
    }
    public:
    bool readTBL(LTABL * r) {
    int x = hash[fhash((unsigned char *) r->key)];
    while(x != 0) {
    if(0 == memcmp(r, &rec[x].tabl, 16 + sizeof(r->location)))
    {
    *r = rec[x].tabl;
    return true;
    }
    x = rec[x].next;
    }
    return false;
    }
    };

    TBLpool * TBL;

    bool TBLread(LTABL * r)
    {
    bool ret = TBL->readTBL(r);
    return ret;
    }
    Sergey Kashyrin, Mar 29, 2006
    #1
    1. Advertising

  2. Its best you post this to either or all of the following ngs:
    microsoft.public.vc.language
    microsoft.public.vc.alt
    microsoft.public.vc.mfc
    --
    Andre
    Extended64 | http://www.extended64.com
    Blog | http://www.extended64.com/blogs/andre
    http://spaces.msn.com/members/adacosta
    FAQ for MS AntiSpy http://www.geocities.com/marfer_mvp/FAQ_MSantispy.htm

    "Sergey Kashyrin" <> wrote in message
    news:...
    > Hi,
    >
    > Here is the small program which is useless but can be compiled. Options
    > are (x64 version !!!) :
    >
    > cl /c /Ox /Fatest /MD test.cpp
    >
    > You can look at assembler code and see
    > mov rax, -7550501021876119059 ; 97373b532ad999edH
    > ...
    > add rcx, rax
    > mov ebx, DWORD PTR [rsi+rcx*4+20]
    >
    > It's incorrect "fhash" function inlining and implementation.
    >
    >
    > The first move looks like garbage and the last will fail (sigment
    > violation)
    >
    > The code is correct if optimizer is OFF (i.e. /Od) but in this case
    > compiler does not force "inline" for "fhash" function.
    >
    > 32-bit mode is ok with all options but it did not "inline" fhash function.
    >
    > Regards,
    > Sergey
    >
    > -------------------------- test.cpp -------------------------------------
    > #include <string.h>
    >
    > const int NTBLHASH = 10007;
    >
    > struct LTABL {
    > struct {
    > char c1[6];
    > char c2[6];
    > } location;
    > char key[16];
    > struct {
    > char num[3];
    > char id[13];
    > char rest[239];
    > } record;
    > char NONEXIST;
    > };
    >
    > struct LTABLR {
    > int next;
    > LTABL tabl;
    > };
    >
    > class TBLpool {
    > public:
    > int sz_mem;
    > int size;
    > int nfree;
    > int nused;
    >
    > private:
    > int ifree;
    > int hash[NTBLHASH];
    > LTABLR rec[1];
    >
    > int fhash(unsigned char * key) {
    > __int64 h = *key++;
    > for(int i = 0; i < 15; ++i) {
    > h <<= 2;
    > h ^= *key++;
    > }
    > int ret = (int)(h % NTBLHASH);
    > return ret;
    > }
    > public:
    > bool readTBL(LTABL * r) {
    > int x = hash[fhash((unsigned char *) r->key)];
    > while(x != 0) {
    > if(0 == memcmp(r, &rec[x].tabl, 16 + sizeof(r->location)))
    > {
    > *r = rec[x].tabl;
    > return true;
    > }
    > x = rec[x].next;
    > }
    > return false;
    > }
    > };
    >
    > TBLpool * TBL;
    >
    > bool TBLread(LTABL * r)
    > {
    > bool ret = TBL->readTBL(r);
    > return ret;
    > }
    >
    >
    Andre Da Costa [Extended64], Mar 29, 2006
    #2
    1. Advertising

  3. Thanks, Andre.

    I've crossposted it to vc.language but I thought it's ok to post here
    because it's strict x64 issue.
    The intention is just to make MS guys aware of this bug, because it's not
    critical and I just don't want to go with "pay-per-incindent" support.

    And in this case the question is what this group for ?

    Regards,
    Sergey


    "Andre Da Costa [Extended64]" <> wrote in message
    news:...
    > Its best you post this to either or all of the following ngs:
    > microsoft.public.vc.language
    > microsoft.public.vc.alt
    > microsoft.public.vc.mfc
    > --
    > Andre
    > Extended64 | http://www.extended64.com
    > Blog | http://www.extended64.com/blogs/andre
    > http://spaces.msn.com/members/adacosta
    > FAQ for MS AntiSpy http://www.geocities.com/marfer_mvp/FAQ_MSantispy.htm
    >
    > "Sergey Kashyrin" <> wrote in message
    > news:...
    >> Hi,
    >>
    >> Here is the small program which is useless but can be compiled. Options
    >> are (x64 version !!!) :
    >>
    >> cl /c /Ox /Fatest /MD test.cpp
    >>
    >> You can look at assembler code and see
    >> mov rax, -7550501021876119059 ; 97373b532ad999edH
    >> ...
    >> add rcx, rax
    >> mov ebx, DWORD PTR [rsi+rcx*4+20]
    >>
    >> It's incorrect "fhash" function inlining and implementation.
    >>
    >>
    >> The first move looks like garbage and the last will fail (sigment
    >> violation)
    >>
    >> The code is correct if optimizer is OFF (i.e. /Od) but in this case
    >> compiler does not force "inline" for "fhash" function.
    >>
    >> 32-bit mode is ok with all options but it did not "inline" fhash
    >> function.
    >>
    >> Regards,
    >> Sergey
    >>
    >> -------------------------- test.cpp -------------------------------------
    >> #include <string.h>
    >>
    >> const int NTBLHASH = 10007;
    >>
    >> struct LTABL {
    >> struct {
    >> char c1[6];
    >> char c2[6];
    >> } location;
    >> char key[16];
    >> struct {
    >> char num[3];
    >> char id[13];
    >> char rest[239];
    >> } record;
    >> char NONEXIST;
    >> };
    >>
    >> struct LTABLR {
    >> int next;
    >> LTABL tabl;
    >> };
    >>
    >> class TBLpool {
    >> public:
    >> int sz_mem;
    >> int size;
    >> int nfree;
    >> int nused;
    >>
    >> private:
    >> int ifree;
    >> int hash[NTBLHASH];
    >> LTABLR rec[1];
    >>
    >> int fhash(unsigned char * key) {
    >> __int64 h = *key++;
    >> for(int i = 0; i < 15; ++i) {
    >> h <<= 2;
    >> h ^= *key++;
    >> }
    >> int ret = (int)(h % NTBLHASH);
    >> return ret;
    >> }
    >> public:
    >> bool readTBL(LTABL * r) {
    >> int x = hash[fhash((unsigned char *) r->key)];
    >> while(x != 0) {
    >> if(0 == memcmp(r, &rec[x].tabl, 16 + sizeof(r->location)))
    >> {
    >> *r = rec[x].tabl;
    >> return true;
    >> }
    >> x = rec[x].next;
    >> }
    >> return false;
    >> }
    >> };
    >>
    >> TBLpool * TBL;
    >>
    >> bool TBLread(LTABL * r)
    >> {
    >> bool ret = TBL->readTBL(r);
    >> return ret;
    >> }
    >>
    >>

    >
    >
    Sergey Kashyrin, Mar 29, 2006
    #3
  4. Well, its not really a programming group, but some knowledgeable persons in
    the developer languages do drop by here from time to time, so its not a
    problem. I just wanted to direct you to a better answer quicker. :)
    --
    --
    Andre
    Windows Connected | http://www.windowsconnected.com
    Extended64 | http://www.extended64.com
    Blog | http://www.extended64.com/blogs/andre
    http://spaces.msn.com/members/adacosta

    "Sergey Kashyrin" <> wrote in message
    news:...
    > Thanks, Andre.
    >
    > I've crossposted it to vc.language but I thought it's ok to post here
    > because it's strict x64 issue.
    > The intention is just to make MS guys aware of this bug, because it's not
    > critical and I just don't want to go with "pay-per-incindent" support.
    >
    > And in this case the question is what this group for ?
    >
    > Regards,
    > Sergey
    >
    >
    > "Andre Da Costa [Extended64]" <> wrote in message
    > news:...
    >> Its best you post this to either or all of the following ngs:
    >> microsoft.public.vc.language
    >> microsoft.public.vc.alt
    >> microsoft.public.vc.mfc
    >> --
    >> Andre
    >> Extended64 | http://www.extended64.com
    >> Blog | http://www.extended64.com/blogs/andre
    >> http://spaces.msn.com/members/adacosta
    >> FAQ for MS AntiSpy http://www.geocities.com/marfer_mvp/FAQ_MSantispy.htm
    >>
    >> "Sergey Kashyrin" <> wrote in message
    >> news:...
    >>> Hi,
    >>>
    >>> Here is the small program which is useless but can be compiled. Options
    >>> are (x64 version !!!) :
    >>>
    >>> cl /c /Ox /Fatest /MD test.cpp
    >>>
    >>> You can look at assembler code and see
    >>> mov rax, -7550501021876119059 ; 97373b532ad999edH
    >>> ...
    >>> add rcx, rax
    >>> mov ebx, DWORD PTR [rsi+rcx*4+20]
    >>>
    >>> It's incorrect "fhash" function inlining and implementation.
    >>>
    >>>
    >>> The first move looks like garbage and the last will fail (sigment
    >>> violation)
    >>>
    >>> The code is correct if optimizer is OFF (i.e. /Od) but in this case
    >>> compiler does not force "inline" for "fhash" function.
    >>>
    >>> 32-bit mode is ok with all options but it did not "inline" fhash
    >>> function.
    >>>
    >>> Regards,
    >>> Sergey
    >>>
    >>> --------------------------
    >>> test.cpp -------------------------------------
    >>> #include <string.h>
    >>>
    >>> const int NTBLHASH = 10007;
    >>>
    >>> struct LTABL {
    >>> struct {
    >>> char c1[6];
    >>> char c2[6];
    >>> } location;
    >>> char key[16];
    >>> struct {
    >>> char num[3];
    >>> char id[13];
    >>> char rest[239];
    >>> } record;
    >>> char NONEXIST;
    >>> };
    >>>
    >>> struct LTABLR {
    >>> int next;
    >>> LTABL tabl;
    >>> };
    >>>
    >>> class TBLpool {
    >>> public:
    >>> int sz_mem;
    >>> int size;
    >>> int nfree;
    >>> int nused;
    >>>
    >>> private:
    >>> int ifree;
    >>> int hash[NTBLHASH];
    >>> LTABLR rec[1];
    >>>
    >>> int fhash(unsigned char * key) {
    >>> __int64 h = *key++;
    >>> for(int i = 0; i < 15; ++i) {
    >>> h <<= 2;
    >>> h ^= *key++;
    >>> }
    >>> int ret = (int)(h % NTBLHASH);
    >>> return ret;
    >>> }
    >>> public:
    >>> bool readTBL(LTABL * r) {
    >>> int x = hash[fhash((unsigned char *) r->key)];
    >>> while(x != 0) {
    >>> if(0 == memcmp(r, &rec[x].tabl, 16 + sizeof(r->location)))
    >>> {
    >>> *r = rec[x].tabl;
    >>> return true;
    >>> }
    >>> x = rec[x].next;
    >>> }
    >>> return false;
    >>> }
    >>> };
    >>>
    >>> TBLpool * TBL;
    >>>
    >>> bool TBLread(LTABL * r)
    >>> {
    >>> bool ret = TBL->readTBL(r);
    >>> return ret;
    >>> }
    >>>
    >>>

    >>
    >>

    >
    >
    Andre Da Costa [Extended64], Mar 29, 2006
    #4
  5. Jochen Kalmbach [MVP], Mar 29, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Silverstrand

    Codegen Group Briza-97 Mid Tower ATX Case

    Silverstrand, Sep 27, 2005, in forum: Front Page News
    Replies:
    0
    Views:
    814
    Silverstrand
    Sep 27, 2005
  2. ead_no1
    Replies:
    0
    Views:
    1,483
    ead_no1
    Oct 21, 2006
  3. nitinnikam

    login control in vs2005

    nitinnikam, Oct 30, 2006, in forum: Software
    Replies:
    0
    Views:
    726
    nitinnikam
    Oct 30, 2006
  4. Anthony LaMark

    vs2005 64-bit platformsdk issue

    Anthony LaMark, Mar 23, 2006, in forum: Windows 64bit
    Replies:
    2
    Views:
    699
    Anthony LaMark
    Mar 23, 2006
  5. =?Utf-8?B?VmVjdG9ycng3?=

    Publishing VS2005 websites to Windows 2003R2 64bit OS

    =?Utf-8?B?VmVjdG9ycng3?=, Oct 2, 2007, in forum: Windows 64bit
    Replies:
    0
    Views:
    397
    =?Utf-8?B?VmVjdG9ycng3?=
    Oct 2, 2007
Loading...

Share This Page