From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 66DD8384F4BE for ; Thu, 1 Aug 2024 15:00:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66DD8384F4BE 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 66DD8384F4BE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524474; cv=none; b=V9Jqo9yvbEbUN4MI9UbVekzJZ+SzS0QwyFpDCDoQ/5PZHcn/o2gjgoM+uvnoKXDuuUS8qqp3Cr38eS3fdllcyl2cFa5C2rEeNb45ZlS7GxxMhtHt5Hmt5kn7ort9HITg/lN2vlNUVsGxGGvReaoDxhniVAMSdY+wO7+o2YkODAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524474; c=relaxed/simple; bh=6rky3Z6yEBJXfoVG53cql4j0t8J75c0ts9HTVZlcJbg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=F3O+HYpg6Zof0dP832LoqnYRRuEYaxNdMhTXM1PnV9ECaa6wq8GJlGzer4BLdFjFsQQPXrkG1O5s1vUkxtwNk5zv60cIOKeF5z4m88EhEyY5pQT/nAxpMlXcIjidAtMK1BppcOThb8N/fFPiiUwYlUIcGegpXHORxacasugeN/g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-52efa9500e0so8612927e87.3 for ; Thu, 01 Aug 2024 08:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524430; x=1723129230; 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=n67vWGSR96H6pQS8ZV+SCYIoMDiz68wQxRFVWyb2HeQ=; b=Jla85DZDfHt4434OBroEIvLB1aOY/tHj0nyHBWObFmNFz3dpBVGF4manYcBjdfTcLu GkzTnED70UB9k14LYE34YrV5Um9Dr9Bi3DqtIamNH1HshSYoh6c5vjSy7AmJHvV2n8UG 5trcexuAkO78cgq7PlYHEeKzyRT93gORpX6wPwMQsWqDQQfilW5AKud2PRY1EKSVdudY CjTVm+EatBGXSdGnnLd7Zz+6gBz8hGMAY4b+Auk8GQ047+VSjZI5feWKyQ0cLhoLF4vQ cl3g+ViLaPRiOeaBSLf1jHotfwXquvMT82O5peyxGc4MXF22RByvPOPmntMj8nqVk9ar 11Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524430; x=1723129230; 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=n67vWGSR96H6pQS8ZV+SCYIoMDiz68wQxRFVWyb2HeQ=; b=VwohAp8+jR2dt+tImuLvkjV2rlZC7M9jXN9C9saWjp66HU9qbi7+qExnkxmzDrzq+Y OkLHBh4C/1mtyCPXccNs0shGRDWPb9HMilVmwkZd2o9MDxrGz4bKlnAyfHYV9QhzZimP 6uFYRPDYt9FptTJG30wCxB9W7lLCzL0vn37BIzmW6CPv61CYGySb5ladnFyVfP0KHPCn T4vO+NUMXn6ORn7zLUJwSraZEwCHcyrUrop/qQRupeTnHPLKl/Y5eH3Za1MurgNPRLj6 kySA5dOp9J3R5Eaj1BFkAl00RKGiM5DqRLPN3mwlntaphe9rqyoRiGxENmUNh6oValkl WS9A== X-Gm-Message-State: AOJu0YzvWo533iFoS9l5XG59pntVtAtCJBlI8ECLyqd3/3fpuuJGz5gW oTkYbPpCUqH9v75knBkZh1sU6Mo9DZ4za+UIfaJPdch0nyJc9DFa82dq+cKbf/9uiDBAv4GpKoL MpYQB X-Google-Smtp-Source: AGHT+IG15LCwS0J1WBcLpOI7MXnnS3SY39T4/YwyhcD1XBShVmP7zQMZA9bdSqJZ5lqhLPooR2n1WQ== X-Received: by 2002:a05:6512:3403:b0:52c:9e25:978d with SMTP id 2adb3069b0e04-530bb39d102mr105363e87.45.1722524429422; Thu, 01 Aug 2024 08:00:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:00:29 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [PATCH 103/125] gccrs: Improve parsing of raw byte string literals Date: Thu, 1 Aug 2024 16:57:39 +0200 Message-ID: <20240801145809.366388-105-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 Content-Transfer-Encoding: 8bit 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 List-Id: From: Owen Avery gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_raw_byte_string): Bring handling of edge cases to par with parse_byte_string. gcc/testsuite/ChangeLog: * rust/compile/raw-byte-string-loc.rs: New test. Signed-off-by: Owen Avery --- gcc/rust/lex/rust-lex.cc | 23 +++++++++++++++---- .../rust/compile/raw-byte-string-loc.rs | 6 +++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/rust/compile/raw-byte-string-loc.rs diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 9c2203160cd..7c37e83d6cb 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -1840,14 +1840,18 @@ Lexer::parse_raw_byte_string (location_t loc) int length = 1; int hash_count = 0; + const location_t string_begin_locus = get_current_location (); + // get hash count at beginnning skip_input (); current_char = peek_input (); length++; + current_column++; while (current_char == '#') { hash_count++; length++; + current_column++; skip_input (); current_char = peek_input (); @@ -1862,6 +1866,7 @@ Lexer::parse_raw_byte_string (location_t loc) skip_input (); current_char = peek_input (); length++; + current_column++; while (true) { @@ -1884,27 +1889,37 @@ Lexer::parse_raw_byte_string (location_t loc) skip_input (hash_count); current_char = peek_input (); length += hash_count + 1; + current_column += hash_count + 1; break; } } - - if (current_char.value > 127) + else if (current_char.value > 127) { rust_error_at (get_current_location (), "character %<%s%> in raw byte string out of range", current_char.as_string ().c_str ()); current_char = 0; } + else if (current_char.is_eof ()) + { + rust_error_at (string_begin_locus, "unended raw byte 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; skip_input (); current_char = peek_input (); } - current_column += length; - loc += length - 1; str.shrink_to_fit (); diff --git a/gcc/testsuite/rust/compile/raw-byte-string-loc.rs b/gcc/testsuite/rust/compile/raw-byte-string-loc.rs new file mode 100644 index 00000000000..f37d3f9694d --- /dev/null +++ b/gcc/testsuite/rust/compile/raw-byte-string-loc.rs @@ -0,0 +1,6 @@ +const X: &'static u8 = br#"12 +12"#; + +BREAK +// { dg-error "unrecognised token" "" { target *-*-* } .-1 } +// { dg-excess-errors "error 'failed to parse item' does not have location" } -- 2.45.2