Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 18, 2010 [Issue 3822] New: alloca() can return the same address inside a function | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=3822 Summary: alloca() can return the same address inside a function Product: D Version: 2.040 Platform: Other OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: druntime AssignedTo: sean@invisibleduck.org ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2010-02-18 11:17:11 PST --- import std.stdio: printf; import std.c.stdlib: alloca; void main() { const int n = 8; for (int i; i < 2; i++) printf("%p\n", alloca(n)); } It prints two times the same address, I don't know why, I think this can be wrong. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 18, 2010 [Issue 3822] alloca() can return the same address inside a function | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3822 BCS <shro8822@vandals.uidaho.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |shro8822@vandals.uidaho.edu --- Comment #1 from BCS <shro8822@vandals.uidaho.edu> 2010-02-18 12:03:35 PST --- I've never used alloca so I'm not sure, so this is a guess: alloca does stack allocation and the body of the for statement forms a scope on the stack (this in this case contains no named variables). I'm guessing that when that scope is exited, the allocation automatically gets deallocated. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 18, 2010 [Issue 3822] alloca() can return the same address inside a function | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3822 --- Comment #2 from bearophile_hugs@eml.cc 2010-02-18 12:32:38 PST --- (In reply to comment #1) > I've never used alloca so I'm not sure, so this is a guess: > > alloca does stack allocation and the body of the for statement forms a scope on the stack (this in this case contains no named variables). I'm guessing that when that scope is exited, the allocation automatically gets deallocated. You can be right, thank you. Then it's very good for Phobos docs to say that alloca is relative to a scope and not to a function. The description of alloca() that I have seen says: The alloca() function allocates space in the stack frame of the caller, and returns a pointer to the allocated block. This temporary space is automatically freed when the function from which alloca() is called returns. While if you are right D alloca frees space when the scope of alloca ends and not when the function ends. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 07, 2010 [Issue 3822] alloca() can return the same address inside a function | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3822 --- Comment #3 from bearophile_hugs@eml.cc 2010-06-07 04:04:04 PDT --- Maybe the alloca() used by dmd frees memory as soon as the current scope is left, instead of deferring all deallocation until function exit. See: http://compilers.iecc.com/comparch/article/91-12-079 D documentation has to explain how exactly its alloca() works. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 07, 2010 [Issue 3822] Memory allocated with alloca() is freed at end of scope instead at end of function | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3822 nfxjfg@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |wrong-code CC| |nfxjfg@gmail.com Summary|alloca() can return the |Memory allocated with |same address inside a |alloca() is freed at end of |function |scope instead at end of | |function --- Comment #4 from nfxjfg@gmail.com 2010-06-07 04:17:53 PDT --- C code that compiles in D without modification should work exactly as it does in C. This means this is a rather bad code gen bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 26, 2010 [Issue 3822] Memory allocated with alloca() is freed at end of scope instead at end of function | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3822 nfxjfg@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |critical --- Comment #5 from nfxjfg@gmail.com 2010-06-26 14:40:47 PDT --- There's D code in druntime that assumes memory allocated by alloca() is valid until the end of the function: http://dsource.org/projects/druntime/browser/trunk/src/rt/adi.d#L242 Maybe the codegen for alloca() within loops is broken, or something. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 11, 2012 [Issue 3822] Memory allocated with alloca() is freed at end of scope instead at end of function | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3822 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yebblies@gmail.com Platform|Other |All Version|2.040 |D1 & D2 AssignedTo|nobody@puremagic.com |yebblies@gmail.com OS/Version|Windows |All --- Comment #6 from yebblies <yebblies@gmail.com> 2012-02-11 17:08:28 EST --- The issue here is that n is a compile-time constant, so the call to alloca is optimized away completely, and always reserving the extra space. This optimization is not valid if the call to alloca might be repeated. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 11, 2012 [Issue 3822] Invalid optimization of alloca called with constant size | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3822 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull Summary|Memory allocated with |Invalid optimization of |alloca() is freed at end of |alloca called with constant |scope instead at end of |size |function | --- Comment #7 from yebblies <yebblies@gmail.com> 2012-02-11 17:29:13 EST --- https://github.com/D-Programming-Language/dmd/pull/707 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 11, 2012 [Issue 3822] Invalid optimization of alloca called with constant size | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3822 --- Comment #8 from bearophile_hugs@eml.cc 2012-02-11 04:12:35 PST --- (In reply to comment #7) > https://github.com/D-Programming-Language/dmd/pull/707 Thank you for your patch, yebblies! -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 11, 2012 [Issue 3822] Invalid optimization of alloca called with constant size | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3822 --- Comment #9 from yebblies <yebblies@gmail.com> 2012-02-11 23:36:09 EST --- (In reply to comment #8) > Thank you for your patch, yebblies! You're welcome. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation