================
@@ -172,3 +172,101 @@ def test_type_conversions(self):
self.assertEqual(short_val.GetValueAsSigned(), -1)
long_val = target.EvaluateExpression("(long) " + short_val.GetName())
self.assertEqual(long_val.GetValueAsSigned(), -1)
+
+ def test_fpconv(self):
+ self.build_and_run()
+
+ interp_options = lldb.SBExpressionOptions()
+ interp_options.SetLanguage(lldb.eLanguageTypeC_plus_plus)
+ interp_options.SetAllowJIT(False)
+
+ jit_options = lldb.SBExpressionOptions()
+ jit_options.SetLanguage(lldb.eLanguageTypeC_plus_plus)
+ jit_options.SetAllowJIT(True)
+
+ set_up_expressions = [
+ "int $i = 3",
+ "int $n = -3",
+ "unsigned $u = 5",
+ "long $l = -7",
+ "float $f = 9.0625",
+ "double $d = 13.75",
+ "float $nf = -11.25",
+ ]
+
+ expressions = [
+ "$i + $f", # sitofp i32 to float
+ "$d - $n", # sitofp i32 to double
+ "$u + $f", # uitofp i32 to float
+ "$u + $d", # uitofp i32 to double
+ "(int)$d", # fptosi double to i32
+ "(int)$f", # fptosi float to i32
+ "(long)$d", # fptosi double to i64
+ "(short)$f", # fptosi float to i16
+ "(long)$nf", # fptosi float to i64
+ "(unsigned short)$f", # fptoui float to i16
+ "(unsigned)$d", # fptoui double to i32
+ "(unsigned long)$d", # fptoui double to i64
+ "(float)$d", # fptrunc double to float
+ "(double)$f", # fpext float to double
+ "(double)$nf", # fpext float to double
+ ]
+
+ for expression in set_up_expressions:
+ self.frame().EvaluateExpression(expression, interp_options)
+
+ func_call = "(int)getpid()"
+ if lldbplatformutil.getPlatform() == "windows":
+ func_call = "(int)GetCurrentProcessId()"
+
+ for expression in expressions:
+ interp_expression = expression
+ # Calling a function forces the expression to be executed with JIT.
+ jit_expression = func_call + "; " + expression
+
+ interp_result = self.frame().EvaluateExpression(
+ interp_expression, interp_options
+ )
+ jit_result = self.frame().EvaluateExpression(jit_expression,
jit_options)
+
+ self.assertEqual(
+ interp_result.GetValue(),
+ jit_result.GetValue(),
+ "Values match for " + expression,
+ )
+ self.assertEqual(
+ interp_result.GetTypeName(),
+ jit_result.GetTypeName(),
+ "Types match for " + expression,
+ )
+
+ def test_fpconv_ub(self):
+ target = self.dbg.GetDummyTarget()
+
+ set_up_expressions = [
+ "float $f = 3e9",
+ "double $d = 1e20",
+ "float $nf = -1.5",
+ ]
+
+ expressions = [
+ "(int)$f",
+ "(long)$d",
+ "(unsigned)$nf",
+ ]
+
+ for expression in set_up_expressions:
+ target.EvaluateExpression(expression)
+
+ # The IR Interpreter returns an error if a value cannot be converted.
+ for expression in expressions:
+ result = target.EvaluateExpression(expression)
+ self.assertIn(
+ "Interpreter couldn't convert a value", str(result.GetError())
+ )
----------------
Michael137 wrote:
Don't feel too strongly about this but I'm a bit wary of making the expression
evaluation more restrictive. What if a user has this in their code and wants to
run it as an expression? If the compiler didn't reject it and codegenned
something for it, should the expression evaluator really refuse to run the
expression because our IRInterpreter decided it wouldn't? Is there precedent
for that? I'm not fussed about checking that they evaluate to something
consistent/deterministic/sensible. Just whether we run the code in the first
place.
But there's probably not good way to fall back to JITted expressions? Or still
somehow try and perform the conversion?
https://github.com/llvm/llvm-project/pull/175292
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits