From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18637 invoked by alias); 3 Mar 2004 22:38:46 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 18630 invoked from network); 3 Mar 2004 22:38:45 -0000 Received: from unknown (HELO develer.com) (151.38.19.110) by sources.redhat.com with SMTP; 3 Mar 2004 22:38:45 -0000 Received: (qmail 19619 invoked from network); 3 Mar 2004 22:38:38 -0000 Received: from beetle.trilan (HELO develer.com) (?GAMON0n6FrnuIoiX/kv9vUAFHtRqN5sN?@10.3.3.220) by ns.trilan with SMTP; 3 Mar 2004 22:38:38 -0000 Message-ID: <40465E6E.5070301@develer.com> Date: Wed, 03 Mar 2004 22:38:00 -0000 From: Bernardo Innocenti Organization: Develer S.r.l. User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040217 MIME-Version: 1.0 To: Andreas Schwab CC: Roman Zippel , Richard Zidlicky , peter@baradas.org, Matthias Klose , gcc@gcc.gnu.org, Gunther Nikl Subject: Re: more m68k breakage on m68k-linux References: <4009E670.5090600@develer.com> <16394.22429.131429.162236@gargle.gargle.HOWL> <20040301200553.GA4188@linux-m68k.org> <20040301215409.GA18138@linux-m68k.org> <4043D2EB.1050602@develer.com> <20040302085305.GA1482@linux-m68k.org> <4044E15C.1000303@linux-m68k.org> <40459CD4.90907@develer.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-03/txt/msg00252.txt.bz2 Andreas Schwab wrote: > Bernardo Innocenti writes: > > >>I'm convinced that argptr missing from FIXED_REGISTERS was an anomaly, >>but I still don't quite understand how it would affect init_reg_sets(). >>Could you elaborate? > > > memcpy (fixed_regs, initial_fixed_regs, sizeof fixed_regs); > memcpy (call_used_regs, initial_call_used_regs, sizeof call_used_regs); > > sizeof fixed_regs > sizeof initial_fixed_regs > sizeof call_used_regs > sizeof initial_call_used_regs Oh, I see. I had been thinking about memory trashing, not uninitialized memory. I apologize for being the root cause of such a subtle bug. To make sure this particular case will never show up again on any backend, I'd like to add some static sanity checks. We can't use the preprocessor because it doesn't know about structure sizes. Woundn't it be nice to have something like BOOST's static assert for C? I've come up with this hack: #define __STATIC_ASSERT_PASTE2(x,y) x ## y #define __STATIC_ASSEET_PASTE(x,y) __PASTE2(x,y) #define STATIC_ASSERT(EXPR) \ typedef struct { \ char ASSERTION_FAILED[(EXPR) ? 1 : -1]; \ } __STATIC_ASSERT_PASTE(__assertion_, __LINE__) Here is a test case to show how it works: int main(void) { static const int a = 42; STATIC_ASSERT(sizeof(short) == sizeof(long)); // ERROR! STATIC_ASSERT(sizeof(short) * 2 == sizeof(long)); OK STATIC_ASSERT(10 > 30); // ERROR! STATIC_ASSERT(a > 10); // OK STATIC_ASSERT(a > 50); // OK??? Is this a GCC bug? return 0; } Do you think we could include something like this somewhere in GCC? -- // Bernardo Innocenti - Develer S.r.l., R&D dept. \X/ http://www.develer.com/