From patchwork Thu Jun 30 02:14:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lawrence Crowl X-Patchwork-Id: 102693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 0D1A7B6F5C for ; Thu, 30 Jun 2011 12:15:08 +1000 (EST) Received: (qmail 12385 invoked by alias); 30 Jun 2011 02:15:04 -0000 Received: (qmail 12311 invoked by uid 22791); 30 Jun 2011 02:15:02 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 30 Jun 2011 02:14:46 +0000 Received: from hpaq3.eem.corp.google.com (hpaq3.eem.corp.google.com [172.25.149.3]) by smtp-out.google.com with ESMTP id p5U2Ejgr011708; Wed, 29 Jun 2011 19:14:45 -0700 Received: from jade.mtv.corp.google.com (jade.mtv.corp.google.com [172.18.110.116]) by hpaq3.eem.corp.google.com with ESMTP id p5U2EhqN023428; Wed, 29 Jun 2011 19:14:43 -0700 Received: by jade.mtv.corp.google.com (Postfix, from userid 21482) id 8DE8922266F; Wed, 29 Jun 2011 19:14:42 -0700 (PDT) To: reply@codereview.appspotmail.com, dnovillo@google.com, gcc-patches@gcc.gnu.org Subject: [pph] Correct executable testing. Factor x1dynarray1. (issue4667050) Message-Id: <20110630021442.8DE8922266F@jade.mtv.corp.google.com> Date: Wed, 29 Jun 2011 19:14:42 -0700 (PDT) From: crowl@google.com (Lawrence Crowl) X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Fix dg-pph.exp to execute both normal and pph executable tests and to avoid false new/disappeared reports. Break x1dynarray1 into three levels of tests. Remove ICE failure in x1dynarray1. We now get bogus warnings, but we cannot seem to mark them with dg-bogus without also getting xfails. --- This patch is available for review at http://codereview.appspot.com/4667050 Index: gcc/testsuite/ChangeLog.pph 2011-06-29 Lawrence Crowl * lib/dg-pph.exp: Run pph executables when normal executables run. Change (assembly identical) and (assembly mismatch) to (assembly comparison) to avoid false "disappeared" test reports. * g++.dg/pph/x1dynarray1.h: Simplfy test to avoid more complicated language features: namespaces, exceptions, placement new, and explicit destructor calls. * g++.dg/pph/x1dynarray1.cc: Strip out namespaces. * g++.dg/pph/x1dynarray0.cc: New. An even simpler use. * g++.dg/pph/x1dynarray2.h: New. Add back the full test. * g++.dg/pph/x1dynarray2.cc: New. Add back the full test. Index: gcc/testsuite/lib/dg-pph.exp =================================================================== --- gcc/testsuite/lib/dg-pph.exp (revision 175673) +++ gcc/testsuite/lib/dg-pph.exp (working copy) @@ -74,29 +74,35 @@ proc dg-pph-pos { subdir test options ma set dg-do-what-default compile dg-test -keep-output $test "$options -I." "" - # Quit if it did not compile successfully. - if { ![file_on_host exists "$bname.s"] } { - # All regular compiles should pass. - fail "$nshort $options (regular assembly missing)" - return + # Executables do not generate assembly. + if { ![string compare "dg-do-what" "run"] } { + # Not executable, so quit if it did not compile successfully. + if { ![file_on_host exists "$bname.s"] } { + fail "$nshort $options (regular assembly missing)" + return + } + # Rename the .s file into .s-pph to compare it after the second build. + remote_upload host "$bname.s" "$bname.s-pph" + remote_download host "$bname.s-pph" + file_on_host delete "$bname.s" } - # Rename the .s file into .s-pph to compare it after the second build. - remote_upload host "$bname.s" "$bname.s-pph" - remote_download host "$bname.s-pph" - file_on_host delete "$bname.s" - verbose -log "" # Compile a second time using the pph files. dg-test -keep-output $test "$options $mapflag -I." "" + # Executables do not generate assembly, + if { [string compare "dg-do-what" "run"] } { + # and so we are done testing. + return + } + # Quit if it did not compile successfully. if { ![file_on_host exists "$bname.s"] } { # Expect assembly to be missing when the compile is an - # expected fail or when this was an executable test. - if { ![string compare "dg-do-what" "run"] \ - && ![llength [grep $test "dg-xfail-if.*-fpph-map"]] } { + # expected fail. + if { ![llength [grep $test "dg-xfail-if.*-fpph-map"]] } { fail "$nshort $options (pph assembly missing)" } return @@ -117,17 +123,17 @@ proc dg-pph-pos { subdir test options ma fail "$nshort $options comparison failure" } elseif { $adiff == 1 } { if { $xdiff } { - xpass "$nshort $options (assembly identical)" + xpass "$nshort $options (assembly comparison)" } else { - pass "$nshort $options (assembly identical)" + pass "$nshort $options (assembly comparison)" } file_on_host delete "$bname.s-pph" file_on_host delete "$bname.s+pph" } else { if { $xdiff } { - xfail "$nshort $options (assembly mismatch)" + xfail "$nshort $options (assembly comparison)" } else { - fail "$nshort $options (assembly mismatch)" + fail "$nshort $options (assembly comparison)" } } } Index: gcc/testsuite/g++.dg/pph/x1dynarray2.h =================================================================== --- gcc/testsuite/g++.dg/pph/x1dynarray2.h (revision 0) +++ gcc/testsuite/g++.dg/pph/x1dynarray2.h (revision 0) @@ -0,0 +1,111 @@ +// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } } +// { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, _WCHAR_H is" "" { xfail *-*-* } 0 } +// { dg-bogus "unistd.h:1144:34: error: declaration of .* has a different exception specifier" "" { xfail *-*-* } 0 } +#ifndef X1DYNARRAY2_H +#define X1DYNARRAY2_H + +#include +#include +#include +#include +#include + +#define DefaultConstructible typename +#define CPP0X( ignore ) + +namespace std { + +template< DefaultConstructible T > +struct dynarray +{ + // types: + typedef T value_type; + typedef T& reference; + typedef const T& const_reference; + typedef T* iterator; + typedef const T* const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + // fields: +private: + T* store; + size_type count; + + // helper functions: + void check(size_type n) + { if ( n >= count ) throw out_of_range("dynarray"); } + T* alloc(size_type n) + { return reinterpret_cast( new char[ n*sizeof(T) ] ); } + +public: + // construct and destruct: + dynarray() CPP0X( = delete ) ; + const dynarray operator=(const dynarray&) CPP0X( = delete ) ; + + explicit dynarray(size_type c) + : store( alloc( c ) ), count( c ) + { size_type i; + try { + for ( size_type i = 0; i < count; ++i ) + new (store+i) T; + } catch ( ... ) { + for ( ; i > 0; --i ) + (store+(i-1))->~T(); + throw; + } } + + dynarray(const dynarray& d) + : store( alloc( d.count ) ), count( d.count ) + { try { uninitialized_copy( d.begin(), d.end(), begin() ); } + catch ( ... ) { delete store; throw; } } + + ~dynarray() + { for ( size_type i = 0; i < count; ++i ) + (store+i)->~T(); + delete[] store; } + + // iterators: + iterator begin() { return store; } + const_iterator begin() const { return store; } + const_iterator cbegin() const { return store; } + iterator end() { return store + count; } + const_iterator end() const { return store + count; } + const_iterator cend() const { return store + count; } + + reverse_iterator rbegin() + { return reverse_iterator(end()); } + const_reverse_iterator rbegin() const + { return reverse_iterator(end()); } + reverse_iterator rend() + { return reverse_iterator(begin()); } + const_reverse_iterator rend() const + { return reverse_iterator(begin()); } + + // capacity: + size_type size() const { return count; } + size_type max_size() const { return count; } + bool empty() const { return false; } + + // element access: + reference operator[](size_type n) { return store[n]; } + const_reference operator[](size_type n) const { return store[n]; } + + reference front() { return store[0]; } + const_reference front() const { return store[0]; } + reference back() { return store[count-1]; } + const_reference back() const { return store[count-1]; } + + const_reference at(size_type n) const { check(n); return store[n]; } + reference at(size_type n) { check(n); return store[n]; } + + // data access: + T* data() { return store; } + const T* data() const { return store; } +}; + +} // namespace std + +#endif Index: gcc/testsuite/g++.dg/pph/x1dynarray2.cc =================================================================== --- gcc/testsuite/g++.dg/pph/x1dynarray2.cc (revision 0) +++ gcc/testsuite/g++.dg/pph/x1dynarray2.cc (revision 0) @@ -0,0 +1,48 @@ +// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } } + +#include +#include +#include "x1dynarray2.h" + +void dump( const std::dynarray< int > & source ) +{ + std::dynarray< int >::const_iterator src = source.begin(); + for ( ; src != source.end(); src++ ) + std::cout << " " << *src; + std::cout << std::endl; +} + +void lowrap( std::dynarray< int > & target, + const std::dynarray< int > & source ) +{ + dump( source ); + + std::dynarray< int > sorted( source ); + dump( sorted ); + + std::sort( sorted.begin(), sorted.end() ); + dump( sorted ); + + const int* srt = &sorted.front(); + std::dynarray< int >::iterator tgt( target.begin() ); + for ( ; tgt != target.end(); tgt++ ) { + *tgt = *srt; + if ( srt == &sorted.back() ) + srt = &sorted.front(); + else + srt++; + } + dump( target ); +} + +int main() { + std::dynarray< int > alpha(8); + std::dynarray< int > gamma(3); + for ( std::dynarray< int >::size_type i = 0; i < gamma.size(); i++ ) + gamma[i] = 4 - i; + lowrap( alpha, gamma ); + int sum = 0; + for ( std::dynarray< int >::size_type i = 0; i < alpha.size(); i++ ) + sum += alpha.at(i); + return sum - 23; +} Index: gcc/testsuite/g++.dg/pph/x1dynarray1.cc =================================================================== --- gcc/testsuite/g++.dg/pph/x1dynarray1.cc (revision 175673) +++ gcc/testsuite/g++.dg/pph/x1dynarray1.cc (working copy) @@ -1,20 +1,13 @@ -// { dg-xfail-if "ICE" { "*-*-*" } { "-fpph-map=pph.map" } } -// { dg-bogus "internal compiler error: in resume_scope" "" { xfail *-*-* } 0 } -// { dg-bogus "from .*" "" { xfail *-*-* } 0 } -// { dg-bogus "fails macro validation " "" { xfail *-*-* } 0 } -// { dg-prune-output "In file included from " } - #include "x1dynarray1.h" -#include #include -void lowrap( std::dynarray< int > & target, - const std::dynarray< int > & source ) +void lowrap( dynarray< int > & target, + const dynarray< int > & source ) { - std::dynarray< int > sorted( source ); + dynarray< int > sorted( source ); std::sort( sorted.begin(), sorted.end() ); const int* srt = &sorted.front(); - std::dynarray< int >::iterator tgt( target.begin() ); + dynarray< int >::iterator tgt( target.begin() ); for ( ; tgt != target.end(); tgt++ ) { *tgt = *srt; if ( srt == &sorted.back() ) @@ -25,13 +18,13 @@ void lowrap( std::dynarray< int > } int main() { - std::dynarray< int > alpha(8); - std::dynarray< int > gamma(3); - for ( std::dynarray< int >::size_type i = 0; i < gamma.size(); i++ ) + dynarray< int > alpha(8); + dynarray< int > gamma(3); + for ( dynarray< int >::size_type i = 0; i < gamma.size(); i++ ) gamma[i] = 4 - i; lowrap( alpha, gamma ); int sum = 0; - for ( std::dynarray< int >::size_type i = 0; i < alpha.size(); i++ ) + for ( dynarray< int >::size_type i = 0; i < alpha.size(); i++ ) sum += alpha.at(i); return sum - 23; } Index: gcc/testsuite/g++.dg/pph/x1dynarray1.h =================================================================== --- gcc/testsuite/g++.dg/pph/x1dynarray1.h (revision 175673) +++ gcc/testsuite/g++.dg/pph/x1dynarray1.h (working copy) @@ -1,14 +1,10 @@ #ifndef X1DYNARRAY1_H #define X1DYNARRAY1_H -#include - -#define DefaultConstructible typename -#define CPP0X( ignore ) - -namespace std { +extern "C" void *memcpy(void *dest, const void *src, unsigned long n); +extern "C" void exit(int) throw(); -template< DefaultConstructible T > +template< typename T > struct dynarray { // types: @@ -27,36 +23,24 @@ private: // helper functions: void check(size_type n) - { if ( n >= count ) throw n; } + { if ( n >= count ) exit(1); } T* alloc(size_type n) { return reinterpret_cast( new char[ n*sizeof(T) ] ); } public: // construct and destruct: - dynarray() CPP0X( = delete ) ; - const dynarray operator=(const dynarray&) CPP0X( = delete ) ; + dynarray(); // undefined + const dynarray operator=(const dynarray&); // undefined explicit dynarray(size_type c) - : store( alloc( c ) ), count( c ) - { size_type i; - try { - for ( size_type i = 0; i < count; ++i ) - new (store+i) T; - } catch ( ... ) { - for ( ; i > 0; --i ) - (store+(i-1))->~T(); - throw; - } } + : store( alloc( c ) ), count( c ) { } dynarray(const dynarray& d) : store( alloc( d.count ) ), count( d.count ) - { try { uninitialized_copy( d.begin(), d.end(), begin() ); } - catch ( ... ) { delete store; throw; } } + { memcpy( store, d.store, count * sizeof(T) ); } ~dynarray() - { for ( size_type i = 0; i < count; ++i ) - (store+i)->~T(); - delete[] store; } + { delete[] store; } // iterators: iterator begin() { return store; } @@ -88,6 +72,4 @@ public: const T* data() const { return store; } }; -} // namespace std - #endif Index: gcc/testsuite/g++.dg/pph/x1dynarray0.cc =================================================================== --- gcc/testsuite/g++.dg/pph/x1dynarray0.cc (revision 0) +++ gcc/testsuite/g++.dg/pph/x1dynarray0.cc (revision 0) @@ -0,0 +1,8 @@ +// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } } + +#include "x1dynarray1.h" + +int main() { + dynarray< int > alpha(8); + return 0; +}