From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 0FD8138618AB for ; Thu, 15 Feb 2024 15:58:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0FD8138618AB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0FD8138618AB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708012717; cv=none; b=TsYwLoafIbwhAn8oUYS7+07GmVo4FT4Hx1eZrjBLlZnrDy8KKci6MbO2o+x1aZnzpSqqkh3CTmOdTv91LT8tWCHSxQB+rB/wFdnFzKUU/6WKOi9d9pz8Wc31zf5W2j+RmawP3GkKzD0G6XWfEfzMuOxKHdMqhI2aablcyPrVqGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708012717; c=relaxed/simple; bh=DJlWP975UPZ72oY0GuOWZbIsA8hgmytIfhMMlTtQ8To=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=dFezG6hQ+0btckaa26k2EvnIUtrBBneqc8X3af4Vxtz4OPDLgR7Y36VZczVqFropRPKxWUbSiJ0GjgdVdmMmdqQNFn+JhNkLjWh+Suu5y3NIb4owp749JSLXG3/U/Hgg604D0IVu1GFxUQjDNqCZNlNd0O7WqeAwhIMNq7B0aGU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41FFleu3014635 for ; Thu, 15 Feb 2024 15:58:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Z5LLdPo92KfTyd92D8AUwdm6aKFRzO9h1MK17wCqVsA=; b=sg+wFQdRXlfrtLyaICdDBKW5k6ki8h9nvuGn0mvoCbo9w03kUs+4wj+2vjkm4RoR8Ty2 Hv7Ra3LwkB2N/vMCIUaWDeOn50kspr/4DGUsz7xIVM9AttLd4uejbLudwf/b5n70AnUk /QwK4T9iUk66nmK0Vx5LIUFLWHDcu4AX1VYGf5mL/PPhPeerH6hlV4yT6206npJ6lN3Z u2YEGSCD2QYKjZMlLggvfCLrnbZtFRQk1NTnz/TB+Kl7+nhhd2TPooU8+Ed68nVtenUs qJfVHmIRWLwUODRzawcyJA661T7lmOEqEsP1wDOafzcHqmoV5LwlpZEjHMsgNUCwlJwq 8g== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w9nje872d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 15 Feb 2024 15:58:34 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41FDjPSK024888 for ; Thu, 15 Feb 2024 15:58:33 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w6mfpnq67-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 15 Feb 2024 15:58:33 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41FFwShp25494236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Feb 2024 15:58:30 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 894152004E; Thu, 15 Feb 2024 15:58:28 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 643A12004F; Thu, 15 Feb 2024 15:58:28 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 15 Feb 2024 15:58:28 +0000 (GMT) From: Jens Remus To: binutils@sourceware.org Cc: Jens Remus , Andreas Krebbel Subject: [PATCH 03/14] s390: Do not erroneously use base operand value for length operand Date: Thu, 15 Feb 2024 16:58:10 +0100 Message-Id: <20240215155821.4065623-4-jremus@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240215155821.4065623-1-jremus@linux.ibm.com> References: <20240215155821.4065623-1-jremus@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: QIlDxuu0ykqEMF1ZojTDPd5LGxlDcKDu X-Proofpoint-GUID: QIlDxuu0ykqEMF1ZojTDPd5LGxlDcKDu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-15_14,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 phishscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1015 malwarescore=0 spamscore=0 impostorscore=0 mlxlogscore=978 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402150129 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The base register operand B may optionally be omitted in D(B) by coding D and in D(L,B) by coding D(L). The index register operand X may optionally be omitted in D(X,B) by coding D(,B) or D(B). Both base and index register operands may optionally be omitted in D(X,B) by coding D. In any case the omitted base and/or index register operand value defaults to zero. When parsing an erroneously omitted length L operand in D(L,B) by coding D(,B) the base register operand B was erroneously consumed as length operand. When using a register name for the base register operand this was detected and reported as error. But when not using a register name the base register operand value was erroneously used as length operand value. Correct the parsing of an omitted optional base or index register to not erroneously use the base register operand value as length, when erroneously omitting the length operand. While at it rename the variable used to remember whether the base or index register operand was omitted to enhance code readability. Additionally add test cases for the optional omission of base and/or index register operands. Example assembler source: mvc 16(1,%r1),32(%r2) mvc 16(1),32(%r2) mvc 16(,1),32(%r2) # undetected syntax error Disassembly of bad assembly without commit shows the base register operand value was erroneously used as length operand value: 0: d2 00 10 10 20 20 mvc 16(1,%r1),32(%r2) 6: d2 00 00 10 20 20 mvc 16(1,%r0),32(%r2) c: d2 00 00 10 20 20 mvc 16(1,%r0),32(%r2) Assembler messages with commit: 3: Error: operand 1: missing operand gas/ * config/tc-s390.c: Correct parsing of omitted base register. * testsuite/gas/s390/s390.exp: Add test cases for omitted base and/or index register. * testsuite/gas/s390/zarch-omitted-base-index.s: Test cases for omitted optional base or index register. * testsuite/gas/s390/zarch-omitted-base-index.d: Likewise. * testsuite/gas/s390/zarch-omitted-base-index-err.s: Test cases for omitted base and/or index register. * testsuite/gas/s390/zarch-omitted-base-index-err.l: Likewise. Reviewed-by: Andreas Krebbel Signed-off-by: Jens Remus --- gas/config/tc-s390.c | 35 ++++++++++--------- gas/testsuite/gas/s390/s390.exp | 2 ++ .../gas/s390/zarch-omitted-base-index-err.l | 24 +++++++++++++ .../gas/s390/zarch-omitted-base-index-err.s | 20 +++++++++++ .../gas/s390/zarch-omitted-base-index.d | 22 ++++++++++++ .../gas/s390/zarch-omitted-base-index.s | 24 +++++++++++++ 6 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 gas/testsuite/gas/s390/zarch-omitted-base-index-err.l create mode 100644 gas/testsuite/gas/s390/zarch-omitted-base-index-err.s create mode 100644 gas/testsuite/gas/s390/zarch-omitted-base-index.d create mode 100644 gas/testsuite/gas/s390/zarch-omitted-base-index.s diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c index 019f26b2f4ab..cfe98b5e94be 100644 --- a/gas/config/tc-s390.c +++ b/gas/config/tc-s390.c @@ -1268,16 +1268,15 @@ md_gather_operands (char *str, expressionS ex; elf_suffix_type suffix; bfd_reloc_code_real_type reloc; - int skip_optional; + int omitted_base_or_index; char *f; int fc, i; while (ISSPACE (*str)) str++; - skip_optional = 0; - /* Gather the operands. */ + omitted_base_or_index = 0; /* Whether B in D(L,B) or X in D(X,B) were omitted. */ fc = 0; for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) { @@ -1294,13 +1293,13 @@ md_gather_operands (char *str, break; } - if (skip_optional && (operand->flags & S390_OPERAND_INDEX)) + if (omitted_base_or_index && (operand->flags & S390_OPERAND_INDEX)) { - /* We do an early skip. For D(X,B) constructions the index - register is skipped (X is optional). For D(L,B) the base - register will be the skipped operand, because L is NOT - optional. */ - skip_optional = 0; + /* Skip omitted optional index register operand in D(X,B) due to + D(,B) or D(B). Skip comma, if D(,B). */ + if (*str == ',') + str++; + omitted_base_or_index = 0; continue; } @@ -1510,17 +1509,19 @@ md_gather_operands (char *str, for (f = str; *f != '\0'; f++) if (*f == ',' || *f == ')') break; - /* If there is no comma until the closing parentheses OR - there is a comma right after the opening parentheses, - we have to skip optional operands. */ + /* If there is no comma until the closing parenthesis ')' or + there is a comma right after the opening parenthesis '(', + we have to skip the omitted optional index or base register + operand: + - Index X in D(X,B), when D(,B) or D(B) + - Base B in D(L,B), when D(L) */ if (*f == ',' && f == str) { - /* comma directly after '(' ? */ - skip_optional = 1; - str++; + /* Comma directly after opening parenthesis '(' ? */ + omitted_base_or_index = 1; } else - skip_optional = (*f != ','); + omitted_base_or_index = (*f != ','); } } else if (operand->flags & S390_OPERAND_BASE) @@ -1530,7 +1531,7 @@ md_gather_operands (char *str, as_bad (_("syntax error; missing ')' after base register")); else str++; - skip_optional = 0; + omitted_base_or_index = 0; if (*str == '\0' && skip_optargs_p (opcode->flags, &opindex_ptr[1])) continue; diff --git a/gas/testsuite/gas/s390/s390.exp b/gas/testsuite/gas/s390/s390.exp index 86e2dd492cd1..7fbc7f8a7515 100644 --- a/gas/testsuite/gas/s390/s390.exp +++ b/gas/testsuite/gas/s390/s390.exp @@ -44,4 +44,6 @@ if [expr [istarget "s390-*-*"] || [istarget "s390x-*-*"]] then { run_list_test "machine-parsing-4" "" run_list_test "machine-parsing-5" "" run_list_test "machine-parsing-6" "" + run_dump_test "zarch-omitted-base-index" "{as -m64}" + run_list_test "zarch-omitted-base-index-err" "" } diff --git a/gas/testsuite/gas/s390/zarch-omitted-base-index-err.l b/gas/testsuite/gas/s390/zarch-omitted-base-index-err.l new file mode 100644 index 000000000000..fe13f95d3174 --- /dev/null +++ b/gas/testsuite/gas/s390/zarch-omitted-base-index-err.l @@ -0,0 +1,24 @@ +.*: Assembler messages: +.*:5: Error: bad expression +.*:5: Error: syntax error; missing '\)' after base register +.*:8: Error: bad expression +.*:8: Error: syntax error; missing '\)' after base register +.*:9: Error: bad expression +.*:9: Error: syntax error; missing '\)' after base register +.*:12: Error: bad expression +.*:12: Error: syntax error; missing '\)' after base register +.*:13: Error: bad expression +.*:13: Error: syntax error; missing '\)' after base register +.*:16: Error: missing operand +.*:17: Error: missing operand +.*:18: Error: invalid length field specified +.*:19: Error: bad expression +.*:19: Error: operand out of range \(0 is not between 1 and 256\) +.*:19: Error: operand out of range \(32 is not between 0 and 15\) +.*:19: Error: syntax error; missing '\)' after base register +.*:19: Error: syntax error; expected ',' +.*:19: Error: bad expression +.*:19: Error: found 'r', expected: '\)' +.*:19: Error: syntax error; missing '\)' after base register +.*:19: Error: junk at end of line: `r2\)' +.*:20: Error: syntax error; missing '\(' after displacement diff --git a/gas/testsuite/gas/s390/zarch-omitted-base-index-err.s b/gas/testsuite/gas/s390/zarch-omitted-base-index-err.s new file mode 100644 index 000000000000..65ad739d02c6 --- /dev/null +++ b/gas/testsuite/gas/s390/zarch-omitted-base-index-err.s @@ -0,0 +1,20 @@ +.text +foo: + +# R1,D2(B2) + clm %r1,0b1000,16() + +# R1,D2(X2,B2) + a %r1,16(%r2,) + a %r1,16() + +# V1,D2(VX2,B2),M3 + vgef %v1,16(%v2,),0 + vgef %v1,16(),0 + +# D1(L1,B1),D2(B2) + mvc 16(,%r1),32(%r2) + mvc 16(,1),32(%r2) + mvc 16(%r1),32(%r2) + mvc 16(),32(%r2) + mvc 16,32(%r2) diff --git a/gas/testsuite/gas/s390/zarch-omitted-base-index.d b/gas/testsuite/gas/s390/zarch-omitted-base-index.d new file mode 100644 index 000000000000..b2ff292628b1 --- /dev/null +++ b/gas/testsuite/gas/s390/zarch-omitted-base-index.d @@ -0,0 +1,22 @@ +#name: s390x omit base/index register +#objdump: -dr + +.*: +file format .* + +Disassembly of section .text: + +.* : +.*: bd 18 20 10 [ ]*clm %r1,8,16\(%r2\) +.*: bd 18 00 10 [ ]*clm %r1,8,16 +.*: 5a 12 30 10 [ ]*a %r1,16\(%r2,%r3\) +.*: 5a 10 30 10 [ ]*a %r1,16\(%r3\) +.*: 5a 10 30 10 [ ]*a %r1,16\(%r3\) +.*: 5a 10 00 10 [ ]*a %r1,16 +.*: e7 12 30 10 00 13 [ ]*vgef %v1,16\(%v2,%r3\),0 +.*: e7 10 30 10 00 13 [ ]*vgef %v1,16\(%r3\),0 +.*: e7 10 30 10 00 13 [ ]*vgef %v1,16\(%r3\),0 +.*: e7 10 00 10 00 13 [ ]*vgef %v1,16,0 +.*: d2 00 10 10 20 20 [ ]*mvc 16\(1,%r1\),32\(%r2\) +.*: d2 00 10 10 00 20 [ ]*mvc 16\(1,%r1\),32 +.*: d2 00 00 10 20 20 [ ]*mvc 16\(1,%r0\),32\(%r2\) +.*: d2 00 00 10 00 20 [ ]*mvc 16\(1,%r0\),32 diff --git a/gas/testsuite/gas/s390/zarch-omitted-base-index.s b/gas/testsuite/gas/s390/zarch-omitted-base-index.s new file mode 100644 index 000000000000..8381319068bc --- /dev/null +++ b/gas/testsuite/gas/s390/zarch-omitted-base-index.s @@ -0,0 +1,24 @@ +.text +foo: + +# R1,D2(B2) + clm %r1,0b1000,16(%r2) + clm %r1,0b1000,16 + +# R1,D1(X2,B2) + a %r1,16(%r2,%r3) + a %r1,16(,%r3) + a %r1,16(%r3) + a %r1,16 + +# V1,D2(VX2,B2),M3 + vgef %v1,16(%v2,%r3),0 + vgef %v1,16(,%r3),0 + vgef %v1,16(%r3),0 + vgef %v1,16,0 + +# D1(L1,B1),D2(B2) + mvc 16(1,%r1),32(%r2) + mvc 16(1,%r1),32 + mvc 16(1),32(%r2) + mvc 16(1),32 -- 2.40.1