diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp --- a/clang/lib/Driver/ToolChains/Fuchsia.cpp +++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp @@ -358,31 +358,30 @@ DriverArgs.hasArg(options::OPT_nostdincxx)) return; - const Driver &D = getDriver(); - std::string Target = getTripleString(); + llvm::Triple Triple = getTriple(); + // x86 is only used for the bootloader and we use x86-64 headers in that case. + if (Triple.getArch() == llvm::Triple::x86) + Triple.setArch(llvm::Triple::x86_64); + + switch (GetCXXStdlibType(DriverArgs)) { + case ToolChain::CST_Libcxx: { + SmallString<128> P(getDriver().Dir); + llvm::sys::path::append(P, "..", "include"); - auto AddCXXIncludePath = [&](StringRef Path) { - std::string Version = detectLibcxxVersion(Path); + std::string Version = detectLibcxxVersion(P); if (Version.empty()) return; - // First add the per-target include path. - SmallString<128> TargetDir(Path); - llvm::sys::path::append(TargetDir, Target, "c++", Version); + // First add the per-target include path if it exists. + SmallString<128> TargetDir(P); + llvm::sys::path::append(TargetDir, Triple.str(), "c++", Version); if (getVFS().exists(TargetDir)) addSystemInclude(DriverArgs, CC1Args, TargetDir); // Second add the generic one. - SmallString<128> Dir(Path); + SmallString<128> Dir(P); llvm::sys::path::append(Dir, "c++", Version); addSystemInclude(DriverArgs, CC1Args, Dir); - }; - - switch (GetCXXStdlibType(DriverArgs)) { - case ToolChain::CST_Libcxx: { - SmallString<128> P(D.Dir); - llvm::sys::path::append(P, "..", "include"); - AddCXXIncludePath(P); break; } diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/i386-unknown-fuchsia/libclang_rt.builtins.a b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/i386-unknown-fuchsia/libclang_rt.builtins.a new file mode 100644 diff --git a/clang/test/Driver/fuchsia.cpp b/clang/test/Driver/fuchsia.cpp --- a/clang/test/Driver/fuchsia.cpp +++ b/clang/test/Driver/fuchsia.cpp @@ -13,16 +13,23 @@ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=lld 2>&1 \ // RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64 %s +// RUN: %clangxx %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia -m32 \ +// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=lld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64-M32 %s // CHECK: {{.*}}clang{{.*}}" "-cc1" // CHECK-X86_64: "-triple" "x86_64-unknown-fuchsia" // CHECK-AARCH64: "-triple" "aarch64-unknown-fuchsia" // CHECK-RISCV64: "-triple" "riscv64-unknown-fuchsia" +// CHECK-X86_64-M32: "-triple" "i386-unknown-fuchsia" // CHECK-NOT: "-fno-use-init-array" // CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]" // CHECK-X86_64: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}x86_64-unknown-fuchsia{{/|\\\\}}c++{{/|\\\\}}v1" // CHECK-AARCH64: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}aarch64-unknown-fuchsia{{/|\\\\}}c++{{/|\\\\}}v1" // CHECK-RISCV64: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}riscv64-unknown-fuchsia{{/|\\\\}}c++{{/|\\\\}}v1" +// CHECK-X86_64-M32: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}x86_64-unknown-fuchsia{{/|\\\\}}c++{{/|\\\\}}v1" // CHECK: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}c++{{/|\\\\}}v1" // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|\\\\}}include" // CHECK: {{.*}}ld.lld{{.*}}" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" @@ -42,6 +49,7 @@ // CHECK-X86_64: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}x86_64-unknown-fuchsia{{/|\\\\}}libclang_rt.builtins.a" // CHECK-AARCH64: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aarch64-unknown-fuchsia{{/|\\\\}}libclang_rt.builtins.a" // CHECK-RISCV64: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}riscv64-unknown-fuchsia{{/|\\\\}}libclang_rt.builtins.a" +// CHECK-X86_64-M32: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}i386-unknown-fuchsia{{/|\\\\}}libclang_rt.builtins.a" // CHECK: "-lc" // CHECK-NOT: crtend.o // CHECK-NOT: crtn.o