| Message ID | aV907fXp89NUiAb-@tucnak |
|---|---|
| State | New |
| Headers |
Return-Path: <gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 833B04BA2E23 for <patchwork@sourceware.org>; Thu, 8 Jan 2026 09:13:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 833B04BA2E23 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SZeVmMT5 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 053DF4BA2E06 for <gcc-patches@gcc.gnu.org>; Thu, 8 Jan 2026 09:12:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 053DF4BA2E06 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 053DF4BA2E06 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1767863543; cv=none; b=o+Huv3wUrc6FzjC5zDirYs00yPSTZna40F/GpCndv9/ysH7tyR465YENlr/u3NVebQ1R+yTRFRLIW6RUtRwIfxrVuUTEiH8EMn/+QIkEqqnu/7e4HgFz/Wyv1H9Lp88jPYFFZEpvjsRvXcV9scPHjxTMD++BhIcvUoA46ByPbRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1767863543; c=relaxed/simple; bh=zsfoBE2tChAxRKc9EsP79Jf4fH5MAUEUeFvpbh4f4Ts=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=G39O3ypCWBAghERTSkAkNFKF5p457iGzBv/JlpL7s+oPg8IFsT2lHBujlkYLTVA6pZS5ZluH+MrtNNT4h3EK153FRe9OB6ZA16mfCbJhmKDSe4a9ak99zRfX3dNgws9QgUSgWInAkb7UI+wazbUBJH+47iGqD8jPKmHw0zwd4Vw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 053DF4BA2E06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767863542; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=ydtII0Cpem0u8h4gVS8MeGNfm++d4CZT9HwHPWTHL3U=; b=SZeVmMT5QFaJD0bS8QSEnYGMWtzIo6hYQJZMMcYXICn6umECQSMbzI3vfnCVrkMWk3Bi58 Rcz7b0NFifHJlsN9ONL5Vc1hLnNNdArBdOhD63cMLqA4vgZlxyBmUgJ65xZtE+uK55lvY/ SxnDgnRwVLroZobXYel5ILU60JY6cIc= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-495-lEZRpWGwNEKiJIj3IX2sCA-1; Thu, 08 Jan 2026 04:12:18 -0500 X-MC-Unique: lEZRpWGwNEKiJIj3IX2sCA-1 X-Mimecast-MFC-AGG-ID: lEZRpWGwNEKiJIj3IX2sCA_1767863537 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6C45F180035D; Thu, 8 Jan 2026 09:12:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.44.32.27]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D622C1800285; Thu, 8 Jan 2026 09:12:16 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.18.1/8.18.1) with ESMTPS id 6089CDFs397194 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 8 Jan 2026 10:12:13 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 6089CDIh397193; Thu, 8 Jan 2026 10:12:13 +0100 Date: Thu, 8 Jan 2026 10:12:13 +0100 From: Jakub Jelinek <jakub@redhat.com> To: Richard Biener <rguenther@suse.de>, Jeff Law <jeffreyalaw@gmail.com> Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] stmt: Fix up parse_input_constraint [PR111817] Message-ID: <aV907fXp89NUiAb-@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: CP1I4H1XLK0_pOzTL4rWCYn2ysxLE_USx2U-U3b0r4Y_1767863537 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_NONE, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org |
| Series |
stmt: Fix up parse_input_constraint [PR111817]
|
|
Commit Message
Jakub Jelinek
Jan. 8, 2026, 9:12 a.m. UTC
Hi!
The following invalid testcase ICEs, because we:
1) for some strange reason ignore invalid punctuations in
parse_output_constraint, which has just
default:
if (!ISALPHA (*p))
break;
compared to parse_input_constraint
default:
if (! ISALPHA (constraint[j]))
{
error ("invalid punctuation %qc in constraint", constraint[j]);
return false;
}
Haven't touched this because I fear it could break real-world code
2) the checking whether = or + is first in the output constraint is
a warning only:
if (p != constraint)
warning (0, "output constraint %qc for operand %d "
"is not at the beginning",
*p, operand_num);
3) parse_input_constraint parses also the corresponding output constraint
if the input constraint has a number as the only variant, but
even the comment removed in the following patch explains that it
doesn't work correctly and skips the first character; now, usually
that is not a big deal because if the first character of the output
constraint is = or + as it should, then the checking doesn't do anything;
but as 2) is just a warning, we accept it and then we fail to check it
4) far later on we parse the whole output constraint when input constraint
refers to it and assert it succeeds, which it doesn't due to 1), 2) and 3)
The following patch fixes the 3) spot, when switching to the output
constraint, instead of setting j = 0; and break; (== continue;) so that it
first does j += CONSTRAINT_LEN (constraint[0], constraint+0) and thus
usually starts at second, sometimes third character of the output constraint
it uses goto before the loop which sets j = 0; and doesn't do the j += ...
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2026-01-08 Jakub Jelinek <jakub@redhat.com>
PR middle-end/111817
* stmt.cc (parse_input_constraint): For matching construct, goto
before the loop without changing j instead of break. Remove comment
about that problem.
* c-c++-common/pr111817.c: New test.
Jakub
Comments
On Thu, 8 Jan 2026, Jakub Jelinek wrote: > Hi! > > The following invalid testcase ICEs, because we: > 1) for some strange reason ignore invalid punctuations in > parse_output_constraint, which has just > default: > if (!ISALPHA (*p)) > break; > compared to parse_input_constraint > default: > if (! ISALPHA (constraint[j])) > { > error ("invalid punctuation %qc in constraint", constraint[j]); > return false; > } > Haven't touched this because I fear it could break real-world code > 2) the checking whether = or + is first in the output constraint is > a warning only: > if (p != constraint) > warning (0, "output constraint %qc for operand %d " > "is not at the beginning", > *p, operand_num); > 3) parse_input_constraint parses also the corresponding output constraint > if the input constraint has a number as the only variant, but > even the comment removed in the following patch explains that it > doesn't work correctly and skips the first character; now, usually > that is not a big deal because if the first character of the output > constraint is = or + as it should, then the checking doesn't do anything; > but as 2) is just a warning, we accept it and then we fail to check it > 4) far later on we parse the whole output constraint when input constraint > refers to it and assert it succeeds, which it doesn't due to 1), 2) and 3) ICK. I wonder if it makes sense to be stricter with some flags? -pedantic isn't really applicable, maybe we want a -pedantic-gnu? > The following patch fixes the 3) spot, when switching to the output > constraint, instead of setting j = 0; and break; (== continue;) so that it > first does j += CONSTRAINT_LEN (constraint[0], constraint+0) and thus > usually starts at second, sometimes third character of the output constraint > it uses goto before the loop which sets j = 0; and doesn't do the j += ... > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. Thanks, Richard. > 2026-01-08 Jakub Jelinek <jakub@redhat.com> > > PR middle-end/111817 > * stmt.cc (parse_input_constraint): For matching construct, goto > before the loop without changing j instead of break. Remove comment > about that problem. > > * c-c++-common/pr111817.c: New test. > > --- gcc/stmt.cc.jj 2026-01-02 09:56:10.331333745 +0100 > +++ gcc/stmt.cc 2026-01-07 15:57:35.329401594 +0100 > @@ -508,6 +508,7 @@ parse_input_constraint (const char **con > unsigned int alt = 0; > unsigned long match = 0; > > +repeat: > for (j = 0; j < c_len; j += CONSTRAINT_LEN (constraint[j], constraint+j)) > switch (constraint[j]) > { > @@ -583,12 +584,7 @@ parse_input_constraint (const char **con > constraint = constraints[match]; > *constraint_p = constraint; > c_len = strlen (constraint); > - j = 0; > - /* ??? At the end of the loop, we will skip the first part of > - the matched constraint. This assumes not only that the > - other constraint is an output constraint, but also that > - the '=' or '+' come first. */ > - break; > + goto repeat; > } > else > j = end - constraint; > --- gcc/testsuite/c-c++-common/pr111817.c.jj 2026-01-07 17:07:23.449815574 +0100 > +++ gcc/testsuite/c-c++-common/pr111817.c 2026-01-07 17:10:47.408343658 +0100 > @@ -0,0 +1,9 @@ > +/* PR middle-end/111817 */ > +/* { dg-do compile } */ > + > +int > +foo (int x, int y) > +{ > + asm ("" : "\n=g" (x) : "0" (y)); /* { dg-warning "output constraint '=' for operand 0 is not at the beginning" } */ > + return x; /* { dg-error "invalid punctuation '\\\\x\[0-9a-zA-Z]*' in constraint" "" { target *-*-* } .-1 } */ > +} > > Jakub > >
--- gcc/stmt.cc.jj 2026-01-02 09:56:10.331333745 +0100 +++ gcc/stmt.cc 2026-01-07 15:57:35.329401594 +0100 @@ -508,6 +508,7 @@ parse_input_constraint (const char **con unsigned int alt = 0; unsigned long match = 0; +repeat: for (j = 0; j < c_len; j += CONSTRAINT_LEN (constraint[j], constraint+j)) switch (constraint[j]) { @@ -583,12 +584,7 @@ parse_input_constraint (const char **con constraint = constraints[match]; *constraint_p = constraint; c_len = strlen (constraint); - j = 0; - /* ??? At the end of the loop, we will skip the first part of - the matched constraint. This assumes not only that the - other constraint is an output constraint, but also that - the '=' or '+' come first. */ - break; + goto repeat; } else j = end - constraint; --- gcc/testsuite/c-c++-common/pr111817.c.jj 2026-01-07 17:07:23.449815574 +0100 +++ gcc/testsuite/c-c++-common/pr111817.c 2026-01-07 17:10:47.408343658 +0100 @@ -0,0 +1,9 @@ +/* PR middle-end/111817 */ +/* { dg-do compile } */ + +int +foo (int x, int y) +{ + asm ("" : "\n=g" (x) : "0" (y)); /* { dg-warning "output constraint '=' for operand 0 is not at the beginning" } */ + return x; /* { dg-error "invalid punctuation '\\\\x\[0-9a-zA-Z]*' in constraint" "" { target *-*-* } .-1 } */ +}