From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6055 invoked by alias); 11 Apr 2011 19:49:06 -0000 Received: (qmail 6046 invoked by uid 22791); 11 Apr 2011 19:49:04 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 11 Apr 2011 19:48:55 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3BJmktL010506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 11 Apr 2011 15:48:46 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p3BJmiWR014678 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 11 Apr 2011 15:48:45 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p3BJmins008154; Mon, 11 Apr 2011 21:48:44 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p3BJmhUu008153; Mon, 11 Apr 2011 21:48:43 +0200 Date: Mon, 11 Apr 2011 19:49:00 -0000 From: Jakub Jelinek To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Error out on uses of void type expressions in inline asm in C FE (PR c/48552) Message-ID: <20110411194843.GZ17079@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-04/txt/msg00795.txt.bz2 Hi! Several of the functions in the following testcases ICE. Unlike C++ FE, C FE doesn't error out on void type derefs right away, just warns. But using void type expression for "r" or "=r" doesn't make sense and was ICEing. The patch still tollerates it for constraints that allow only mem, as that case wasn't crashing and just address of it was presented to the asm. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-04-11 Jakub Jelinek PR c/48552 * c-typeck.c (build_asm_expr): Error out on attempts to use void type outputs or inputs for constraints that allow reg or don't allow memory. * gcc.dg/pr48552-1.c: New test. * gcc.dg/pr48552-2.c: New test. --- gcc/c-typeck.c.jj 2011-03-31 08:51:03.000000000 +0200 +++ gcc/c-typeck.c 2011-04-11 13:29:17.000000000 +0200 @@ -8502,6 +8502,13 @@ build_asm_expr (location_t loc, tree str mark it addressable. */ if (!allows_reg && !c_mark_addressable (output)) output = error_mark_node; + if (!(!allows_reg && allows_mem) + && output != error_mark_node + && VOID_TYPE_P (TREE_TYPE (output))) + { + error_at (loc, "invalid use of void expression"); + output = error_mark_node; + } } else output = error_mark_node; @@ -8528,7 +8535,12 @@ build_asm_expr (location_t loc, tree str STRIP_NOPS (input); if (!c_mark_addressable (input)) input = error_mark_node; - } + } + else if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input))) + { + error_at (loc, "invalid use of void expression"); + input = error_mark_node; + } } else input = error_mark_node; --- gcc/testsuite/gcc.dg/pr48552-1.c.jj 2011-04-11 14:22:13.000000000 +0200 +++ gcc/testsuite/gcc.dg/pr48552-1.c 2011-04-11 14:24:40.000000000 +0200 @@ -0,0 +1,53 @@ +/* PR c/48552 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct S; + +void +f1 (void *x) +{ + __asm volatile ("" : : "r" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 10 } */ + +void +f2 (void *x) +{ + __asm volatile ("" : "=r" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 16 } */ + /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 16 } */ +void +f3 (void *x) +{ + __asm volatile ("" : : "m" (*x)); /* { dg-warning "dereferencing" } */ +} + +void +f4 (void *x) +{ + __asm volatile ("" : "=m" (*x)); /* { dg-warning "dereferencing" } */ +} + +void +f5 (void *x) +{ + __asm volatile ("" : : "g" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 34 } */ + +void +f6 (void *x) +{ + __asm volatile ("" : "=g" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 40 } */ + /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 40 } */ +void +f7 (struct S *x) +{ + __asm volatile ("" : : "r" (*x)); /* { dg-error "dereferencing pointer to incomplete type" } */ +} + +void +f8 (struct S *x) +{ + __asm volatile ("" : "=r" (*x)); /* { dg-error "dereferencing pointer to incomplete type" } */ +} /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 52 } */ --- gcc/testsuite/gcc.dg/pr48552-2.c.jj 2011-04-11 14:22:13.000000000 +0200 +++ gcc/testsuite/gcc.dg/pr48552-2.c 2011-04-11 14:24:59.000000000 +0200 @@ -0,0 +1,53 @@ +/* PR c/48552 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct S; + +void +f1 (void *x) +{ + __asm ("" : : "r" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 10 } */ + +void +f2 (void *x) +{ + __asm ("" : "=r" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 16 } */ + /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 16 } */ +void +f3 (void *x) +{ + __asm ("" : : "m" (*x)); /* { dg-warning "dereferencing" } */ +} + +void +f4 (void *x) +{ + __asm ("" : "=m" (*x)); /* { dg-warning "dereferencing" } */ +} + +void +f5 (void *x) +{ + __asm ("" : : "g" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 34 } */ + +void +f6 (void *x) +{ + __asm ("" : "=g" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 40 } */ + /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 40 } */ +void +f7 (struct S *x) +{ + __asm ("" : : "r" (*x)); /* { dg-error "dereferencing pointer to incomplete type" } */ +} + +void +f8 (struct S *x) +{ + __asm ("" : "=r" (*x)); /* { dg-error "dereferencing pointer to incomplete type" } */ +} /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 52 } */ Jakub