From patchwork Mon Mar 20 22:06:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 72491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1460876wrt; Mon, 20 Mar 2023 15:07:55 -0700 (PDT) X-Google-Smtp-Source: AK7set8dymICgqAwJhqEaPrblZ6rcs0m2pVTEtP6qAUNiss00Xk7nGrRnaAHoTMIeoeDDkhQo3Vh X-Received: by 2002:aa7:de82:0:b0:4fa:e187:64d1 with SMTP id j2-20020aa7de82000000b004fae18764d1mr908712edv.38.1679350074974; Mon, 20 Mar 2023 15:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679350074; cv=none; d=google.com; s=arc-20160816; b=buldPaaQie0noIBqRrjCSaXLXqB2Jw04V/yGi8M5DNN0omqCu9fs/asvS/Kg4v6Jms lmx0paZkwBpaRwLl83yxvdXoN/wLtHNGxoDJ2k6rRxqDoV57b2W72nN+P9wMEhcDc8oY j0kDae1LYS62V+zapW522fEzpF8nDkLP0NKK7Nfc81wehagmzz8/N7+5m8vHyg2B2Gp8 6+UM6a1Ps9c7w4CZLvZlhQ8+L4VzGzlGCwB9pIOVef72nWdmU99yQ3MUfnqQ4hlNLMt8 8GWgdnpBdF5EBVa/J/p655Xq9BgKDgzVWjLL8S8xWsK3B1JiiMCYO4JpIU3/cArkSC65 MdvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=CbYG+m+Rjeky9rofDmxjebkqUHxXcfbrjcOnga7IOlY=; b=aSnILtI4xclZrXNJbeGOxQ55VcbDSvdC2FjQtydCpJ9qwgp2mnmiWkam612gEC0eAE iS3p+24+rigwWeF0eEzsFcZIZyZyKRtbepe2bMeNJKat9d8mVXOqUw/eHSRAK5qG8zue Ou8u3XNSKoyGjSjMCfV/bu/FTdbOOCVaEZxgeMrRJfX99Ay9WlRnyhqI/qLcu5pSI4IR BF9nNZ6cHH6X/2AdaQcxC6AkaRNVUSGXWBGhlIBOMZlrRSVSlFg6F/12S3dH0CVruZrk yGWkLsS2pbkxWVt/mx0v6tRWEHlYWKTeHtXMmr3iNTX5a6f/Sc3F2vxQKPamNZmsEA8V dOdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Xq83+zL3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l6-20020aa7c3c6000000b00501cf6775dasi2438621edr.46.2023.03.20.15.07.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 15:07:54 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Xq83+zL3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3BAD385840D for ; Mon, 20 Mar 2023 22:07:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F3BAD385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679350074; bh=CbYG+m+Rjeky9rofDmxjebkqUHxXcfbrjcOnga7IOlY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Xq83+zL3VjyVrwfe7FH013qCOnG69tfQVX4LgEAvPbZ0kXy+gVl0NtPSeJxYnuFST RcGiE2suxH1BMpLImxa/87/gwQd4dKAvLTNp4aPKSz8tmT3yf/l8FV4ILhZtUEMXaN bPol/DWqDt/1TvolIeIpiD5653f3HSPOV4Ja8F7s= 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 ESMTPS id 48B5F3858401 for ; Mon, 20 Mar 2023 22:06:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 48B5F3858401 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-313-RTJ9LNUuORiZ9KXT6sBDBQ-1; Mon, 20 Mar 2023 18:06:27 -0400 X-MC-Unique: RTJ9LNUuORiZ9KXT6sBDBQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 834853814943 for ; Mon, 20 Mar 2023 22:06:27 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4623A1121315; Mon, 20 Mar 2023 22:06:26 +0000 (UTC) To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH] testsuite: always use UTF-8 in scan-sarif-file[-not] [PR105959] Date: Mon, 20 Mar 2023 18:06:25 -0400 Message-Id: <20230320220625.3877024-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760926184324946263?= X-GMAIL-MSGID: =?utf-8?q?1760926184324946263?= c-c++-common/diagnostic-format-sarif-file-4.c is a test case for quoting non-ASCII source code in a SARIF diagnostic log. The SARIF standard mandates that .sarif files are UTF-8 encoded. PR testsuite/105959 notes that the test case fails when the system encoding is not UTF-8, such as when the "make" invocation is prefixed with LC_ALL=C, whereas it works with in a UTF-8-locale. The root cause is that dg-scan opens the file for reading using the "system" encoding; I believe it is falling back to treating all files as effectively ISO 8859-1 in a non-UTF-8 locale. This patch fixes things by adding a mechanism to dg-scan to allow callers to (optionally) specify an encoding to use when reading the file, and updating scan-sarif-file (and the -not variant) to always use UTF-8 when calling dg-scan, fixing the test case with LC_ALL=C. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Manually verified the problematic testcases work with this with both LC_ALL=C and LC_ALL=en_US.UTF-8 OK for trunk? gcc/testsuite/ChangeLog: PR testsuite/105959 * gcc.dg-selftests/dg-final.exp (dg_final_directive_check_num_args): Update expected maximum number of args for the various directives using dg-scan. * lib/scanasm.exp (append_encoding_arg): New procedure. (dg-scan): Add optional 3rd argument: the encoding to use when reading from the file. * lib/scansarif.exp (scan-sarif-file): Treat the file as UTF-8 encoded when reading it. (scan-sarif-file-not): Likewise. Signed-off-by: David Malcolm --- gcc/testsuite/gcc.dg-selftests/dg-final.exp | 22 ++++++++++----------- gcc/testsuite/lib/scanasm.exp | 22 +++++++++++++++++++-- gcc/testsuite/lib/scansarif.exp | 13 +++++++++++- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/gcc/testsuite/gcc.dg-selftests/dg-final.exp b/gcc/testsuite/gcc.dg-selftests/dg-final.exp index e75fb45f44a..e34f29ab13a 100644 --- a/gcc/testsuite/gcc.dg-selftests/dg-final.exp +++ b/gcc/testsuite/gcc.dg-selftests/dg-final.exp @@ -104,17 +104,17 @@ proc dg_final_directive_check_num_args {} { global testname_with_flags set testname_with_flags "test.c" - verify_args scan-assembler 1 2 - verify_args scan-assembler-not 1 2 - verify_args scan-hidden 1 2 - verify_args scan-not-hidden 1 2 - verify_args scan-file 2 3 - verify_args scan-file-not 2 3 - verify_args scan-stack-usage 1 2 - verify_args scan-stack-usage-not 1 2 - verify_args scan-ada-spec 1 2 - verify_args scan-ada-spec-not 1 2 - verify_args scan-lto-assembler 1 2 + verify_args scan-assembler 1 3 + verify_args scan-assembler-not 1 3 + verify_args scan-hidden 1 3 + verify_args scan-not-hidden 1 3 + verify_args scan-file 2 4 + verify_args scan-file-not 2 5 + verify_args scan-stack-usage 1 3 + verify_args scan-stack-usage-not 1 3 + verify_args scan-ada-spec 1 3 + verify_args scan-ada-spec-not 1 3 + verify_args scan-lto-assembler 1 3 unset testname_with_flags } diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp index 4b018abcf3d..fb53544d40c 100644 --- a/gcc/testsuite/lib/scanasm.exp +++ b/gcc/testsuite/lib/scanasm.exp @@ -24,19 +24,33 @@ proc make_pattern_printable { pattern } { return [string map {\t \\t \n \\n \r \\r \\ \\\\} $pattern] } +# Append to ARGS to make it suitable for use by dg-scan to indicate +# that encoding ENC should be used when reading from the file. + +proc append_encoding_arg { args enc } { + if { [llength $args] < 2 } { + # Add target selector. + lappend args { target "*-*-*" } + } + # Add encoding ENC. + lappend args $enc + return $args +} + # Scan the OUTPUT_FILE for a pattern. If it is present and POSITIVE # is non-zero, or it is not present and POSITIVE is zero, the test # passes. The ORIG_ARGS is the list of arguments provided by dg-final # to scan-assembler. The first element in ORIG_ARGS is the regular # expression to look for in the file. The second element, if present, -# is a DejaGNU target selector. +# is a DejaGNU target selector. The third element, if present, is the +# encoding to use when reading from the file. proc dg-scan { name positive testcase output_file orig_args } { if { [llength $orig_args] < 1 } { error "$name: too few arguments" return } - if { [llength $orig_args] > 2 } { + if { [llength $orig_args] > 3 } { error "$name: too many arguments" return } @@ -59,6 +73,10 @@ proc dg-scan { name positive testcase output_file orig_args } { return } set fd [open $output_file r] + if { [llength $orig_args] >= 3 } { + set file_encoding [lindex $orig_args 2] + fconfigure $fd -encoding $file_encoding + } set text [read $fd] close $fd diff --git a/gcc/testsuite/lib/scansarif.exp b/gcc/testsuite/lib/scansarif.exp index d06390b854f..05524aa6e7a 100644 --- a/gcc/testsuite/lib/scansarif.exp +++ b/gcc/testsuite/lib/scansarif.exp @@ -17,7 +17,10 @@ # Various utilities for scanning SARIF output, used by gcc-dg.exp and # g++-dg.exp. # -# This is largely borrowed from scanasm.exp. +# This is largely borrowed from scanasm.exp, but tweaked to force Tcl +# to treat the file as UTF-8: section 3.1 of SARIF 2.1.0 +# ("File Format" > "General") specifies: "A SARIF log file SHALL be +# encoded in UTF-8 [RFC3629])". # Look for a pattern in the .sarif file produced by the compiler. See # dg-scan for details. @@ -27,6 +30,10 @@ proc scan-sarif-file { args } { # The name might include a list of options; extract the file name. set filename [lindex $testcase 0] set output_file "[file tail $filename].sarif" + + # Treat the file as UTF-8 encoded when reading it. + set args [append_encoding_arg $args "utf-8"] + dg-scan "scan-sarif-file" 1 $testcase $output_file $args } @@ -38,5 +45,9 @@ proc scan-sarif-file-not { args } { # The name might include a list of options; extract the file name. set filename [lindex $testcase 0] set output_file "[file tail $filename].sarif" + + # Treat the file as UTF-8 encoded when reading it. + set args [append_encoding_arg $args "utf-8"] + dg-scan "scan-sarif-file-not" 0 $testcase $output_file $args }