OSDN Git Service

Fix broken asan Support tests
authorEric Liu <ioeric@google.com>
Tue, 15 May 2018 13:43:20 +0000 (13:43 +0000)
committerEric Liu <ioeric@google.com>
Tue, 15 May 2018 13:43:20 +0000 (13:43 +0000)
The asan failures were caught in google internal asan tests after r332311
o Make StackOption support cl::list
o Rememeber to removeArguments for cl::alias in tests.

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

unittests/Support/CommandLineTest.cpp

index a52420f..8e5e9ad 100644 (file)
@@ -51,9 +51,8 @@ class TempEnvVar {
   const char *const name;
 };
 
-template <typename T>
-class StackOption : public cl::opt<T> {
-  typedef cl::opt<T> Base;
+template <typename T, typename Base = cl::opt<T>>
+class StackOption : public Base {
 public:
   // One option...
   template<class M0t>
@@ -72,6 +71,12 @@ public:
   StackOption(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
     : Base(M0, M1, M2, M3) {}
 
+  // Five options...
+  template <class M0t, class M1t, class M2t, class M3t, class M4t>
+  StackOption(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
+              const M4t &M4)
+      : Base(M0, M1, M2, M3, M4) {}
+
   ~StackOption() override { this->removeArgument(); }
 
   template <class DT> StackOption<T> &operator=(const DT &V) {
@@ -636,8 +641,8 @@ TEST(CommandLineTest, ResponseFileWindows) {
   if (!Triple(sys::getProcessTriple()).isOSWindows())
     return;
 
-  static cl::list<std::string>
-         InputFilenames(cl::Positional, cl::desc("<input files>"), cl::ZeroOrMore);
+  StackOption<std::string, cl::list<std::string>> InputFilenames(
+      cl::Positional, cl::desc("<input files>"), cl::ZeroOrMore);
   StackOption<bool> TopLevelOpt("top-level", cl::init(false));
 
   // Create response file.
@@ -760,6 +765,7 @@ TEST(CommandLineTest, SetDefautValue) {
   EXPECT_TRUE(Opt1 == "true");
   EXPECT_TRUE(Opt2);
   EXPECT_TRUE(Opt3 == 3);
+  Alias.removeArgument();
 }
 
 TEST(CommandLineTest, ReadConfigFile) {
@@ -817,9 +823,9 @@ TEST(CommandLineTest, ReadConfigFile) {
 }
 
 TEST(CommandLineTest, PositionalEatArgsError) {
-  static cl::list<std::string> PosEatArgs("positional-eat-args", cl::Positional,
-    cl::desc("<arguments>..."), cl::ZeroOrMore,
-    cl::PositionalEatsArgs);
+  StackOption<std::string, cl::list<std::string>> PosEatArgs(
+      "positional-eat-args", cl::Positional, cl::desc("<arguments>..."),
+      cl::ZeroOrMore, cl::PositionalEatsArgs);
 
   const char *args[] = {"prog", "-positional-eat-args=XXXX"};
   const char *args2[] = {"prog", "-positional-eat-args=XXXX", "-foo"};