From patchwork Wed Oct 9 22:47:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1995131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OJrJdYRs; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4XP7Tg70TWz1xvW for ; Thu, 10 Oct 2024 09:53:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6438E38650DB for ; Wed, 9 Oct 2024 22:53:23 +0000 (GMT) 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 ESMTP id B1E753858417 for ; Wed, 9 Oct 2024 22:52:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1E753858417 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B1E753858417 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728514374; cv=none; b=vbnrzeQ25tIAFP2r796JWbGcF3yO3b1GkD7J25soh+sacpHClp57Dwjt+yDGRxQyfDBUhrLySD+ugFrvckDVaVgkGyVLzaxn8ckeuohru+J7rRaK6R7AjXp7m46QmBA5bU1uOGbXcwzP/QSj+zWg0Aw/xqJSnQ9NQmdsS2QjiGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728514374; c=relaxed/simple; bh=Kb96j8DUoWQn6dTgScqFNYEknaPJDrtEPyvzSNRStIs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vJF6RjpqcsW+Thi6F7PuhNHImZqv7tSxt1iHwvwyfOyKZ07TQ1NU4V7hNTJQwMgU63ZpPp3SDLFSXDBWjKffJTY/ed+WukNUTWSECdveGLFEyhomfD4JpdKILBztqbALRY90ZLFHe9KGSvSY6JTHNzC5l37UJrwmAE+5btxFKDI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728514372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sc1XMAhPTKmZ4omEwFKILRPz4LzyOj1gQzrpEMKr/hY=; b=OJrJdYRsXN90z18dXTUljk1kCN/zg032DcroRMhrsoJh1wLeiAXauumj60boUeX3A/M+9l 0oGAyEMPAwb3Nm2bYQR7zz7gDUJPglz1OsJq4K8MD30rkx4IGb/DjoNgZl455CJwpBBB4h aWGUD6sc+da8xxEkTmhhBISFsSslsf4= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-jGawFLxfMsW1F9u-05FKSA-1; Wed, 09 Oct 2024 18:52:50 -0400 X-MC-Unique: jGawFLxfMsW1F9u-05FKSA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7ac9b08cb77so56801385a.1 for ; Wed, 09 Oct 2024 15:52:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728514370; x=1729119170; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sc1XMAhPTKmZ4omEwFKILRPz4LzyOj1gQzrpEMKr/hY=; b=VDBjTPzfmRzFo4u/4qJ+DgJiHRC4rN0pVt3xGICtIaLPdShz76Fex5HItgMgTfT45H lYaGvmEGK7NrxU9x+ejugZZlMX2SxaNvLIhnvcoNwy0K+nhx1Ln0qDXKnyqJO1HUA6hC ZhrkNyEfKFsfoTJlAio1q0wUcnHW6MiGNxHbsisP07aB3C1WnBBty68QSKA61JswZ4F8 mz7dUjReHb1yv5u1WKAd2zHRDKyt1uGKDwCrqSBEI+FQnScOkTkLpoQsNhEKdrghl2RF bzGEHLjas9OTr9vtwqNJLfxZBSKvBtOMBy6MhSmyaz5XhbEzz7uvv5b5kiGi41fHE9hv QKHg== X-Gm-Message-State: AOJu0Yzvs5NeKqNjUo2vz2Lv/IDewII94AdQDU95F12n7eQDIdXLKKPR TKR1u0QFGq2XLYTP6cvVFgPvn7UB4d9ij+GpBr7QA8+YJLN2JNkdcAErMYMC0fFEKjyUjGDA/0b T3ybb0536q9mZXt70xkMxnY4x9GqHi2H7HLfwqwzCv0Nw9NybwAOv9qCYBX6pZh0hylKfgNTf+t sFRSn/PcqWUitlau2xogMCBRTXhK3HtTIz3VQ= X-Received: by 2002:a05:620a:462a:b0:7a9:aae5:331 with SMTP id af79cd13be357-7b07953e8f3mr462073285a.21.1728514370099; Wed, 09 Oct 2024 15:52:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/7CMQIzcfUuYufrvRhbW/cb4FSflFVEBr+XOkIIy5jkfUAOdMc9guBjWvrKbHTNSMoYg2Rg== X-Received: by 2002:a05:620a:462a:b0:7a9:aae5:331 with SMTP id af79cd13be357-7b07953e8f3mr462070485a.21.1728514369489; Wed, 09 Oct 2024 15:52:49 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b1148dc71dsm1531285a.34.2024.10.09.15.52.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 15:52:48 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [PATCH RFC 1/4] c-family: add -fsearch-include-path Date: Wed, 9 Oct 2024 18:47:53 -0400 Message-ID: <20241009225246.2770766-1-jason@redhat.com> X-Mailer: git-send-email 2.46.2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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_H3, RCVD_IN_MSPIKE_WL, 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.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 Tested x86_64-pc-linux-gnu. Any thoughts? -- 8< -- The C++ modules code has a -fmodule-header option to specify looking up headers to compile to header units on the usual include paths. I'd like to have the same functionality for full C++20 modules such as module std, which could also live on the include path. But this behavior doesn't seem necessarily connected to modules, so I'm proposing a general C/C++ option to specify the behavior of looking in the include path for the input files specified on the command line. Other ideas for the name of the option are very welcome. gcc/ChangeLog: * doc/cppopts.texi: Document -fsearch-include-path. gcc/c-family/ChangeLog: * c.opt: Add -fsearch-include-path. * c-opts.cc (c_common_post_options): Handle it. gcc/cp/ChangeLog: * module.cc (module_preprocess_options): Don't override it. --- gcc/doc/cppopts.texi | 11 +++++++++++ gcc/doc/invoke.texi | 5 +++++ gcc/c-family/c.opt | 7 +++++++ gcc/c-family/c-opts.cc | 13 +++++++++++++ gcc/cp/module.cc | 3 ++- 5 files changed, 38 insertions(+), 1 deletion(-) base-commit: dcee0b6547211a428b75adb03a461285fed0f20d diff --git a/gcc/doc/cppopts.texi b/gcc/doc/cppopts.texi index 5b5b0848ae8..e3686b63337 100644 --- a/gcc/doc/cppopts.texi +++ b/gcc/doc/cppopts.texi @@ -270,6 +270,17 @@ When preprocessing, do not shorten system header paths with canonicalization. @item -fmax-include-depth=@var{depth} Set the maximum depth of the nested #include. The default is 200. +@opindex fsearch-include-path +@item -fsearch-include-path +Look for input files on the #include path, not just the current +directory. This is particularly useful with C++20 modules, for which +both header units and module interface units need to be compiled +directly: + +@smallexample +g++ -c -std=c++20 -fmodules-ts -fsearch-include-path bits/stdc++.h std.cppm +@end smallexample + @opindex ftabstop @item -ftabstop=@var{width} Set the distance between tab stops. This helps the preprocessor report diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c0c8bf1c29a..c69d032323e 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -38042,6 +38042,11 @@ installed. Specifying the language as one of these variants also inhibits output of the object file, as header files have no associated object file. +Alternately, or for a module interface unit in an installed location, +you can use @option{-fsearch-include-path} to specify that the main +source file should be found on the include path rather than the +current directory. + Header units can be used in much the same way as precompiled headers (@pxref{Precompiled Headers}), but with fewer restrictions: an #include that is translated to a header unit import can appear at any diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 1f2e72a0bb7..0aada1c3080 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -2237,6 +2237,13 @@ frtti C++ ObjC++ Optimization Var(flag_rtti) Init(1) Generate run time type descriptor information. +fsearch-include-path +C ObjC C++ ObjC++ +Look for the main source file on the include path. + +fsearch-include-path= +C++ ObjC++ Joined RejectNegative Undocumented + fshort-enums C ObjC C++ ObjC++ LTO Optimization Var(flag_short_enums) Use the narrowest integer type possible for enumeration types. diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 510e0870140..2798b4d295f 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -769,6 +769,19 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value, cpp_opts->traditional = 1; break; + case OPT_fsearch_include_path: + cpp_opts->main_search = CMS_user; + break; + + case OPT_fsearch_include_path_: + if (!strcmp (arg, "user")) + cpp_opts->main_search = CMS_user; + else if (!strcmp (arg, "system")) + cpp_opts->main_search = CMS_system; + else + error ("invalid argument %qs to %<-fsearch-include-path%>", arg); + break; + case OPT_v: verbose = true; break; diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 2dc59ce8a12..e58c057a96e 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -21069,7 +21069,8 @@ module_preprocess_options (cpp_reader *reader) } auto *opt = cpp_get_options (reader); opt->module_directives = true; - opt->main_search = cpp_main_search (flag_header_unit); + if (opt->main_search == CMS_none) + opt->main_search = cpp_main_search (flag_header_unit); } }