From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112248 invoked by alias); 12 Mar 2018 11:18:24 -0000 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 Received: (qmail 112231 invoked by uid 89); 12 Mar 2018 11:18:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-ot0-f196.google.com Received: from mail-ot0-f196.google.com (HELO mail-ot0-f196.google.com) (74.125.82.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Mar 2018 11:18:21 +0000 Received: by mail-ot0-f196.google.com with SMTP id l5so14823441otf.9 for ; Mon, 12 Mar 2018 04:18:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=dcyPEVcu9Taj6mPvDQiHtukY4estvp8kfQazluqxa0A=; b=M0KJ7/BIatq4nZDf+7DMlWGnJqinpVhS1vic0L25O05Ut6sFvZ4LyBJ//Agt5qD+Ms NFysNTWtP0oNbVMJP07gZg/SKMFhV03IVIBNfmLo1yqXUicjh52g73upZxV5b/pcSiBm hlmeiF4bQcx+s4gusReim1x1e2UV+5Vd7/i1hZxza8Gu8DZVNKY/oIXF38qwQ7tWaKYS PZXeN6jJHwnvWyRAOm0vCmipBTlwlXPphvs5esj8KnMFdwa5XzOsXK6j8mViC29QGNjf z5+M+cWTRsd4Ks1R3qCLhTDRPyB5YIsKbV1ECX3Jy7JPr0jG3pTER1etJGQQ8cyAX9YZ VFMw== X-Gm-Message-State: AElRT7E8I6Gj+Arls58QA4rTbhd4fvRs8QyqUG+nu6HRjlfvJX88ffyQ 9Bsz6Zr0lho/Q493XgdqODIbuiB57icJwHclpGU= X-Google-Smtp-Source: AG47ELufcD24bp2yHUuP6rIwV5LbVc/KqSTm9IOEi/nErL24fDPKEnS88DI5ZTi1s+vLvg1cebwEQXMiZtNW8Bovmyg= X-Received: by 10.157.65.18 with SMTP id o18mr5508606ote.7.1520853500071; Mon, 12 Mar 2018 04:18:20 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.10.20 with HTTP; Mon, 12 Mar 2018 04:18:19 -0700 (PDT) In-Reply-To: <20180308181907.GX5867@tucnak> References: <20180308181907.GX5867@tucnak> From: "H.J. Lu" Date: Mon, 12 Mar 2018 11:18:00 -0000 Message-ID: Subject: Re: [PATCH] Diagnose earlier invalid inline asm constraints (PR inline-asm/84742) To: Jakub Jelinek Cc: Richard Biener , Jeff Law , GCC Patches Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2018-03/txt/msg00517.txt.bz2 On Thu, Mar 8, 2018 at 10:19 AM, Jakub Jelinek wrote: > Hi! > > We have many loops that use CONSTRAINT_LEN to skip over various constraint > characters, but we assume the constraints have valid length and don't walk > the individual characters to double check this. > > If that is not the case, when e.g. 2 character constraint starting letter > is followed by '\0', we'd reject it early (during vregs pass, through > asm_operand_ok). The PR has different testcase (that fails randomly based > on ASLR), where a 2 character constraint starting letter is followed by ',', > and several spots expect that not to happen (they count number of > alternatives and then for each alternative walk with skipping CONSTRAINT_LEN > characters). > > This patch diagnoses this problematic case early as well. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2018-03-08 Jakub Jelinek > > PR inline-asm/84742 > * recog.c (asm_operand_ok): Return 0 if multi-character constraint > has ',' character inside of it. > > * gcc.target/i386/pr84742-1.c: New test. > * gcc.target/i386/pr84742-2.c: New test. > > --- gcc/recog.c.jj 2018-01-16 09:53:47.000000000 +0100 > +++ gcc/recog.c 2018-03-08 14:04:35.889274871 +0100 > @@ -1825,7 +1825,7 @@ asm_operand_ok (rtx op, const char *cons > len = CONSTRAINT_LEN (c, constraint); > do > constraint++; > - while (--len && *constraint); > + while (--len && *constraint && *constraint != ','); > if (len) > return 0; > } > --- gcc/testsuite/gcc.target/i386/pr84742-1.c.jj 2018-03-08 14:11:20.155463943 +0100 > +++ gcc/testsuite/gcc.target/i386/pr84742-1.c 2018-03-08 14:12:28.453495882 +0100 > @@ -0,0 +1,10 @@ > +/* PR inline-asm/84742 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2" } */ > + > +void > +foo () > +{ > + char b = 1; > + asm volatile ("" : "+T,Y" (b)); /* { dg-error "impossible constraint in 'asm'" } */ > +} This test fails at random on 32-bit hosts (i686 and x32). Sometimes I got spawn -ignore SIGHUP /export/build/gnu/gcc-32bit-all-test/build-i686-linux/gcc/xgcc -B/export/build/gnu/gcc-32bit-all-test/build-i686-linux/gcc/ /export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c -m32 -fno-diagnostics-show-caret -fdiagnostics-color=never -O2 -S -o pr84742-1.s /export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c: In function 'foo': /export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c:9:3: error: matching constraint not valid in output operand /export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c:9:3: error: matching constraint not valid in output operand FAIL: gcc.target/i386/pr84742-1.c (test for errors, line 9) FAIL: gcc.target/i386/pr84742-1.c (test for excess errors) But when I ran it by hand: [hjl@gnu-skx-1 gcc]$ /export/build/gnu/gcc-32bit-all-test/build-i686-linux/gcc/xgcc -B/export/build/gnu/gcc-32bit-all-test/build-i686-linux/gcc/ /export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c -m32 -fno-diagnostics-show-caret -fdiagnostics-color=never -O2 -S -o pr84742-1.s /export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c: In function \u2018foo\u2019: /export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c:9:3: error: impossible constraint in \u2018asm\u2019 [hjl@gnu-skx-1 gcc]$ -- H.J.