diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -421,9 +421,8 @@ // We only tell you about the FixIt if we applied it. The compiler errors // will suggest the FixIt if it parsed. if (!m_fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) { - if (success == eExpressionCompleted) - error_stream.Printf(" Fix-it applied, fixed expression was: \n %s\n", - m_fixed_expression.c_str()); + error_stream.Printf(" Fix-it applied, fixed expression was: \n %s\n", + m_fixed_expression.c_str()); } if (result_valobj_sp) { diff --git a/lldb/test/API/commands/expression/fixits/TestFixIts.py b/lldb/test/API/commands/expression/fixits/TestFixIts.py --- a/lldb/test/API/commands/expression/fixits/TestFixIts.py +++ b/lldb/test/API/commands/expression/fixits/TestFixIts.py @@ -82,6 +82,22 @@ error_string.find("my_pointer->second.a") != -1, "Fix was right") + def test_with_target_error_applies_fixit(self): + """ Check that applying a Fix-it which fails to execute correctly still + prints that the Fix-it was applied. """ + self.build() + (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + 'Stop here to evaluate expressions', + lldb.SBFileSpec("main.cpp")) + # Enable fix-its as they were intentionally disabled by TestBase.setUp. + self.runCmd("settings set target.auto-apply-fixits true") + ret_val = lldb.SBCommandReturnObject() + result = self.dbg.GetCommandInterpreter().HandleCommand("expression null_pointer.first", ret_val) + self.assertEqual(result, lldb.eReturnStatusFailed, ret_val.GetError()) + + self.assertIn("Fix-it applied, fixed expression was:", ret_val.GetError()) + self.assertIn("null_pointer->first", ret_val.GetError()) + # The final function call runs into SIGILL on aarch64-linux. @expectedFailureAll(archs=["aarch64"], oslist=["freebsd", "linux"], bugnumber="llvm.org/pr49407") diff --git a/lldb/test/API/commands/expression/fixits/main.cpp b/lldb/test/API/commands/expression/fixits/main.cpp --- a/lldb/test/API/commands/expression/fixits/main.cpp +++ b/lldb/test/API/commands/expression/fixits/main.cpp @@ -17,6 +17,7 @@ { struct MyStruct my_struct = {10, {20, 30}}; struct MyStruct *my_pointer = &my_struct; + struct MyStruct *null_pointer = nullptr; printf ("Stop here to evaluate expressions: %d %d %p\n", my_pointer->first, my_pointer->second.a, my_pointer); return 0; }