2011-06-29 Lawrence Crowl <crowl@google.com>
* 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.
===================================================================
@@ -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)"
}
}
}
===================================================================
@@ -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 <stddef.h>
+#include <stdexcept>
+#include <memory>
+#include <new>
+#include <iterator>
+
+#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<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_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<T*>( 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
===================================================================
@@ -0,0 +1,48 @@
+// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
+
+#include <iostream>
+#include <algorithm>
+#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;
+}
===================================================================
@@ -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 <iostream>
#include <algorithm>
-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;
}
===================================================================
@@ -1,14 +1,10 @@
#ifndef X1DYNARRAY1_H
#define X1DYNARRAY1_H
-#include <memory>
-
-#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<T*>( 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
===================================================================
@@ -0,0 +1,8 @@
+// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
+
+#include "x1dynarray1.h"
+
+int main() {
+ dynarray< int > alpha(8);
+ return 0;
+}