]> granicus.if.org Git - llvm/commitdiff
Revert "[FileCheck] Simplify numeric variable interface"
authorMichael Liao <michael.hliao@gmail.com>
Fri, 5 Jul 2019 22:23:27 +0000 (22:23 +0000)
committerMichael Liao <michael.hliao@gmail.com>
Fri, 5 Jul 2019 22:23:27 +0000 (22:23 +0000)
This reverts commit 096600a4b073dd94a366cc8e57bff93c34ff6966.

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

include/llvm/Support/FileCheck.h
lib/Support/FileCheck.cpp
unittests/Support/FileCheckTest.cpp

index b3a8433b54e658909e8fc51950716c1ae3a65ad5..dea68ba482c2e1b4e9f7fc6b7898368fbec1c261 100644 (file)
@@ -69,13 +69,13 @@ public:
   /// \returns this variable's value.
   Optional<uint64_t> getValue() const { return Value; }
 
-  /// Sets value of this numeric variable, if undefined. Triggers an assertion
-  /// failure if the variable is actually defined.
-  void setValue(uint64_t Value);
+  /// Sets value of this numeric variable if not defined. \returns whether the
+  /// variable was already defined.
+  bool setValue(uint64_t Value);
 
-  /// Clears value of this numeric variable, regardless of whether it is
-  /// currently defined or not.
-  void clearValue();
+  /// Clears value of this numeric variable. \returns whether the variable was
+  /// already undefined.
+  bool clearValue();
 
   /// \returns the line number where this variable is defined.
   size_t getDefLineNumber() { return DefLineNumber; }
index 12431d985e8bac35356fa532dbfa824aa1d3fad6..03e892af274668b85503a64fec7f174901e7ed4d 100644 (file)
 
 using namespace llvm;
 
-void FileCheckNumericVariable::setValue(uint64_t NewValue) {
-  assert(!Value && "Overwriting numeric variable's value is not allowed");
+bool FileCheckNumericVariable::setValue(uint64_t NewValue) {
+  if (Value)
+    return true;
   Value = NewValue;
+  return false;
 }
 
-void FileCheckNumericVariable::clearValue() {
+bool FileCheckNumericVariable::clearValue() {
   if (!Value)
-    return;
+    return true;
   Value = None;
+  return false;
 }
 
 Expected<uint64_t> FileCheckExpression::eval() const {
@@ -620,7 +623,8 @@ Expected<size_t> FileCheckPattern::match(StringRef Buffer, size_t &MatchLen,
     if (MatchedValue.getAsInteger(10, Val))
       return FileCheckErrorDiagnostic::get(SM, MatchedValue,
                                            "Unable to represent numeric value");
-    DefinedNumericVariable->setValue(Val);
+    if (DefinedNumericVariable->setValue(Val))
+      llvm_unreachable("Numeric variable redefined");
   }
 
   // Like CHECK-NEXT, CHECK-EMPTY's match range is considered to start after
index 3b44f5ee3b52135e4feec0fa7d56c7e8c730bfea..7fcd5bba608b2426fc073960f108de77f339afb4 100644 (file)
@@ -15,23 +15,28 @@ namespace {
 class FileCheckTest : public ::testing::Test {};
 
 TEST_F(FileCheckTest, NumericVariable) {
-  // Undefined variable: getValue fails, setValue does not trigger assert.
+  // Undefined variable: getValue and clearValue fails, setValue works.
   FileCheckNumericVariable FooVar = FileCheckNumericVariable(1, "FOO");
   EXPECT_EQ("FOO", FooVar.getName());
   llvm::Optional<uint64_t> Value = FooVar.getValue();
   EXPECT_FALSE(Value);
-  FooVar.clearValue();
-  FooVar.setValue(42);
+  EXPECT_TRUE(FooVar.clearValue());
+  EXPECT_FALSE(FooVar.setValue(42));
 
-  // Defined variable: getValue returns value set.
+  // Defined variable: getValue returns value set, setValue fails.
+  Value = FooVar.getValue();
+  EXPECT_TRUE(Value);
+  EXPECT_EQ(42U, *Value);
+  EXPECT_TRUE(FooVar.setValue(43));
   Value = FooVar.getValue();
   EXPECT_TRUE(Value);
   EXPECT_EQ(42U, *Value);
 
-  // Clearing variable: getValue fails.
-  FooVar.clearValue();
+  // Clearing variable: getValue fails, clearValue again fails.
+  EXPECT_FALSE(FooVar.clearValue());
   Value = FooVar.getValue();
   EXPECT_FALSE(Value);
+  EXPECT_TRUE(FooVar.clearValue());
 }
 
 uint64_t doAdd(uint64_t OpL, uint64_t OpR) { return OpL + OpR; }