Skip to content

Conversation

@naveen-seth
Copy link
Contributor

When -nostdlib is specified, Clang should not report any library‑provided module manifest, even if a manifest for the default standard library is present.

@naveen-seth naveen-seth added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules labels Sep 29, 2025
@llvmbot llvmbot added the clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' label Sep 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 29, 2025

@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: Naveen Seth Hanig (naveen-seth)

Changes

When -nostdlib is specified, Clang should not report any library‑provided module manifest, even if a manifest for the default standard library is present.


Full diff: https://github.com/llvm/llvm-project/pull/161110.diff

2 Files Affected:

  • (modified) clang/lib/Driver/Driver.cpp (+3)
  • (modified) clang/test/Driver/modules-print-library-module-manifest-path.cpp (+8)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index f110dbab3e5a5..85a1335785542 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -6613,6 +6613,9 @@ std::string Driver::GetStdModuleManifestPath(const Compilation &C, const ToolChain &TC) const { std::string error = "<NOT PRESENT>"; + if (C.getArgs().hasArg(options::OPT_nostdlib)) + return error; + switch (TC.GetCXXStdlibType(C.getArgs())) { case ToolChain::CST_Libcxx: { auto evaluate = [&](const char *library) -> std::optional<std::string> { diff --git a/clang/test/Driver/modules-print-library-module-manifest-path.cpp b/clang/test/Driver/modules-print-library-module-manifest-path.cpp index 7606713bfa22a..ba4c2cd4524cd 100644 --- a/clang/test/Driver/modules-print-library-module-manifest-path.cpp +++ b/clang/test/Driver/modules-print-library-module-manifest-path.cpp @@ -18,6 +18,14 @@ // RUN: --target=x86_64-linux-gnu 2>&1 \ // RUN: | FileCheck libcxx.cpp +// check that -nostdlib causes no library-provided module manifest to +// be reported, // even when libc++.modules.json is present. +// RUN: %clang -print-library-module-manifest-path \ +// RUN: -nostdlib \ +// RUN: -resource-dir=%t/Inputs/usr/lib/x86_64-linux-gnu \ +// RUN: --target=x86_64-linux-gnu 2>&1 \ +// RUN: | FileCheck libcxx-no-module-json.cpp + // for macos there is a different directory structure // where the library and libc++.modules.json file are in lib // directly but headers are in clang/ver directory which 
@naveen-seth
Copy link
Contributor Author

This ties into #152770. For driver-managed module builds, -nostdlib should ensure that standard library modules are not implicitly imported. The logic doesn’t necessarily have to be here, but I thought it would be a reasonable location.

When -nostdlib is specified, Clang should not report any library‑provided module manifest, even if a manifest for the default standard library is present.
@naveen-seth naveen-seth force-pushed the get-manifest-path-no-stdlib branch from f22a06d to dee3897 Compare September 29, 2025 01:10
@naveen-seth naveen-seth merged commit b555c99 into llvm:main Sep 29, 2025
9 checks passed
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
…lvm#161110) When -nostdlib is specified, Clang should not report any library‑provided module manifest, even if a manifest for the default standard library is present.
@naveen-seth naveen-seth deleted the get-manifest-path-no-stdlib branch October 20, 2025 14:33
naveen-seth added a commit to naveen-seth/llvm-project that referenced this pull request Oct 24, 2025
This change was enabled by llvm#161110. Previously, it was not possible to disable reading the standard modules manifest with `-nostdlib`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category

3 participants