|
24 | 24 | #include "SwiftUserExpression.h"
|
25 | 25 |
|
26 | 26 | #include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
|
| 27 | +#include "lldb/Core/Debugger.h" |
27 | 28 | #include "lldb/Core/Module.h"
|
28 | 29 | #include "lldb/Core/ModuleList.h"
|
29 | 30 | #include "lldb/Core/ModuleSpec.h"
|
|
50 | 51 | #include "llvm/ADT/StringRef.h"
|
51 | 52 | #include "llvm/BinaryFormat/Dwarf.h"
|
52 | 53 | #include "llvm/IR/IRBuilder.h"
|
| 54 | +#include "llvm/IR/IntrinsicInst.h" |
53 | 55 | #include "llvm/IR/LLVMContext.h"
|
54 | 56 | #include "llvm/IR/Module.h"
|
55 | 57 | #include "llvm/IR/Verifier.h"
|
@@ -1700,6 +1702,17 @@ RedirectCallFromSinkToTrampolineFunction(llvm::Module &module,
|
1700 | 1702 | return true;
|
1701 | 1703 | }
|
1702 | 1704 |
|
| 1705 | +static bool ContainsUB(llvm::Module &module) { |
| 1706 | + for (llvm::Function &function : module) |
| 1707 | + for (llvm::BasicBlock &bb : function) |
| 1708 | + for (llvm::Instruction &i : bb) |
| 1709 | + if (auto *memcpy = llvm::dyn_cast<llvm::MemCpyInst>(&i)) |
| 1710 | + if (llvm::isa<llvm::UndefValue>(memcpy->getOperand(0)) || |
| 1711 | + llvm::isa<llvm::UndefValue>(memcpy->getOperand(1))) |
| 1712 | + return true; |
| 1713 | + return false; |
| 1714 | +} |
| 1715 | + |
1703 | 1716 | /// Add additional context that is otherwise hard to convey.
|
1704 | 1717 | static void AnnotateDiagnostics(DiagnosticManager &diagnostic_manager) {
|
1705 | 1718 | bool append_missing_library_note = false;
|
@@ -2089,6 +2102,17 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
|
2089 | 2102 | m_module.reset(ContextAndModule.second);
|
2090 | 2103 | }
|
2091 | 2104 |
|
| 2105 | + // In rare cases missing type information results in IRGen lowering |
| 2106 | + // values into SILUndef. This may be for a variable that isn't even |
| 2107 | + // used in the expression, so just warn about it. This is reported |
| 2108 | + // as an out-of-band warning, because LLDB suppresses warnings on |
| 2109 | + // successful expressions. |
| 2110 | + if (m_sc.target_sp && m_module && ContainsUB(*m_module)) |
| 2111 | + Debugger::ReportWarning( |
| 2112 | + "Expression contains undefined behavior. Expression results may be " |
| 2113 | + "incorrect. This may be due to incomplete Swift type information.", |
| 2114 | + m_sc.target_sp->GetDebugger().GetID()); |
| 2115 | + |
2092 | 2116 | // If IRGen failed without errors, the root cause may be a fatal
|
2093 | 2117 | // Clang diagnostic.
|
2094 | 2118 | using ErrorKind = SwiftASTContext::ScopedDiagnostics::ErrorKind;
|
|
0 commit comments