Skip to content

Conversation

@JDevlieghere
Copy link
Member

Both the default value and the min/max value are within LLDB's control, so an assert is more appropriate than a runtime check.

Both the default value and the min/max value are within LLDB's control,
so an assert is more appropriate than a runtime check.

(cherry picked from commit 1a1d0d5a12e310e23e8fd63eaa810c6af5420312)
@llvmbot llvmbot added the lldb label Feb 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 10, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

Both the default value and the min/max value are within LLDB's control, so an assert is more appropriate than a runtime check.


Full diff: https://github.com/llvm/llvm-project/pull/126590.diff

2 Files Affected:

  • (modified) lldb/include/lldb/Interpreter/OptionValueSInt64.h (+4-5)
  • (modified) lldb/include/lldb/Interpreter/OptionValueUInt64.h (+6-7)
diff --git a/lldb/include/lldb/Interpreter/OptionValueSInt64.h b/lldb/include/lldb/Interpreter/OptionValueSInt64.h
index 3cf41d38c0ef0c5..f7e72684e4102f9 100644
--- a/lldb/include/lldb/Interpreter/OptionValueSInt64.h
+++ b/lldb/include/lldb/Interpreter/OptionValueSInt64.h
@@ -68,11 +68,10 @@ class OptionValueSInt64 : public Cloneable<OptionValueSInt64, OptionValue> {
   }
 
   bool SetDefaultValue(int64_t value) {
-    if (value >= m_min_value && value <= m_max_value) {
-      m_default_value = value;
-      return true;
-    }
-    return false;
+    assert(value >= m_min_value && value <= m_max_value &&
+           "disallowed default value");
+    m_default_value = value;
+    return true;
   }
 
   void SetMinimumValue(int64_t v) { m_min_value = v; }
diff --git a/lldb/include/lldb/Interpreter/OptionValueUInt64.h b/lldb/include/lldb/Interpreter/OptionValueUInt64.h
index 07076075790c674..5cccff177cb1d60 100644
--- a/lldb/include/lldb/Interpreter/OptionValueUInt64.h
+++ b/lldb/include/lldb/Interpreter/OptionValueUInt64.h
@@ -73,18 +73,17 @@ class OptionValueUInt64 : public Cloneable<OptionValueUInt64, OptionValue> {
   }
 
   bool SetDefaultValue(uint64_t value) {
-    if (value >= m_min_value && value <= m_max_value) {
-      m_default_value = value;
-      return true;
-    }
-    return false;
+    assert(value >= m_min_value && value <= m_max_value &&
+           "disallowed default value");
+    m_default_value = value;
+    return true;
   }
 
-  void SetMinimumValue(int64_t v) { m_min_value = v; }
+  void SetMinimumValue(uint64_t v) { m_min_value = v; }
 
   uint64_t GetMinimumValue() const { return m_min_value; }
 
-  void SetMaximumValue(int64_t v) { m_max_value = v; }
+  void SetMaximumValue(uint64_t v) { m_max_value = v; }
 
   uint64_t GetMaximumValue() const { return m_max_value; }
 

return true;
}
return false;
assert(value >= m_min_value && value <= m_max_value &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things I'd like to make sure of:

  • What happens in release configurations where assertions are compiled out? Might this allow you to set an invalid value?
  • Can you call SetDefaultValue by typing a command in lldb? If so, an assertion seems like the wrong way of catching this. I ask because this is in OptionValue, which are involved in parsing commands in LLDB.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the default value is set by LLDB itself. The situation this assert catches is someone defining a default value in the tablegen file that's larger or smaller than the mix/max value. AFAIK there is no way for a user to set a default value.

Currently, SetMinValue is only called for the terminal width and height. There are no other users.

@JDevlieghere JDevlieghere merged commit f451d27 into llvm:main Feb 10, 2025
9 checks passed
@JDevlieghere JDevlieghere deleted the default-value-check branch February 10, 2025 23:10
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
Both the default value and the min/max value are within LLDB's control,
so an assert is more appropriate than a runtime check.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
Both the default value and the min/max value are within LLDB's control,
so an assert is more appropriate than a runtime check.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
Both the default value and the min/max value are within LLDB's control,
so an assert is more appropriate than a runtime check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants