From: Hans-Peter Nilsson Date: Wed, 2 Nov 2005 02:41:44 +0000 (+0000) Subject: target-supports.exp (check_effective_default_packed): New proc. X-Git-Tag: releases/gcc-4.1.0~1115 X-Git-Url: https://gcc.gnu.org/git/?a=commitdiff_plain;h=aa5c7673b84fbcecbe6301d6df6a0849dffbcb02;p=gcc.git target-supports.exp (check_effective_default_packed): New proc. * lib/target-supports.exp (check_effective_default_packed): New proc. * g++.dg/ext/packed3.C, g++.dg/ext/packed8.C, g++.dg/other/crash-4.C: Gate expected errors on target ! default_packed. * g++.dg/ext/packed4.C: Gate on target ! default_packed. From-SVN: r106374 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index faa7ff51382d..079e1e64ed1f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2005-11-02 Hans-Peter Nilsson + + * lib/target-supports.exp (check_effective_default_packed): New proc. + * g++.dg/ext/packed3.C, g++.dg/ext/packed8.C, g++.dg/other/crash-4.C: + Gate expected errors on target ! default_packed. + * g++.dg/ext/packed4.C: Gate on target ! default_packed. + 2005-11-02 Tobias Schl"uter * gfortran.fortran-torture/execute/entry_9.f90: Revert previous diff --git a/gcc/testsuite/g++.dg/ext/packed3.C b/gcc/testsuite/g++.dg/ext/packed3.C index 1d3ef534ae1b..3494ff4c31ee 100644 --- a/gcc/testsuite/g++.dg/ext/packed3.C +++ b/gcc/testsuite/g++.dg/ext/packed3.C @@ -19,7 +19,7 @@ struct __attribute__ ((packed)) Packed void Foo (Packed &p) { - Ref (p.i); // { dg-error "cannot bind packed field" "" } + Ref (p.i); // { dg-error "cannot bind packed field" "" { target { ! default_packed } } } Ref (p.u.i); - Ref (p.u); // { dg-error "cannot bind packed field" "" } + Ref (p.u); // { dg-error "cannot bind packed field" "" { target { ! default_packed } } } } diff --git a/gcc/testsuite/g++.dg/ext/packed4.C b/gcc/testsuite/g++.dg/ext/packed4.C index db1f5c992eea..e5e5e2c08da3 100644 --- a/gcc/testsuite/g++.dg/ext/packed4.C +++ b/gcc/testsuite/g++.dg/ext/packed4.C @@ -1,4 +1,4 @@ -// { dg-do run } +// { dg-do run { target { ! default_packed } } } // { dg-options "-w" } // Copyright (C) 2003 Free Software Foundation, Inc. diff --git a/gcc/testsuite/g++.dg/ext/packed8.C b/gcc/testsuite/g++.dg/ext/packed8.C index 61d248e99285..13fc134bd97e 100644 --- a/gcc/testsuite/g++.dg/ext/packed8.C +++ b/gcc/testsuite/g++.dg/ext/packed8.C @@ -19,6 +19,6 @@ class B public: B() {} - A GetA() { return a; } // { dg-error "" } + A GetA() { return a; } // { dg-error "" "" { target { ! default_packed } } } }; diff --git a/gcc/testsuite/g++.dg/other/crash-4.C b/gcc/testsuite/g++.dg/other/crash-4.C index 900afb7f90bd..ea5a14fa7aed 100644 --- a/gcc/testsuite/g++.dg/other/crash-4.C +++ b/gcc/testsuite/g++.dg/other/crash-4.C @@ -15,12 +15,12 @@ struct a a(const a&); }; struct b -{ // { dg-error "cannot bind packed field" } +{ // { dg-error "cannot bind packed field" "" { target { ! default_packed } } } char c; a aa __attribute__((packed)); }; struct c { b bb; - c(const b& __a): bb(__a) {} // { dg-error "synthesized" } + c(const b& __a): bb(__a) {} // { dg-error "synthesized" "" { target { ! default_packed } } } }; diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index b98e3ceb94f1..eac665838f6d 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -304,6 +304,46 @@ proc check_profiling_available { test_what } { return $profiling_available_saved } +# Return 1 if target has packed layout of structure members by +# default, 0 otherwise. Note that this is slightly different than +# whether the target has "natural alignment": both attributes may be +# false. + +proc check_effective_target_default_packed { } { + global et_default_packed_saved + global et_default_packed_target_name + + if { ![info exists et_default_packed_target_name] } { + set et_default_packed_target_name "" + } + + # If the target has changed since we set the cached value, clear it. + set current_target [current_target_name] + if { $current_target != $et_default_packed_target_name } { + verbose "check_effective_target_default_packed: `$et_default_packed_target_name'" 2 + set et_default_packed_target_name $current_target + if [info exists et_default_packed_saved] { + verbose "check_effective_target_default_packed: removing cached result" 2 + unset et_default_packed_saved + } + } + + if [info exists et_default_packed_saved] { + verbose "check_effective_target_default_packed: using cached result" 2 + } else { + verbose "check_effective_target_default_packed: compiling source" 2 + + set et_default_packed_saved \ + [string match "" [get_compiler_messages default_packed assembly { + struct x { char a; long b; } c; + int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1]; + } ]] + + } + verbose "check_effective_target_default_packed: returning $et_default_packed_saved" 2 + return $et_default_packed_saved +} + # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors # emitted, 0 otherwise. Whether a shared library can actually be built is # out of scope for this test.