From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1552 invoked by alias); 8 Dec 2007 17:20:30 -0000 Received: (qmail 1544 invoked by uid 22791); 8 Dec 2007 17:20:29 -0000 X-Spam-Check-By: sourceware.org Received: from os.inf.tu-dresden.de (HELO os.inf.tu-dresden.de) (141.76.48.99) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 08 Dec 2007 17:20:23 +0000 Received: from pd9eb0389.dip0.t-ipconnect.de ([217.235.3.137] helo=laptop.hypervisor.org) by os.inf.tu-dresden.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.68) id 1J13Lg-000227-L9 for gcc-help@gcc.gnu.org; Sat, 08 Dec 2007 18:20:20 +0100 Date: Sat, 08 Dec 2007 17:20:00 -0000 From: "Udo A. Steinberg" To: gcc-help@gcc.gnu.org Subject: Clobbering memory region Message-ID: <20071208182019.6b983dce@laptop.hypervisor.org> X-Mailer: X-Mailer 5.0 Gold Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2007-12/txt/msg00177.txt.bz2 Hello all, An easy way to specify that an inline assembler statement changes memory is to add "memory" to the clobber list. However, that is overly pessimistic. As an alternative one can specify an output parameter for the memory region like this: #include void *memcpy (void *d, void const *s, size_t n) { unsigned dummy; asm volatile ("rep; movsb" : "=D" (dummy), "+S" (s), "+c" (n), "=m" (*(struct { char x[n]; } *) d) : "0" (d)); return d; } This works well in C (e.g., via gcc -c test.c). With C++ (g++ -c test.c) the compiler complains: test.c: In function 'void* memcpy(void*, const void*, size_t)': test.c:9: error: types may not be defined in casts test.c:9: error: array bound is not an integer constant Is there a way to make this kind of sophisticated clobber work in C++ also? Cheers, - Udo