[Lldb-commits] [lldb] [LLDB] Add `ScalarLiteralNode` and literal parsing in DIL (PR #152308)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 14 06:06:25 PDT 2025
================
@@ -0,0 +1,76 @@
+"""
+Test DIL literals.
+"""
+
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+from lldbsuite.test import lldbutil
+
+
+class TestFrameVarDILLiterals(TestBase):
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def test_literals(self):
+ self.build()
+ (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+ self, "Set a breakpoint here", lldb.SBFileSpec("main.cpp")
+ )
+
+ self.runCmd("settings set target.experimental.use-DIL true")
+
+ # Check number literals parsing
+ self.expect_var_path("1.0", value="1", type="double")
+ self.expect_var_path("1.0f", value="1", type="float")
+ self.expect_var_path("0x1.2p+3f", value="9", type="float")
+ self.expect_var_path("1", value="1", type="int")
+ self.expect_var_path("1u", value="1", type="unsigned int")
+ self.expect_var_path("0b1l", value="1", type="long")
+ self.expect_var_path("01ul", value="1", type="unsigned long")
+ self.expect_var_path("01lu", value="1", type="unsigned long")
+ self.expect_var_path("0o1ll", value="1", type="long long")
+ self.expect_var_path("0x1ULL", value="1", type="unsigned long long")
+ self.expect_var_path("0x1llu", value="1", type="unsigned long long")
+ self.expect(
+ "frame var '1ullu'",
+ error=True,
+ substrs=["Failed to parse token as numeric-constant"],
+ )
+
+ # Check integer literal type edge cases (dil::Interpreter::PickIntegerType)
+ frame = thread.GetFrameAtIndex(0)
+ v = frame.GetValueForVariablePath("argc")
+ # Creating an SBType from a BasicType still requires any value from the frame
+ int_size = v.GetType().GetBasicType(lldb.eBasicTypeInt).GetByteSize()
+ long_size = v.GetType().GetBasicType(lldb.eBasicTypeLong).GetByteSize()
+ longlong_size = v.GetType().GetBasicType(lldb.eBasicTypeLongLong).GetByteSize()
+
+ longlong_str = "0x" + "F" * longlong_size * 2
+ longlong_str = str(int(longlong_str, 16))
+ self.assert_literal_type(frame, longlong_str, lldb.eBasicTypeUnsignedLongLong)
+ toolong_str = "0x" + "F" * longlong_size * 2 + "F"
+ self.expect(
+ f"frame var '{toolong_str}'",
+ error=True,
+ substrs=[
+ "integer literal is too large to be represented in any integer type"
+ ],
+ )
+
+ # These check only apply if `int` and `long` have different sizes
----------------
labath wrote:
if `int` and `long` are the same size, then `long` and `long long` likely aren't, so you could perform the same check with those two.
https://github.com/llvm/llvm-project/pull/152308
More information about the lldb-commits
mailing list