From patchwork Thu Aug 1 14:57:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1967814 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=QpBtJrBI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZXvp3Gt5z1ybV for ; Fri, 2 Aug 2024 01:29:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2D473861031 for ; Thu, 1 Aug 2024 15:29:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id A2A3C384F032 for ; Thu, 1 Aug 2024 15:00:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2A3C384F032 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A2A3C384F032 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524478; cv=none; b=HIFSKmrKJ2jL6ckWVdOXR/9bIkeyxMcQOMVQxcJJv9xA0/dGWorpjc8TBYgOY9LmDLD+EUXoByhKYMSgFmUSd5ISjwa4gm69ngCsegnz6j3pKT6VQx07uTYohy23RxxYTP6GQfIWxUg9JzI1TluIITHL92Y6RtkusEMYpXFS9XA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524478; c=relaxed/simple; bh=m5GkShSUg9Ynga9Q1MaKF5tR8jXaYMjbdN1RCIZn3Wo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gXgoVmMleRcmmq374u1jjpYQFulo1buxtjWys0RwnDPCurFC2fSFVtOwDgmu640ZiWtPsKz/yTMUfUaJxB39VoRcW/NyedMLnOFu+lSOGursdmj5mnwWpwndoqauCcZA5qtqrTyLVA1FRciaIzINyyKfkQDkHGE63LnJG4g7gL0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-52f04150796so11606533e87.3 for ; Thu, 01 Aug 2024 08:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524432; x=1723129232; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hK7YSvkkLO29ZdkD6m7Oiya8tDUiIKqlGjDbpX+B+6I=; b=QpBtJrBIaO2MvQ/Ktt+tpXdUG6nJNhgSzQKaGlkXNQlqqCISvqoDag3zf1scAWn33w z6hceOgjBSKEYZTNjoQyrVRb1BZ2JRf/QHFq6K6BJ5XTvOJrbh/dzp08uCDbQ8/Ro9ue jEY+YeNmNPMOFkq0wvE0oOY5pNrWFRruciWzVgLX2G69uOPmrFSVfcLBoFcnplJRdCFq BF0lW4FYLPIrCDfQCPyu31JgHcp+aY2/sOpHC2F1K1wCVQE36f5qOI0VFQwbhCugzNPR U39SzqhSVEIgwNi1O4Ah5B4IGwxeRhFz8P3FtHw7HJ7W5U8etVOTlDru+0/qMEs6fX3D 0u4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524432; x=1723129232; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hK7YSvkkLO29ZdkD6m7Oiya8tDUiIKqlGjDbpX+B+6I=; b=c4Pb6DP09wwH+7yFLhwOuJaQ/MJoJCb9MN97GokU5HkQkAlaiVMqRE2Ra5kZqmpykG Lm9R1xCsfSGeKiy4jxFiYtnRIBXs9LBBQKZyPYbfIOOV9T2QjjkfMspDjtMxXiIgiX5f iwWjcsQyHV3AWQrug/1d22kqwkYITHsE9ed9vQnWnFj3eY8u3UL4oX/U2wk97VUgKszi BOJQVoRd8ivWi2m5/ZRSM+gOHdao/x1X+j2wTgU3pVQ45WG7wUTpSCEtD2OWrmbSaUxn WYhs+SfMWZZfRGx+r3ZSeSRql6h9+y0RlX6/VxmN/7H9QYGU7cRq9g9xSmsOXU5Tr/b9 c2ew== X-Gm-Message-State: AOJu0YzlFFa+Hy0UU4T/oNObO7gOIJJbvkrJxnBlXCtLJ60Jqbokvyug SIy1BXXA26gfDc1d1Q8t0AwAlR16hA8xjcX00lLZjK3B6bV9BinIDOnMMyJ2SSUh5b9OJnLFfRA SAwOu X-Google-Smtp-Source: AGHT+IGFD7+j0i7uGFJlwdkUm6veeSK7jiCfbKboGcjs9MHXWvvivTMxWIWt/TOOd0lUolh3ySpMCQ== X-Received: by 2002:a05:6512:2805:b0:52e:93da:f921 with SMTP id 2adb3069b0e04-530bb36fe59mr130472e87.19.1722524431646; Thu, 01 Aug 2024 08:00:31 -0700 (PDT) Received: from platypus.lan ([2a04:cec2:9:dc84:3622:6733:ff49:ee91]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590592sm10252456a12.25.2024.08.01.08.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:00:31 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [PATCH 107/125] gccrs: Improve parsing of raw string literals Date: Thu, 1 Aug 2024 16:57:43 +0200 Message-ID: <20240801145809.366388-109-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801145809.366388-2-arthur.cohen@embecosm.com> References: <20240801145809.366388-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org From: Owen Avery gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_raw_string): Bring handling of edge cases to par with parse_raw_byte_string. gcc/testsuite/ChangeLog: * rust/compile/raw-string-loc.rs: New test. Signed-off-by: Owen Avery --- gcc/rust/lex/rust-lex.cc | 21 +++++++++++++++++--- gcc/testsuite/rust/compile/raw-string-loc.rs | 6 ++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/rust/compile/raw-string-loc.rs diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 7c37e83d6cb..e5c9148976c 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -2152,6 +2152,9 @@ Lexer::parse_raw_string (location_t loc, int initial_hash_count) str.reserve (16); // some sensible default int length = 1 + initial_hash_count; + current_column += length; + + const location_t string_begin_locus = get_current_location (); if (initial_hash_count > 0) skip_input (initial_hash_count - 1); @@ -2162,10 +2165,11 @@ Lexer::parse_raw_string (location_t loc, int initial_hash_count) rust_error_at (get_current_location (), "raw string has no opening %<\"%>"); length++; + current_column++; skip_input (); current_char = peek_input (); - while (!current_char.is_eof ()) + while (true) { if (current_char.value == '"') { @@ -2186,19 +2190,30 @@ Lexer::parse_raw_string (location_t loc, int initial_hash_count) skip_input (initial_hash_count); current_char = peek_input (); length += initial_hash_count + 1; + current_column += initial_hash_count + 1; break; } } + else if (current_char.is_eof ()) + { + rust_error_at (string_begin_locus, "unended raw string literal"); + return Token::make (END_OF_FILE, get_current_location ()); + } length++; + current_column++; + if (current_char == '\n') + { + current_line++; + current_column = 1; + start_line (current_line, max_column_hint); + } str += current_char.as_string (); skip_input (); current_char = peek_input (); } - current_column += length; - loc += length - 1; str.shrink_to_fit (); diff --git a/gcc/testsuite/rust/compile/raw-string-loc.rs b/gcc/testsuite/rust/compile/raw-string-loc.rs new file mode 100644 index 00000000000..70977510ba3 --- /dev/null +++ b/gcc/testsuite/rust/compile/raw-string-loc.rs @@ -0,0 +1,6 @@ +const X: &'static str = r#"12 +12"#; + +BREAK +// { dg-error "unrecognised token" "" { target *-*-* } .-1 } +// { dg-excess-errors "error 'failed to parse item' does not have location" }