3617 – CTFE: wrong code for if(x) where x is int or smaller

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3617 - CTFE: wrong code for if(x) where x is int or smaller
Summary: CTFE: wrong code for if(x) where x is int or smaller
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
Reported: 2009年12月15日 14:12 UTC by Don
Modified: 2014年04月18日 09:12 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2009年12月15日 14:12:33 UTC
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;
}
Comment 1 Leandro Lucarella 2009年12月15日 16:50:30 UTC
http://www.dsource.org/projects/dmd/changeset/296 
Comment 2 Walter Bright 2009年12月31日 11:17:28 UTC
Fixed dmd 1.054 and 2.038


AltStyle によって変換されたページ (->オリジナル) /