[Driver] [C++20] [Modules] Don't emit unused-argument warning for '-fmodule-output...
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Mon, 16 Jan 2023 06:07:58 +0000 (14:07 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Mon, 16 Jan 2023 06:08:02 +0000 (14:08 +0800)
Suppres the r unused-argument warning for -fmodule-output according to
the discussion thread in
https://gcc.gnu.org/pipermail/gcc/2022-December/240239.html.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D140001

clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/module-output.cppm

index b2eadaf..5462634 100644 (file)
@@ -3798,6 +3798,10 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
     Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation);
   }
 
+  // Claim `-fmodule-output` and `-fmodule-output=` to avoid unused warnings.
+  Args.ClaimAllArgs(options::OPT_fmodule_output);
+  Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
+
   return HaveModules;
 }
 
index 604cd17..a01531b 100644 (file)
@@ -27,6 +27,9 @@
 // in the comamnd line.
 // RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/pcm/Hello.pcm -o %t/Hello.o \
 // RUN:   -c -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-SPECIFIED
+//
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/Hello.pcm -fmodule-output -c -fsyntax-only \
+// RUN:   -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-NOT-USED
 
 //--- Hello.cppm
 export module Hello;
@@ -39,6 +42,11 @@ export module Hello;
 // CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/pcm/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
 // CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/pcm/Hello.pcm"
 
+// CHECK-NOT-USED-NOT: warning: argument unused during compilation: '-fmodule-output'
+// CHECK-NOT-USED-NOT: warning: argument unused during compilation: '-fmodule-output=Hello.pcm'
+// CHECK-NOT-USED-NOT: "-fmodule-output"
+// CHECK-NOT-USED-NOT: "-fmodule-output="
+
 //--- AnotherModule.cppm
 export module AnotherModule;
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"