Skip to content

Commit 6fd498c

Browse files
author
git apple-llvm automerger
committed
Merge commit '72c29fa9e226' from llvm.org/main into next
2 parents 90b66d3 + 72c29fa commit 6fd498c

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ Improvements to Clang's diagnostics
328328
- New ``-Wformat-signedness`` diagnostic that warn if the format string requires an
329329
unsigned argument and the argument is signed and vice versa.
330330

331+
- Clang now emits ``unused argument`` warning when the -fmodule-output flag is used
332+
with an input that is not of type c++-module.
333+
331334
Improvements to Clang's time-trace
332335
----------------------------------
333336

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,9 +4052,18 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
40524052
// module fragment.
40534053
CmdArgs.push_back("-fskip-odr-check-in-gmf");
40544054

4055-
// Claim `-fmodule-output` and `-fmodule-output=` to avoid unused warnings.
4056-
Args.ClaimAllArgs(options::OPT_fmodule_output);
4057-
Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
4055+
// We need to include the case the input file is a module file here.
4056+
// Since the default compilation model for C++ module interface unit will
4057+
// create temporary module file and compile the temporary module file
4058+
// to get the object file. Then the `-fmodule-output` flag will be
4059+
// brought to the second compilation process. So we have to claim it for
4060+
// the case too.
4061+
if (Input.getType() == driver::types::TY_CXXModule ||
4062+
Input.getType() == driver::types::TY_PP_CXXModule ||
4063+
Input.getType() == driver::types::TY_ModuleFile) {
4064+
Args.ClaimAllArgs(options::OPT_fmodule_output);
4065+
Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
4066+
}
40584067

40594068
return HaveModules;
40604069
}

clang/test/Driver/module-output.cppm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/Hello.pcm -fmodule-output -c -fsyntax-only \
3434
// RUN: -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-NOT-USED
3535

36+
// Test that we can emit a warning if the type of the input file is not a module interface unit.
37+
// RUN: %clang -std=c++20 %t/a.cpp -fmodule-output -c -o %t/a.o -### 2>&1 | FileCheck %t/a.cpp
38+
3639
//--- Hello.cppm
3740
export module Hello;
3841

@@ -55,3 +58,8 @@ export module AnotherModule;
5558
// CHECK: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello-{{.*}}.o" "-x" "pcm" "{{.*}}/Hello.pcm"
5659
// CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "AnotherModule.cppm" {{.*}}"-o" "{{.*}}/AnotherModule.pcm" "-x" "c++" "{{.*}}/AnotherModule.cppm"
5760
// CHECK: "-emit-obj" {{.*}}"-main-file-name" "AnotherModule.cppm" {{.*}}"-o" "{{.*}}/AnotherModule-{{.*}}.o" "-x" "pcm" "{{.*}}/AnotherModule.pcm"
61+
62+
//--- a.cpp
63+
export module a;
64+
65+
// CHECK: warning: argument unused during compilation: '-fmodule-output'

0 commit comments

Comments
 (0)