[clang] [Clang] WIP: Take libstdc++ into account during GCC detection (PR #145056)
https://github.com/frederik-h edited https://github.com/llvm/llvm-project/pull/145056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Take libstdc++ into account during GCC detection (PR #145056)
https://github.com/frederik-h created https://github.com/llvm/llvm-project/pull/145056 The Generic_GCC::GCCInstallationDetector class always picks the latest available GCC installation directory. This often breaks C++ compilation on systems on which this directory does not contain a libstdc++ installation. On Ubuntu 22.04 systems, for instance, this can happen if the "gcc-12" package gets installed without the corresponding "g++-12" or "libstdc++-12" package in addition to the default "g++-11" installation. This patch changes the GCC installation selection, if compiling for C++ using libstdc++, to consider only GCC installation directories which also contain libstdc++. This is accomplished by enabling the GCCInstallationDetector to reuse the existing functionality for determinig the libstdc++ include directories which had to be decoupled from its existing uses. >From 87c03ace23467a7d6cb7e466a02309b5b287a013 Mon Sep 17 00:00:00 2001 From: Frederik Harwath Date: Wed, 19 Feb 2025 16:01:56 +0100 Subject: [PATCH] [Clang] Take libstdc++ into account during GCC detection The Generic_GCC::GCCInstallationDetector class always picks the latest available GCC installation directory. This often breaks C++ compilation on systems on which this directory does not contain a libstdc++ installation. On Ubuntu 22.04 systems, for instance, this can happen if the "gcc-12" package gets installed without the corresponding "g++-12" or "libstdc++-12" package in addition to the default "g++-11" installation. This patch changes the GCC installation selection, if compiling for C++ using libstdc++, to consider only GCC installation directories which also contain libstdc++. This is accomplished by enabling the GCCInstallationDetector to reuse the existing functionality for determinig the libstdc++ include directories which had to be decoupled from its existing uses. --- clang/include/clang/Driver/Options.td | 5 +- clang/include/clang/Driver/ToolChain.h| 27 ++- clang/lib/Driver/ToolChain.cpp| 25 ++- clang/lib/Driver/ToolChains/AVR.cpp | 3 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 191 -- clang/lib/Driver/ToolChains/Gnu.h | 84 ++-- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- .../gcc-11.2.0/include/c++/11.2.0/.keep | 0 .../gcc-12/include/c++/12/.keep | 0 clang/test/Driver/gcc-toolchain.cpp | 5 - 16 files changed, 245 insertions(+), 109 deletions(-) create mode 100644 clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/include/c++/11.2.0/.keep create mode 100644 clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-12/include/c++/12/.keep diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 6eabd9f76a792..65a63a990d8e3 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -732,8 +732,9 @@ def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">, def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>, Visibility<[ClangOption, FlangOption]>, HelpText< -"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " -"Clang will use the GCC installation with the largest version">, +"Specify a directory to search for GCC installations (see --gcc-install-dir). " +"Picks the subdirectory with the largest GCC version, " +"skipping those without libstdc++ if the compile flags require it.">, HelpTextForVariants<[FlangOption], "Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " "Flang will use the GCC installation with the largest version">; diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 7d1d8feebf35e..fe4e22caca5f5 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -226,25 +226,32 @@ class ToolChain { /// \name Utilities for implementing subclasses. ///@{ - static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args, - const Twine &Path); static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path); static void - addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1A
[clang] [Clang] WIP: Take libstdc++ into account during GCC detection (PR #145056)
frederik-h wrote: See also this related [discourse thread](https://discourse.llvm.org/t/rfc-take-libstdc-into-account-during-gcc-detection/86992). https://github.com/llvm/llvm-project/pull/145056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][test] Remove duplication from gcc toolchain test (NFC) (PR #146487)
https://github.com/frederik-h created https://github.com/llvm/llvm-project/pull/146487 Changes from Commit 40aab0412fe7a14781e133627c2bb0a22761eac8 "[test] Migrate -gcc-toolchain with space separator to --gcc-toolchain=" made two previously different RUN lines equal. Remove one RUN line. >From f495f9aece299b4e194a39be7b66ce14c4632f2d Mon Sep 17 00:00:00 2001 From: Frederik Harwath Date: Tue, 1 Jul 2025 10:36:52 +0200 Subject: [PATCH] [clang][test] Remove duplication from gcc toolchain test (NFC) Changes from Commit 40aab0412fe7a14781e133627c2bb0a22761eac8 "[test] Migrate -gcc-toolchain with space separator to --gcc-toolchain=" made two previously different RUN lines equal. Remove one RUN line. --- clang/test/Driver/gcc-toolchain.cpp | 5 - 1 file changed, 5 deletions(-) diff --git a/clang/test/Driver/gcc-toolchain.cpp b/clang/test/Driver/gcc-toolchain.cpp index 6d4ad417cfec6..a14e8d00af1ef 100644 --- a/clang/test/Driver/gcc-toolchain.cpp +++ b/clang/test/Driver/gcc-toolchain.cpp @@ -6,11 +6,6 @@ // RUN: --gcc-toolchain=%S/Inputs/ubuntu_14.04_multiarch_tree/usr -stdlib=libstdc++ --rtlib=libgcc --unwindlib=libgcc -no-pie 2>&1 | \ // RUN: FileCheck %s // -// Additionally check that the legacy spelling of the flag works. -// RUN: %clangxx %s -### --target=x86_64-linux-gnu --sysroot= \ -// RUN: --gcc-toolchain=%S/Inputs/ubuntu_14.04_multiarch_tree/usr -stdlib=libstdc++ --rtlib=libgcc --unwindlib=libgcc -no-pie 2>&1 | \ -// RUN: FileCheck %s -// // Test for header search toolchain detection. // CHECK: "-internal-isystem" // CHECK: "[[TOOLCHAIN:[^"]+]]/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][test] Remove duplication from gcc toolchain test (NFC) (PR #146487)
frederik-h wrote: Merging without review as this change is trivial. https://github.com/llvm/llvm-project/pull/146487 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Take libstdc++ into account during GCC detection (PR #145056)
https://github.com/frederik-h updated https://github.com/llvm/llvm-project/pull/145056 >From 87c03ace23467a7d6cb7e466a02309b5b287a013 Mon Sep 17 00:00:00 2001 From: Frederik Harwath Date: Wed, 19 Feb 2025 16:01:56 +0100 Subject: [PATCH 1/7] [Clang] Take libstdc++ into account during GCC detection The Generic_GCC::GCCInstallationDetector class always picks the latest available GCC installation directory. This often breaks C++ compilation on systems on which this directory does not contain a libstdc++ installation. On Ubuntu 22.04 systems, for instance, this can happen if the "gcc-12" package gets installed without the corresponding "g++-12" or "libstdc++-12" package in addition to the default "g++-11" installation. This patch changes the GCC installation selection, if compiling for C++ using libstdc++, to consider only GCC installation directories which also contain libstdc++. This is accomplished by enabling the GCCInstallationDetector to reuse the existing functionality for determinig the libstdc++ include directories which had to be decoupled from its existing uses. --- clang/include/clang/Driver/Options.td | 5 +- clang/include/clang/Driver/ToolChain.h| 27 ++- clang/lib/Driver/ToolChain.cpp| 25 ++- clang/lib/Driver/ToolChains/AVR.cpp | 3 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 191 -- clang/lib/Driver/ToolChains/Gnu.h | 84 ++-- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- .../gcc-11.2.0/include/c++/11.2.0/.keep | 0 .../gcc-12/include/c++/12/.keep | 0 clang/test/Driver/gcc-toolchain.cpp | 5 - 16 files changed, 245 insertions(+), 109 deletions(-) create mode 100644 clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/include/c++/11.2.0/.keep create mode 100644 clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-12/include/c++/12/.keep diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 6eabd9f76a792..65a63a990d8e3 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -732,8 +732,9 @@ def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">, def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>, Visibility<[ClangOption, FlangOption]>, HelpText< -"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " -"Clang will use the GCC installation with the largest version">, +"Specify a directory to search for GCC installations (see --gcc-install-dir). " +"Picks the subdirectory with the largest GCC version, " +"skipping those without libstdc++ if the compile flags require it.">, HelpTextForVariants<[FlangOption], "Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " "Flang will use the GCC installation with the largest version">; diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 7d1d8feebf35e..fe4e22caca5f5 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -226,25 +226,32 @@ class ToolChain { /// \name Utilities for implementing subclasses. ///@{ - static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args, - const Twine &Path); static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path); static void - addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args, - const Twine &Path); - static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, -llvm::opt::ArgStringList &CC1Args, -ArrayRef Paths); - + addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args, + const Twine &Path); static std::string concat(StringRef Path, const Twine &A, const Twine &B = "", const Twine &C = "", const Twine &D = ""); + + /// Return the CXXStdlibType which has been selected based on the + /// type of ToolChain driver args, triple etc. if it is in use, + /// i.e. we are compiling for C++ and the std
[clang] [Clang] WIP: Take libstdc++ into account during GCC detection (PR #145056)
https://github.com/frederik-h updated https://github.com/llvm/llvm-project/pull/145056 >From 87c03ace23467a7d6cb7e466a02309b5b287a013 Mon Sep 17 00:00:00 2001 From: Frederik Harwath Date: Wed, 19 Feb 2025 16:01:56 +0100 Subject: [PATCH 1/3] [Clang] Take libstdc++ into account during GCC detection The Generic_GCC::GCCInstallationDetector class always picks the latest available GCC installation directory. This often breaks C++ compilation on systems on which this directory does not contain a libstdc++ installation. On Ubuntu 22.04 systems, for instance, this can happen if the "gcc-12" package gets installed without the corresponding "g++-12" or "libstdc++-12" package in addition to the default "g++-11" installation. This patch changes the GCC installation selection, if compiling for C++ using libstdc++, to consider only GCC installation directories which also contain libstdc++. This is accomplished by enabling the GCCInstallationDetector to reuse the existing functionality for determinig the libstdc++ include directories which had to be decoupled from its existing uses. --- clang/include/clang/Driver/Options.td | 5 +- clang/include/clang/Driver/ToolChain.h| 27 ++- clang/lib/Driver/ToolChain.cpp| 25 ++- clang/lib/Driver/ToolChains/AVR.cpp | 3 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 191 -- clang/lib/Driver/ToolChains/Gnu.h | 84 ++-- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- .../gcc-11.2.0/include/c++/11.2.0/.keep | 0 .../gcc-12/include/c++/12/.keep | 0 clang/test/Driver/gcc-toolchain.cpp | 5 - 16 files changed, 245 insertions(+), 109 deletions(-) create mode 100644 clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/include/c++/11.2.0/.keep create mode 100644 clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-12/include/c++/12/.keep diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 6eabd9f76a792..65a63a990d8e3 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -732,8 +732,9 @@ def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">, def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>, Visibility<[ClangOption, FlangOption]>, HelpText< -"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " -"Clang will use the GCC installation with the largest version">, +"Specify a directory to search for GCC installations (see --gcc-install-dir). " +"Picks the subdirectory with the largest GCC version, " +"skipping those without libstdc++ if the compile flags require it.">, HelpTextForVariants<[FlangOption], "Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " "Flang will use the GCC installation with the largest version">; diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 7d1d8feebf35e..fe4e22caca5f5 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -226,25 +226,32 @@ class ToolChain { /// \name Utilities for implementing subclasses. ///@{ - static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args, - const Twine &Path); static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path); static void - addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args, - const Twine &Path); - static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, -llvm::opt::ArgStringList &CC1Args, -ArrayRef Paths); - + addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args, + const Twine &Path); static std::string concat(StringRef Path, const Twine &A, const Twine &B = "", const Twine &C = "", const Twine &D = ""); + + /// Return the CXXStdlibType which has been selected based on the + /// type of ToolChain driver args, triple etc. if it is in use, + /// i.e. we are compiling for C++ and the std
[clang] [Clang] WIP: Take libstdc++ into account during GCC detection (PR #145056)
https://github.com/frederik-h updated https://github.com/llvm/llvm-project/pull/145056 >From 87c03ace23467a7d6cb7e466a02309b5b287a013 Mon Sep 17 00:00:00 2001 From: Frederik Harwath Date: Wed, 19 Feb 2025 16:01:56 +0100 Subject: [PATCH 1/5] [Clang] Take libstdc++ into account during GCC detection The Generic_GCC::GCCInstallationDetector class always picks the latest available GCC installation directory. This often breaks C++ compilation on systems on which this directory does not contain a libstdc++ installation. On Ubuntu 22.04 systems, for instance, this can happen if the "gcc-12" package gets installed without the corresponding "g++-12" or "libstdc++-12" package in addition to the default "g++-11" installation. This patch changes the GCC installation selection, if compiling for C++ using libstdc++, to consider only GCC installation directories which also contain libstdc++. This is accomplished by enabling the GCCInstallationDetector to reuse the existing functionality for determinig the libstdc++ include directories which had to be decoupled from its existing uses. --- clang/include/clang/Driver/Options.td | 5 +- clang/include/clang/Driver/ToolChain.h| 27 ++- clang/lib/Driver/ToolChain.cpp| 25 ++- clang/lib/Driver/ToolChains/AVR.cpp | 3 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 191 -- clang/lib/Driver/ToolChains/Gnu.h | 84 ++-- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- .../gcc-11.2.0/include/c++/11.2.0/.keep | 0 .../gcc-12/include/c++/12/.keep | 0 clang/test/Driver/gcc-toolchain.cpp | 5 - 16 files changed, 245 insertions(+), 109 deletions(-) create mode 100644 clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/include/c++/11.2.0/.keep create mode 100644 clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-12/include/c++/12/.keep diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 6eabd9f76a792..65a63a990d8e3 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -732,8 +732,9 @@ def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">, def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>, Visibility<[ClangOption, FlangOption]>, HelpText< -"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " -"Clang will use the GCC installation with the largest version">, +"Specify a directory to search for GCC installations (see --gcc-install-dir). " +"Picks the subdirectory with the largest GCC version, " +"skipping those without libstdc++ if the compile flags require it.">, HelpTextForVariants<[FlangOption], "Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " "Flang will use the GCC installation with the largest version">; diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 7d1d8feebf35e..fe4e22caca5f5 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -226,25 +226,32 @@ class ToolChain { /// \name Utilities for implementing subclasses. ///@{ - static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args, - const Twine &Path); static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path); static void - addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args, - const Twine &Path); - static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, -llvm::opt::ArgStringList &CC1Args, -ArrayRef Paths); - + addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args, + const Twine &Path); static std::string concat(StringRef Path, const Twine &A, const Twine &B = "", const Twine &C = "", const Twine &D = ""); + + /// Return the CXXStdlibType which has been selected based on the + /// type of ToolChain driver args, triple etc. if it is in use, + /// i.e. we are compiling for C++ and the std
[clang] [Clang] Take libstdc++ into account during GCC detection (PR #145056)
https://github.com/frederik-h edited https://github.com/llvm/llvm-project/pull/145056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] WIP: Take libstdc++ into account during GCC detection (PR #145056)
https://github.com/frederik-h updated https://github.com/llvm/llvm-project/pull/145056 >From 87c03ace23467a7d6cb7e466a02309b5b287a013 Mon Sep 17 00:00:00 2001 From: Frederik Harwath Date: Wed, 19 Feb 2025 16:01:56 +0100 Subject: [PATCH 1/4] [Clang] Take libstdc++ into account during GCC detection The Generic_GCC::GCCInstallationDetector class always picks the latest available GCC installation directory. This often breaks C++ compilation on systems on which this directory does not contain a libstdc++ installation. On Ubuntu 22.04 systems, for instance, this can happen if the "gcc-12" package gets installed without the corresponding "g++-12" or "libstdc++-12" package in addition to the default "g++-11" installation. This patch changes the GCC installation selection, if compiling for C++ using libstdc++, to consider only GCC installation directories which also contain libstdc++. This is accomplished by enabling the GCCInstallationDetector to reuse the existing functionality for determinig the libstdc++ include directories which had to be decoupled from its existing uses. --- clang/include/clang/Driver/Options.td | 5 +- clang/include/clang/Driver/ToolChain.h| 27 ++- clang/lib/Driver/ToolChain.cpp| 25 ++- clang/lib/Driver/ToolChains/AVR.cpp | 3 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 191 -- clang/lib/Driver/ToolChains/Gnu.h | 84 ++-- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- .../gcc-11.2.0/include/c++/11.2.0/.keep | 0 .../gcc-12/include/c++/12/.keep | 0 clang/test/Driver/gcc-toolchain.cpp | 5 - 16 files changed, 245 insertions(+), 109 deletions(-) create mode 100644 clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/include/c++/11.2.0/.keep create mode 100644 clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-12/include/c++/12/.keep diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 6eabd9f76a792..65a63a990d8e3 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -732,8 +732,9 @@ def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">, def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>, Visibility<[ClangOption, FlangOption]>, HelpText< -"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " -"Clang will use the GCC installation with the largest version">, +"Specify a directory to search for GCC installations (see --gcc-install-dir). " +"Picks the subdirectory with the largest GCC version, " +"skipping those without libstdc++ if the compile flags require it.">, HelpTextForVariants<[FlangOption], "Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " "Flang will use the GCC installation with the largest version">; diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 7d1d8feebf35e..fe4e22caca5f5 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -226,25 +226,32 @@ class ToolChain { /// \name Utilities for implementing subclasses. ///@{ - static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args, - const Twine &Path); static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path); static void - addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args, - const Twine &Path); - static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, -llvm::opt::ArgStringList &CC1Args, -ArrayRef Paths); - + addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args, + const Twine &Path); static std::string concat(StringRef Path, const Twine &A, const Twine &B = "", const Twine &C = "", const Twine &D = ""); + + /// Return the CXXStdlibType which has been selected based on the + /// type of ToolChain driver args, triple etc. if it is in use, + /// i.e. we are compiling for C++ and the std