public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52067] New: force sibling call optimization
@ 2012-01-31 14:51 trashyankes at wp dot pl
2012-01-31 15:06 ` [Bug c++/52067] " rguenth at gcc dot gnu.org
2012-01-31 18:28 ` trashyankes at wp dot pl
0 siblings, 2 replies; 3+ messages in thread
From: trashyankes at wp dot pl @ 2012-01-31 14:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52067
Bug #: 52067
Summary: force sibling call optimization
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: trashyankes@wp.pl
code:
-------------------------------
-------------------------------
template<typename T>
int loop(int a) __attribute__((optimize(3)));
template<typename T>
int loop(int a)
{
T zz;
a -= 1;
if(a>0)
return loop<T>(a);
return a;
}
class pod
{
};
class not_pod
{
public:
not_pod() {}
};
void main()
{
loop<pod>(10); //use tail call
loop<not_pod>(10); //dont use tail call
}
-------------------------------
-------------------------------
I want use sibling call optimization and build around this my system.
But because C++ types can break this optimization without any waring, I could
get unexpected stack overflow.
It would be good if GCC have attribute that force function to use sibling call
and if that is impossible, break compilation with error.
something like this:
-------------------------------
-------------------------------
int foo(int a) __attribute__((siblingcall));
int foo(int a)
{
std::string b = "abc"; //Error, have destructor
{
std::string b2 = "zzz"; //OK, destroyed before any tail call
}
if(a==1)
return foo(a+1); //OK
if(a==2)
return 1+foo(a+1); //Error, except tail call
if(a==3)
{
int c = foo(a+1); //OK, normal call
return c;
}
return 0; //OK
}
-------------------------------
-------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-01-31 17:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-31 14:51 [Bug c++/52067] New: force sibling call optimization trashyankes at wp dot pl
2012-01-31 15:06 ` [Bug c++/52067] " rguenth at gcc dot gnu.org
2012-01-31 18:28 ` trashyankes at wp dot pl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).