[PATCH] D70763: [clang][IFS] Allow 2 output files when using -o and -c with clang IFS stubs.

Puyan Lotfi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 26 21:10:20 PST 2019


plotfi created this revision.
plotfi added a reviewer: compnerd.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch allows for -o to be used with -c when compiling with clang interface stubs enabled. This is because the second file will be an intermediate ifs stubs file that is the text stub analog of the .o file. Both get produces in this case, so two files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70763

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/InterfaceStubs/driver-test3.c


Index: clang/test/InterfaceStubs/driver-test3.c
===================================================================
--- /dev/null
+++ clang/test/InterfaceStubs/driver-test3.c
@@ -0,0 +1,16 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: shell
+
+// RUN: mkdir -p %t; cd %t
+// RUN: %clang -target x86_64-unknown-linux-gnu -c -emit-interface-stubs %s -o %t/driver-test3.o
+// RUN: cat %t/driver-test3.ifs | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion:
+// CHECK-NEXT: Triple:
+// CHECK-NEXT: ObjectFileFormat:
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT:   "bar" : { Type: Func }
+// CHECK-NEXT: ...
+
+int bar(int a) { return a; }
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5621,8 +5621,16 @@
   if (Output.getType() == types::TY_Dependencies) {
     // Handled with other dependency code.
   } else if (Output.isFilename()) {
-    CmdArgs.push_back("-o");
-    CmdArgs.push_back(Output.getFilename());
+    if (Output.getType() == clang::driver::types::TY_IFS_CPP ||
+        Output.getType() == clang::driver::types::TY_IFS) {
+      SmallString<128> OutputFilename(Output.getFilename());
+      llvm::sys::path::replace_extension(OutputFilename, "ifs");
+      CmdArgs.push_back("-o");
+      CmdArgs.push_back(Args.MakeArgString(OutputFilename));
+    } else {
+      CmdArgs.push_back("-o");
+      CmdArgs.push_back(Output.getFilename());
+    }
   } else {
     assert(Output.isNothing() && "Invalid output.");
   }
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -3696,9 +3696,13 @@
   // location.
   if (FinalOutput) {
     unsigned NumOutputs = 0;
+    unsigned NumIfsOutputs = 0;
     for (const Action *A : C.getActions())
       if (A->getType() != types::TY_Nothing &&
           !(A->getKind() == Action::IfsMergeJobClass ||
+            (A->getType() == clang::driver::types::TY_IFS_CPP &&
+             A->getKind() == clang::driver::Action::CompileJobClass &&
+             0 == NumIfsOutputs++) ||
             (A->getKind() == Action::BindArchClass && A->getInputs().size() &&
              A->getInputs().front()->getKind() == Action::IfsMergeJobClass)))
         ++NumOutputs;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70763.231174.patch
Type: text/x-patch
Size: 2415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191127/ac668985/attachment.bin>


More information about the cfe-commits mailing list