www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3617] New: CTFE: wrong code for if(x) where x is int or smaller

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3617

           Summary: CTFE: wrong code for if(x) where x is int or smaller
           Product: D
           Version: 1.051
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: patch, wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: clugdbug yahoo.com.au


--- Comment #0 from Don <clugdbug yahoo.com.au> 2009-12-15 14:12:33 PST ---
Applies to while(), if(), assert(), etc.
Also happens if you have (say) uint u = 0x8000_0000; u<<=1;
-- since this sets the high bit of the value to 1.

TEST CASE:
----
int foo() {
   int u = cast(int)(0x1_0000_0000L);
   while (u) {
      if (u) { 
         assert(u!=0); 
        }
      assert(u!=0);
   }
   return 2;
}
static assert(foo()==2);
--------------------
PATCH: expression.c, around line 1575.
Need to convert the value to an appropriate sized integer.

int IntegerExp::isBool(int result)
{
+    toInteger();
    return result ? value != 0 : value == 0;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 15 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3617


Leandro Lucarella <llucax gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |llucax gmail.com


--- Comment #1 from Leandro Lucarella <llucax gmail.com> 2009-12-15 16:50:30
PST ---
http://www.dsource.org/projects/dmd/changeset/296

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 15 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3617


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2009-12-31
11:17:28 PST ---
Fixed dmd 1.054 and 2.038

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 31 2009