From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9964 invoked by alias); 15 Jul 2005 05:50:31 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 9943 invoked by uid 48); 15 Jul 2005 05:50:28 -0000 Date: Fri, 15 Jul 2005 06:41:00 -0000 Message-ID: <20050715055028.9941.qmail@sourceware.org> From: "neroden at gcc dot gnu dot org" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20050702164323.22278.olivier.baudron@m4x.org> References: <20050702164323.22278.olivier.baudron@m4x.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c/22278] gcc -O2 discards cast to volatile X-Bugzilla-Reason: CC X-SW-Source: 2005-07/txt/msg01861.txt.bz2 List-Id: ------- Additional Comments From neroden at gcc dot gnu dot org 2005-07-15 05:50 ------- OK, so in X.org, the key area where this is hit is the definition of MMIO_IN8 in compiler.h. For alpha, sparc, and powerpc, inline volatile ASM is used instead (much better in some ways). The vanishing line is: (void) minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET); This expands in preprocessing to: (void) MMIO_IN8(hwp->MMIOBase, (hwp->MMIOOffset + (hwp->IOBase + VGA_IN_STAT_1_OFFSET))) which further expands in preprocessing in compiler.h (except for sparc, alpha and powerpc) to: (void) *(volatile CARD8 *)( (CARD8*)(hwp->MMIOBase) + hwp->MMIOOffset + hwp->IOBase + VGA_IN_STAT_1_OFFSET) The key expansion is this one: # define MMIO_IN8(base, offset) \ *(volatile CARD8 *)(((CARD8*)(base)) + (offset)) This obviously doesn't work and perhaps it shouldn't work. But what is a good alternative implementation? Essentially, we're trying to force a read of an arbitrary memory address. If the "underlying object" has to be volatile, how do we make it volatile? Can we simply create a new "underlying object" by throwing in a temporary pointer variable? Is something like the following sufficient to force an access? static inline unsigned char myMmioIn8(volatile void* base, const unsigned long offset) { volatile CARD8 * tmp = (CARD8*)base + offset; return *tmp; } # define MMIO_IN8(base, offset) myMmioIn8(base, offset) If that's not sufficient, I don't see any way to accomplish the required behavior under gcc 4.0 (without massive rewriting of the X.org code), so I hope it is. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22278