4825 – Regression(1.057, 2.040) "Error: non-constant expression" with -inline

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4825 - Regression(1.057, 2.040) "Error: non-constant expression" with -inline
Summary: Regression(1.057, 2.040) "Error: non-constant expression" with -inline
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 regression
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
Reported: 2010年09月05日 15:42 UTC by nfxjfg
Modified: 2015年06月09日 05:11 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 nfxjfg 2010年09月05日 15:42:44 UTC
This only happens with -inline. It worked on dmd 1.055, but fails on dmd 1.057, 1.061, 1.062 and 1.063.
//fails with dmd -c -inline test.d
int a() {
 int r;
 return r; //Error: non-constant expression r
}
int b() {
 return a();
}
void c() {
 void d() {
 auto e = b();
 }
 const int f = b();
}
Comment 1 nfxjfg 2010年09月05日 15:46:57 UTC
I have to add that this bug triggers even when the "const int..." line on function c is in a different function in a different module. This makes it a very non-obvious bug, where you have no idea what is happening.
Comment 2 Don 2010年09月09日 14:09:58 UTC
Replace 'const' with 'static const' and this fails on D2.040 and later, but passed on 2.039 and earlier.
Comment 3 Don 2010年09月27日 13:26:04 UTC
This was caused by the improvements to CommaExp::interpret, making things like (int x=3, x); into an lvalue, which allows struct constructors to work in CTFE.
But inlining can also create peculiar comma expressions. We need to make sure that non-ref returns return rvalues, not lvalues.
PATCH interpret.c, ReturnStatement::interpret(), line 566.
--- old ----
#if LOG
 Expression *e = exp->interpret(istate);
 printf("e = %p\n", e);
 return e;
#else
 return exp->interpret(istate);
#endif
--- new ---
 Expression *e = exp->interpret(istate);
 if (e == EXP_CANT_INTERPRET)
 return e;
 // Convert lvalues into rvalues
 if (e->op == TOKvar)
 e = e->interpret(istate);
 return e;
Comment 4 Walter Bright 2010年10月08日 13:11:12 UTC
http://www.dsource.org/projects/dmd/changeset/708 


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