Search

VS2008 C++ x64: buggy result in expression containing double and unsigned int64 by BenKaufmann1

Active

1
0
Sign in
to vote
Type: Bug
ID: 526921
Opened: 1/25/2010 7:30:50 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
#include <stdio.h>

typedef unsigned __int64 size_type;
typedef unsigned int uint32;

struct Foo {
    Foo() : strategy_(B), invert_(false) {}
    enum { A, B };
    int strategy_;
    bool invert_;
    bool test(uint32 a) {
        bool conflict = isTrue(a);
        if (strategy_ == A) {
            invert_ = conflict || strategy_ == B;
        }
        else if (conflict) {
            size_type capacity = 0;
            size_type minCap = 1;
            if (capacity > minCap) return true;
            minCap = minCap < 4 ? 4 : minCap;
            size_type cap = static_cast<size_type>(capacity * 1.5);
            if (cap > minCap) minCap = cap;
            CHECK_EQUAL(minCap, 4);
            return false;
        }
        return !conflict;
    }
    void CHECK_EQUAL(size_type n, size_type x) {
        if (n != x) throw n;
    }
    bool isTrue(uint32 x) {
        int bla;
        sscanf("1", "%d", &bla);
        return bla;
    }
};
int main() {
    Foo f;
    try {
        f.test(10864);
        printf("OK\n");
    }
    catch (size_type n) {
        printf("ERROR: n == %llu but should be 4!\n", n);
    }
}

Note: The first part of the generated code for the else if (conflict) branch is:

pxor        xmm0,xmm0
cvtsi2sd    xmm0,rdx
addsd     xmm0,mmword ptr [__real@43f0000000000000 (13FA42220h)]
mulsd     xmm0,mmword ptr [__real@3ff8000000000000 (13FA42218h)]
[...]

I think, there is a test/jns missing, i.e. the __real@43f0000000000000 should not be added
unconditionally.
Details (expand)

Product Language

English

Version

Visual Studio 2008 SP1

Operating System

Windows 7

Operating System Language

German

Steps to Reproduce

1. Create a default C++ Console Project
2. Copy the code above to a main.cpp file
3. Create x64 target
4. Enable Release configuration (Optimization O2)
5. Compile & run the program

Actual Results

ERROR: n == 9223372036854775808 but should be 4!

Expected Results

OK
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey.

 

Sign in to post a comment.
Posted by Microsoft on 7/12/2010 at 12:10 PM
This issue will be fixed in the next release of Visual Studio.

Thanks again for reporting it.
Posted by Microsoft on 1/26/2010 at 11:55 PM
Thank you for reporting the issue.
We were able to reproduce the issue you are seeing. We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 1/26/2010 at 7:11 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.