]> granicus.if.org Git - llvm/commitdiff
Revert [Support] Fix recursive response file expansion guard
authorShoaib Meenai <smeenai@fb.com>
Mon, 15 Apr 2019 22:51:53 +0000 (22:51 +0000)
committerShoaib Meenai <smeenai@fb.com>
Mon, 15 Apr 2019 22:51:53 +0000 (22:51 +0000)
This reverts r358452 (git commit c8df4fb9c3865eac52a99602c26bbc070098c3d4)

A dependent commit breaks the Windows buildbots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358460 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/CommandLine.cpp
unittests/Support/CommandLineTest.cpp

index 0050002ff054dfa58dec51a18270bad3bf30bf46..98d06f65c79894549695529c215f21c0f38ac6cd 100644 (file)
@@ -1040,7 +1040,7 @@ static bool ExpandResponseFile(StringRef FName, StringSaver &Saver,
 bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
                              SmallVectorImpl<const char *> &Argv,
                              bool MarkEOLs, bool RelativeNames) {
-  unsigned ExpandedRspFiles = 0;
+  unsigned RspFiles = 0;
   bool AllExpanded = true;
 
   // Don't cache Argv.size() because it can change.
@@ -1058,16 +1058,14 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
 
     // If we have too many response files, leave some unexpanded.  This avoids
     // crashing on self-referential response files.
-    if (ExpandedRspFiles > 20)
+    if (RspFiles++ > 20)
       return false;
 
     // Replace this response file argument with the tokenization of its
     // contents.  Nested response files are expanded in subsequent iterations.
     SmallVector<const char *, 0> ExpandedArgv;
-    if (ExpandResponseFile(Arg + 1, Saver, Tokenizer, ExpandedArgv, MarkEOLs,
-                           RelativeNames)) {
-      ++ExpandedRspFiles;
-    } else {
+    if (!ExpandResponseFile(Arg + 1, Saver, Tokenizer, ExpandedArgv,
+                            MarkEOLs, RelativeNames)) {
       // We couldn't read this file, so we leave it in the argument stream and
       // move on.
       AllExpanded = false;
index 99db7e2d86cdf3aab24aa7b00737c4389b0ebc8b..782a8169ec0bfc21a6d90d2bd707f125e9613361 100644 (file)
@@ -813,43 +813,6 @@ TEST(CommandLineTest, RecursiveResponseFiles) {
     EXPECT_STREQ(Argv[i], ResponseFileRef.c_str());
 }
 
-TEST(CommandLineTest, ResponseFilesAtArguments) {
-  SmallString<128> TestDir;
-  std::error_code EC = sys::fs::createUniqueDirectory("unittest", TestDir);
-  EXPECT_TRUE(!EC);
-
-  SmallString<128> ResponseFilePath;
-  sys::path::append(ResponseFilePath, TestDir, "test.rsp");
-
-  std::ofstream ResponseFile(ResponseFilePath.c_str());
-  EXPECT_TRUE(ResponseFile.is_open());
-  ResponseFile << "-foo" << "\n";
-  ResponseFile << "-bar" << "\n";
-  ResponseFile.close();
-
-  // Ensure we expand rsp files after lots of non-rsp arguments starting with @.
-  constexpr size_t NON_RSP_AT_ARGS = 64;
-  llvm::SmallVector<const char *, 4> Argv = {"test/test"};
-  Argv.append(NON_RSP_AT_ARGS, "@non_rsp_at_arg");
-  std::string ResponseFileRef = std::string("@") + ResponseFilePath.c_str();
-  Argv.push_back(ResponseFileRef.c_str());
-
-  llvm::BumpPtrAllocator A;
-  llvm::StringSaver Saver(A);
-  bool Res = llvm::cl::ExpandResponseFiles(
-      Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, false);
-  EXPECT_FALSE(Res);
-
-  // ASSERT instead of EXPECT to prevent potential out-of-bounds access.
-  ASSERT_EQ(Argv.size(), 1 + NON_RSP_AT_ARGS + 2);
-  size_t i = 0;
-  EXPECT_STREQ(Argv[i++], "test/test");
-  for (; i < 1 + NON_RSP_AT_ARGS; ++i)
-    EXPECT_STREQ(Argv[i], "@non_rsp_at_arg");
-  EXPECT_STREQ(Argv[i++], "-foo");
-  EXPECT_STREQ(Argv[i++], "-bar");
-}
-
 TEST(CommandLineTest, SetDefautValue) {
   cl::ResetCommandLineParser();