{"id":2226539,"url":"http://patchwork.ozlabs.org/api/patches/2226539/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/1954864.tdWV9SEqCh@arcturus/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1954864.tdWV9SEqCh@arcturus>","list_archive_url":null,"date":"2026-04-22T15:22:37","name":"[Ada] Fix problematic trailing separator for Ada.Directories.Containing_Directory","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"30c5654df44356836b9f84dbd73acf2a1f31dc55","submitter":{"id":78832,"url":"http://patchwork.ozlabs.org/api/people/78832/?format=json","name":"Eric Botcazou","email":"botcazou@adacore.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/1954864.tdWV9SEqCh@arcturus/mbox/","series":[{"id":501032,"url":"http://patchwork.ozlabs.org/api/series/501032/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=501032","date":"2026-04-22T15:22:37","name":"[Ada] Fix problematic trailing separator for Ada.Directories.Containing_Directory","version":1,"mbox":"http://patchwork.ozlabs.org/series/501032/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2226539/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226539/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256\n header.s=google header.b=B6LQPC7k;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256\n header.s=google header.b=B6LQPC7k","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=adacore.com","sourceware.org; spf=pass smtp.mailfrom=adacore.com","server2.sourceware.org;\n arc=none smtp.remote-ip=209.85.221.46"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g12zn3TDlz1yD5\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 01:23:16 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 354DB4BB592C\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 15:23:14 +0000 (GMT)","from mail-wr1-f46.google.com (mail-wr1-f46.google.com\n [209.85.221.46])\n by sourceware.org (Postfix) with ESMTPS id 596614BB5915\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 15:22:40 +0000 (GMT)","by mail-wr1-f46.google.com with SMTP id\n ffacd0b85a97d-43cfbd17589so4474324f8f.0\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 08:22:40 -0700 (PDT)","from arcturus.localnet ([37.166.89.92])\n by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-43fe4cc375dsm42031245f8f.14.2026.04.22.08.22.38\n for <gcc-patches@gcc.gnu.org>\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 22 Apr 2026 08:22:38 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 354DB4BB592C","OpenDKIM Filter v2.11.0 sourceware.org 596614BB5915"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 596614BB5915","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 596614BB5915","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776871360; cv=none;\n b=FER5P9+SNzte58BPadPrgYDchZdwFW9mHeQ8RkW7ZVgTvBtZP3U0AdrtcszMrqweGOkl1W+f5toPMjm4JCb1BVGcLrd/dHBe2wAfP4RYe2m8SUMSJimSMq04A+BtMqgsJJ5bJXWEGCtM1Ju25Cu82oH+royjym4OaOiiH77sii0=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776871360; c=relaxed/simple;\n bh=Dk2AMCr6ZxyaVSNz1ScaEZbZ+QKPcI3wUA3XwOUe85A=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=QWWVnpwNrq6kJ6SeO8dSU9XwaZ2bu43mAIpNYgY++7O3OUhjtQmZy6fcnZuZpT0T4bFb1e9kFHFTIG3M0AcarVfxkzDj7ripsHVARFE+xogGbxeHGZBWMrYJR1jVbbbQT4ljdw2hkJHu0r17n7HNb5zTZ9SJfE3hcvyTChSOhKo=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=adacore.com; s=google; t=1776871359; x=1777476159; darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:message-id:date:subject:to\n :from:from:to:cc:subject:date:message-id:reply-to;\n bh=sy4EudYP7VxkMobquVOkG2QnOUZ8mG4f1L52lwiuLdc=;\n b=B6LQPC7k+6bBGNtoAi1GPWJdw/Jke9rMnq9vBlrAM7GZ0pZDUk3hs1AAAKJMhQWKDW\n k9T8hPg429dsk5JjrXFRjk6oMS5KFBIE9QVL8IQnXQXDB1cUP0RBQ+FkOyBowr97jNp5\n nRYiotvY0uFRPJI93LcQtgchDNlAfr9AED7TkbQFa8HGXxC1KkrB5Oh94kVO82PUFfbI\n R27xx3Y27/uEf/Pg0YBNpG3aF1ijtegWjm8iKvRXPP6ZoYZddMZ7TvwGVhdlRRX53KPM\n 2fHaqqT8hB9GLqzwd6reG+x5T7VkOuNd0j2Jz72ZFxhONVl3hWUdrjBt02m15cMv8nk6\n ii3w==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776871359; x=1777476159;\n h=content-transfer-encoding:mime-version:message-id:date:subject:to\n :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=sy4EudYP7VxkMobquVOkG2QnOUZ8mG4f1L52lwiuLdc=;\n b=N89ttH0ZxLdLk1iHx8Bn5TY/jIRjKXoX48zNpcPghcBTzzQy0z9i5Q/KjAU0XO+/dv\n urRJZdn5/8O6ZwBq5qKgOwI9iv55uBr/H8/g2K5rKJ9FFcO0RcQihEpFnd7noi4plj8E\n ux+5nz8xa9X9EHUTpeERqtkgQiAKmkiLtRyYNliWcekOacP+Q7ydi1lHxZamShZFP7/v\n ukLz3OGWGmz/x5OWbo1svNYkarA1H3BZkVpGr1snnPTLbS2FRIhLmqNGfBFThGUsMrn/\n sCpsguqGSi7brmx9XVpagwnxnrG+N43aI8OuXAsfDogSwNWFPKvMXtMADWyKUG5YkyPd\n idIg==","X-Gm-Message-State":"AOJu0YzFLki9vPXL72SDf0NCqGkuO7TkY1U6IFPfCuW/grzaZEynmdNn\n bsJ+iYvQuRXIWguGXy6QJGqnmNrOTygRlZU6WrYXISJd9G+PXxgfDrghCWTG11nIaaa6AhVsFPS\n gvtE=","X-Gm-Gg":"AeBDievKzZp9AJxwijk4osFV61aMgBp2jw200CfHJJEEcodZ2++PbgUGVu4S+qIcSyi\n e4CLnCAcc9g31GQxdUvzhnyS/14DyYA6V4IOEqAtC+yH5Q4qBUUwFLJf7EUreLi/sfDMO95aCkz\n b/ovgtO44RuwPE1XYwD/dtOWd7eB62Dy4ynHqAKRx4Xg90qwJK6ds7HmdCrBz4fQcWLC4v+Simr\n IHYoFZP8AGoL4/OvQvQwdWzeLNg6egfWZKICz20Rb1XjT9yvQDKGRcLBYMpqu7WDQ/R8WhgOW8K\n LOPbcRlljS2PpQgUtUIwflN52fuYPI0kZoplNmJQFZDoHRuoz6k/K9JKdnLbthXdA7A9RF0if8G\n 30zRxO0H7kWXWgzE6+AP3hzO/MONBjX4yf5NA9XLlN5ZyFcxaFtyjBrjAvuuEYMfirJoO2ts860\n J5WVySRLrfvIxPgXqQ3FWvgwApL+2EpL9BH+EVCwKJ","X-Received":"by 2002:a5d:5f89:0:b0:441:1cf9:4f06 with SMTP id\n ffacd0b85a97d-4411cf94f2cmr15039562f8f.31.1776871359114;\n Wed, 22 Apr 2026 08:22:39 -0700 (PDT)","From":"Eric Botcazou <botcazou@adacore.com>","X-Google-Original-From":"Eric Botcazou <ebotcazou@adacore.com>","To":"gcc-patches@gcc.gnu.org","Subject":"[Ada] Fix problematic trailing separator for\n Ada.Directories.Containing_Directory","Date":"Wed, 22 Apr 2026 17:22:37 +0200","Message-ID":"<1954864.tdWV9SEqCh@arcturus>","MIME-Version":"1.0","Content-Type":"multipart/mixed; boundary=\"nextPart2262180.irdbgypaU6\"","Content-Transfer-Encoding":"7Bit","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>,\n <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>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"Adding a trailing directory separator should arguably not change the result of \na call to Ada.Directories.Containing_Directory.\n\nTested on x86-64/Linux, applied on the mainline.\n\n\n2026-04-22  Eric Botcazou  <ebotcazou@adacore.com>\n\n\tPR ada/85766\n\t* libgnat/a-direct.adb (Containing_Directory): Streamline and strip\n\ta trailing directory separator from the name.\n\n\n2026-04-22  Eric Botcazou  <ebotcazou@adacore.com>\n\n\t* gnat.dg/directory1.adb: New test.","diff":"diff --git a/gcc/ada/libgnat/a-direct.adb b/gcc/ada/libgnat/a-direct.adb\nindex 567fe44ec68..971790c1b95 100644\n--- a/gcc/ada/libgnat/a-direct.adb\n+++ b/gcc/ada/libgnat/a-direct.adb\n@@ -228,27 +228,36 @@ package body Ada.Directories is\n       if not Is_Valid_Path_Name (Name) then\n          raise Name_Error with \"invalid path name \"\"\" & Name & '\"';\n \n+      --  Second, If Name indicates a root directory, raise Use_Error, because\n+      --  it has no containing directory.\n+\n+      elsif Is_Parent_Directory_Name (Name)\n+        or else Is_Current_Directory_Name (Name)\n+        or else Is_Root_Directory_Name (Name)\n+      then\n+         raise Use_Error with\n+          \"directory \"\"\" & Name & \"\"\" has no containing directory\";\n+\n+      --  Otherwise, the common case\n+\n       else\n          declare\n             Last_DS : constant Natural :=\n               Strings.Fixed.Index (Name, Dir_Seps, Going => Strings.Backward);\n \n          begin\n-            --  If Name indicates a root directory, raise Use_Error, because\n-            --  it has no containing directory.\n+            --  If there is no directory separator, return \".\", representing\n+            --  the current working directory.\n \n-            if Is_Parent_Directory_Name (Name)\n-              or else Is_Current_Directory_Name (Name)\n-              or else Is_Root_Directory_Name (Name)\n-            then\n-               raise Use_Error with\n-                 \"directory \"\"\" & Name & \"\"\" has no containing directory\";\n+            if Last_DS = 0 then\n+               return \".\";\n \n-            elsif Last_DS = 0 then\n-               --  There is no directory separator, so return \".\", representing\n-               --  the current working directory.\n+            --  If the directory separator is last, then Name is a directory\n+            --  and we recurse after stripping the separator.\n \n-               return \".\";\n+            elsif Last_DS = Name'Last then\n+               return\n+                 Containing_Directory (Name (Name'First .. Name'Last - 1));\n \n             else\n                declare\n","prefixes":["Ada"]}