aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2022-07-12 16:55:11 -0700
committerBen Langmuir <blangmuir@apple.com>2022-07-13 13:36:15 -0700
commit3ce78cbd2392d7c98f97d1d424cd7ff582fc28f8 (patch)
tree87623ae2a72558525fb43c9f21a166d43b8473db /clang/lib/Basic
parent94e0f8e001002b828c42048f383806295e7abbb2 (diff)
downloadllvm-3ce78cbd2392d7c98f97d1d424cd7ff582fc28f8.zip
llvm-3ce78cbd2392d7c98f97d1d424cd7ff582fc28f8.tar.gz
llvm-3ce78cbd2392d7c98f97d1d424cd7ff582fc28f8.tar.bz2
[clang][deps] Fix handling of -MT in module command-line
Follow-up to 6626f6fec3d3, this fixes the handling of -MT * If no targets are provided, we need to invent one since cc1 expects the driver to have handled it. The default is to use -o, quoting as necessary for a make target. * Fix the splitting for empty string, which was incorrectly treated as {""} instead of {}. * Add a way to test this behaviour in clang-scan-deps. Differential Revision: https://reviews.llvm.org/D129607
Diffstat (limited to 'clang/lib/Basic')
-rw-r--r--clang/lib/Basic/CMakeLists.txt1
-rw-r--r--clang/lib/Basic/MakeSupport.cpp35
2 files changed, 36 insertions, 0 deletions
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index c815b57..89dd332 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -54,6 +54,7 @@ add_clang_library(clangBasic
IdentifierTable.cpp
LangOptions.cpp
LangStandards.cpp
+ MakeSupport.cpp
Module.cpp
ObjCRuntime.cpp
OpenCLOptions.cpp
diff --git a/clang/lib/Basic/MakeSupport.cpp b/clang/lib/Basic/MakeSupport.cpp
new file mode 100644
index 0000000..37838f7
--- /dev/null
+++ b/clang/lib/Basic/MakeSupport.cpp
@@ -0,0 +1,35 @@
+//===-- MakeSuport.cpp --------------------------------------------------*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Basic/MakeSupport.h"
+
+void clang::quoteMakeTarget(StringRef Target, SmallVectorImpl<char> &Res) {
+ for (unsigned i = 0, e = Target.size(); i != e; ++i) {
+ switch (Target[i]) {
+ case ' ':
+ case '\t':
+ // Escape the preceding backslashes
+ for (int j = i - 1; j >= 0 && Target[j] == '\\'; --j)
+ Res.push_back('\\');
+
+ // Escape the space/tab
+ Res.push_back('\\');
+ break;
+ case '$':
+ Res.push_back('$');
+ break;
+ case '#':
+ Res.push_back('\\');
+ break;
+ default:
+ break;
+ }
+
+ Res.push_back(Target[i]);
+ }
+} \ No newline at end of file