From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17322 invoked by alias); 31 Jan 2012 14:11:05 -0000 Received: (qmail 17314 invoked by uid 22791); 31 Jan 2012 14:11:04 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 31 Jan 2012 14:10:52 +0000 From: "trashyankes at wp dot pl" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/52067] New: force sibling call optimization Date: Tue, 31 Jan 2012 14:51:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: trashyankes at wp dot pl X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-01/txt/msg03684.txt.bz2 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 int loop(int a) __attribute__((optimize(3))); template int loop(int a) { T zz; a -= 1; if(a>0) return loop(a); return a; } class pod { }; class not_pod { public: not_pod() {} }; void main() { loop(10); //use tail call loop(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 } ------------------------------- -------------------------------