From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30524 invoked by alias); 28 Nov 2003 14:13:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 30512 invoked from network); 28 Nov 2003 14:13:56 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sources.redhat.com with SMTP; 28 Nov 2003 14:13:56 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.11.6/8.11.6) with ESMTP id hASEDsH29693 for ; Fri, 28 Nov 2003 09:13:54 -0500 Received: from localhost (vpnuser1.surrey.redhat.com [172.16.9.1]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id hASEDsw07385 for ; Fri, 28 Nov 2003 09:13:54 -0500 Received: from rsandifo by localhost with local (Exim 3.35 #1) id 1APjOd-0000Cf-00 for gcc-patches@gcc.gnu.org; Fri, 28 Nov 2003 14:14:59 +0000 To: gcc-patches@gcc.gnu.org Subject: Fix x86 segfault on thread-local asm operands From: Richard Sandiford Date: Fri, 28 Nov 2003 16:32:00 -0000 Message-ID: <874qwok2ak.fsf@redhat.com> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-11/txt/msg02244.txt.bz2 If "i" is a thread-local variable, using the deprecated: asm volatile ("" :: "m" (&i)); will cause gcc to segfault on x86. We try to force the constant into memory but don't check for success. Patch bootstrapped & regression tested on i686-pc-linux-gnu. OK to install? Richard * stmt.c (expand_asm_operands): Check whether force_const_mem succeeded. testsuite/ * gcc.dg/tls/asm-1.C: New test. Index: stmt.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/stmt.c,v retrieving revision 1.336 diff -c -d -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.336 stmt.c *** stmt.c 20 Nov 2003 00:28:39 -0000 1.336 --- stmt.c 28 Nov 2003 14:00:04 -0000 *************** expand_asm_operands (tree string, tree o *** 1712,1724 **** if (CONSTANT_P (op)) { ! op = force_const_mem (TYPE_MODE (type), op); ! op = validize_mem (op); } ! else if (GET_CODE (op) == REG ! || GET_CODE (op) == SUBREG ! || GET_CODE (op) == ADDRESSOF ! || GET_CODE (op) == CONCAT) { tree qual_type = build_qualified_type (type, (TYPE_QUALS (type) --- 1712,1727 ---- if (CONSTANT_P (op)) { ! rtx mem = force_const_mem (TYPE_MODE (type), op); ! if (mem) ! op = validize_mem (mem); ! else ! op = force_reg (TYPE_MODE (type), op); } ! if (GET_CODE (op) == REG ! || GET_CODE (op) == SUBREG ! || GET_CODE (op) == ADDRESSOF ! || GET_CODE (op) == CONCAT) { tree qual_type = build_qualified_type (type, (TYPE_QUALS (type) *** /dev/null Tue Mar 19 20:01:09 2002 --- testsuite/gcc.dg/tls/asm-1.c Fri Nov 28 13:56:54 2003 *************** *** 0 **** --- 1,7 ---- + /* { dg-options "" } */ + __thread int i; + + int foo () + { + asm volatile ("" :: "m" (&i)); /* { dg-warning "input without lvalue" } */ + }