From patchwork Sun Sep 14 16:23:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: joergboe X-Patchwork-Id: 120217 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD98F3858C2D for ; Sun, 14 Sep 2025 16:25:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD98F3858C2D Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=snafu.de header.i=@snafu.de header.a=rsa-sha256 header.s=sn header.b=SmIATHEg X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from longisland.snafu.de (longisland.snafu.de [IPv6:2001:1560:3:255::153]) by sourceware.org (Postfix) with ESMTPS id F01C03858C50 for ; Sun, 14 Sep 2025 16:23:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F01C03858C50 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=snafu.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=snafu.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F01C03858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:1560:3:255::153 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757867037; cv=none; b=A2ibVpkYcjCQbaYqFb69ckcCP5xqCGmz565qulmaPtUa4roQTjoRxwcNKc/l3RdG92MA00cBoIfUZBQ8kbxsuK9JATByJmDnUhT0zQAvbkH0e7/T5jAsUX36OVhlijPSEtZo+Tz2Ukg+Nj6llGNfgiqL7O6qPL2MF98xJyaPPzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757867037; c=relaxed/simple; bh=nMVm/Iq0ZAneuVbRyK7lUy1m1dLHUY7gMzAmtijnKQE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Y4jM2CFdpMU8nVh9saej0Ilear25GJWn1Y0u/dSlDJ3Rcg13gHzmKcih5VpKkqLLJRZIrrC6kGU2ceUvnKYS58WUV/sitBoZJ0bzFbHlOFhGwW29m6bk15Lvp4EGbOwQDnFZyBOIqKvmhpHtX74rPIx6FD4+5eJ3a1F630o6hZU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F01C03858C50 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=snafu.de; s=sn; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc:To: From:Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=Q8jQldc1TJvTIrtt9NOmdZa6Xyahw4JFDOZU/J5uHe0=; b=S mIATHEgBS15zOO5V0i4JX5BxFh0GcpPsZ2VWra8iOnbY5fPVz8i4O57TgS3FORjS8xGUF3fqSSgoC 1Ddq/yM6rdK4V/1zC/m4c90Brr+ONo/AHex1OgOudzxkAyVVu/fenPZfEY9GLhdN5TOQKiDVTr0Ls hnq5SNbPanqph1RJNrHpMhEK/4uN23XWzznhtSASPneDvbdTwYPwbubOZhyTutbuhH1MXd2ZYSsJI siYLldq4HVGqNU4ESA/2wXo/gYeSt4LFtQJRWu/3fjzD8QdhjJi9nPd52im1mzC8O2xMaunNwW+VR AmReRScK8PY50v4BH7RWo6z3TtAnXWrHQ==; X-Trace: 507c6a6f657267626f6540736e6166752e64657c38352e3139312e32352e323335 7c3175787057352d30303030303030305031752d327837427c3137353738363730 3333 Received: from longisland.snafu.de ([10.153.10.19] helo=localhost) by longisland.snafu.de with esmtpsa (Exim 4.98.2) id 1uxpW5-00000000P1u-2x7B; Sun, 14 Sep 2025 18:23:54 +0200 From: Joerg Boehmer To: gcc-patches@gcc.gnu.org Cc: Joerg Boehmer Subject: [PATCH v3] preprocessor: More escapes for Makefile rules (-M option) [PR41329, PR121450] Date: Sun, 14 Sep 2025 18:23:15 +0200 Message-ID: <20250914162315.12947-1-joergboe@snafu.de> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 X-VISP-ShouldScan: 1 X-VISP-Virus-Check: clean X-VISP-Spam-Score: -0.2 (/) X-VISP-Spam-Report: This message has been scanned on "longisland.snafu.de" to identify if it is considered spam or not. Contact the support hotline for details. Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% [score: 0.5000] X-VISP-Spam-Max-Score: +++++ X-SA-Exim-Connect-IP: 85.191.25.235 X-SA-Exim-Mail-From: joergboe@snafu.de X-SA-Exim-Scanned: No (on longisland.snafu.de); SAEximRunCond expanded to false X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, 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~patchwork=sourceware.org@gcc.gnu.org This patch adds support for more characters that are special to GNU make in file-names. Especially GNU make expects in rules that #, %, :, *, ? and [ characters are preceded by a backslash to remove their special meaning. PR preprocessor/41329 PR preprocessor/121450 libcpp/ChangeLog: * mkdeps.cc (munge): Quote additional characters: %, :, *, ? and [ gcc/testsuite/ChangeLog: * g++.dg/modules/dep-1_a.C: Adapt tescase * g++.dg/modules/dep-1_b.C: Likewise * g++.dg/modules/dep-2.C: Likewise --- gcc/testsuite/g++.dg/modules/dep-1_a.C | 4 ++-- gcc/testsuite/g++.dg/modules/dep-1_b.C | 4 ++-- gcc/testsuite/g++.dg/modules/dep-2.C | 6 +++--- libcpp/mkdeps.cc | 28 ++++++++++++++++---------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/gcc/testsuite/g++.dg/modules/dep-1_a.C b/gcc/testsuite/g++.dg/modules/dep-1_a.C index 3e92eeaef9f..f90c2378702 100644 --- a/gcc/testsuite/g++.dg/modules/dep-1_a.C +++ b/gcc/testsuite/g++.dg/modules/dep-1_a.C @@ -4,6 +4,6 @@ export module m:part; // { dg-module-cmi m:part } // All The Backslashes! -// { dg-final { scan-file dep-1_a.d {\nm:part\.c\+\+-module: gcm.cache/m-part\.gcm} } } +// { dg-final { scan-file dep-1_a.d {\nm\\:part\.c\+\+-module: gcm.cache/m-part\.gcm} } } // { dg-final { scan-file dep-1_a.d {\ngcm.cache/m-part\.gcm:| dep-1_a\.o} } } -// { dg-final { scan-file dep-1_a.d {\n\.PHONY: m:part\.c\+\+-module} } } +// { dg-final { scan-file dep-1_a.d {\n\.PHONY: m\\:part\.c\+\+-module} } } diff --git a/gcc/testsuite/g++.dg/modules/dep-1_b.C b/gcc/testsuite/g++.dg/modules/dep-1_b.C index 265ebfcda64..1ecb31c230e 100644 --- a/gcc/testsuite/g++.dg/modules/dep-1_b.C +++ b/gcc/testsuite/g++.dg/modules/dep-1_b.C @@ -3,8 +3,8 @@ export module m; // { dg-module-cmi m } export import :part; -// { dg-final { scan-file dep-1_b.d {\ndep-1_b\.s gcm.cache/m\.gcm: m:part\.c\+\+-module} } } +// { dg-final { scan-file dep-1_b.d {\ndep-1_b\.s gcm.cache/m\.gcm: m\\:part\.c\+\+-module} } } // { dg-final { scan-file dep-1_b.d {\nm\.c\+\+-module: gcm.cache/m\.gcm} } } // { dg-final { scan-file dep-1_b.d {\n\.PHONY: m\.c\+\+-module} } } // { dg-final { scan-file dep-1_b.d {\ngcm.cache/m\.gcm:| dep-1_b.o} } } -// { dg-final { scan-file dep-1_b.d {\nCXX_IMPORTS \+= m:part\.c\+\+-module} } } +// { dg-final { scan-file dep-1_b.d {\nCXX_IMPORTS \+= m\\:part\.c\+\+-module} } } diff --git a/gcc/testsuite/g++.dg/modules/dep-2.C b/gcc/testsuite/g++.dg/modules/dep-2.C index 3c869755785..eca5653f548 100644 --- a/gcc/testsuite/g++.dg/modules/dep-2.C +++ b/gcc/testsuite/g++.dg/modules/dep-2.C @@ -5,8 +5,8 @@ module m:part; // { dg-module-cmi !m:part } // All The Backslashes! -// { dg-final { scan-file dep-2.d {\nm:part\.c\+\+-module: gcm.cache/m-part\.gcm} } } -// { dg-final { scan-file dep-2.d {\ngcm.cache/m:part\.gcm:| dep-2\.o} } } -// { dg-final { scan-file dep-2.d {\n\.PHONY: m:part\.c\+\+-module} } } +// { dg-final { scan-file dep-2.d {\nm\\:part\.c\+\+-module: gcm.cache/m-part\.gcm} } } +// { dg-final { scan-file dep-2.d {\ngcm.cache/m\\:part\.gcm:| dep-2\.o} } } +// { dg-final { scan-file dep-2.d {\n\.PHONY: m\\:part\.c\+\+-module} } } // { dg-final { scan-file dep-2.i {\nmodule m:part;\n} } } diff --git a/libcpp/mkdeps.cc b/libcpp/mkdeps.cc index a4bea6e47d4..40fd5062a8a 100644 --- a/libcpp/mkdeps.cc +++ b/libcpp/mkdeps.cc @@ -121,10 +121,11 @@ public: }; /* Apply Make quoting to STR, TRAIL. Note that it's not possible to - quote all such characters - e.g. \n, %, *, ?, [, \ (in some + quote all such characters - e.g. \n, ;, =, |, \ (in some contexts), and ~ are not properly handled. It isn't possible to get this right in any current version of Make. (??? Still true? - Old comment referred to 3.76.1.) */ + Old comment referred to 4.4.1.) However there are still issues with + this special characters in some contexts. */ static const char * munge (const char *str, const char *trail = nullptr) @@ -157,18 +158,23 @@ munge (const char *str, const char *trail = nullptr) case ' ': case '\t': - /* GNU make uses a weird quoting scheme for white space. - A space or tab preceded by 2N+1 backslashes - represents N backslashes followed by space; a space - or tab preceded by 2N backslashes represents N - backslashes at the end of a file name; and - backslashes in other contexts should not be + case '#': + case ':': + case '*': + case '?': + case '[': + case '%': + /* GNU make uses a weird quoting scheme for those special + characters in the context of a target or prerequisite. + A special character preceded by 2N+1 backslashes + represents N backslashes and the following character + loses its special meaning; a special + character preceded by 2N backslashes represents N + backslashes and the special meaning of the character is + retained; and backslashes in other contexts should not be doubled. */ while (slashes--) buf[dst++] = '\\'; - /* FALLTHROUGH */ - - case '#': buf[dst++] = '\\'; /* FALLTHROUGH */