|
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"
|
@@ -1697,6 +1699,17 @@ RedirectCallFromSinkToTrampolineFunction(llvm::Module &module,
|
1697 | 1699 | return true;
|
1698 | 1700 | }
|
1699 | 1701 |
|
| 1702 | +static bool ContainsUB(llvm::Module &module) { |
| 1703 | + for (llvm::Function &function : module) |
| 1704 | + for (llvm::BasicBlock &bb : function) |
| 1705 | + for (llvm::Instruction &i : bb) |
| 1706 | + if (auto *memcpy = llvm::dyn_cast<llvm::MemCpyInst>(&i)) |
| 1707 | + if (llvm::isa<llvm::UndefValue>(memcpy->getOperand(0)) || |
| 1708 | + llvm::isa<llvm::UndefValue>(memcpy->getOperand(1))) |
| 1709 | + return true; |
| 1710 | + return false; |
| 1711 | +} |
| 1712 | + |
1700 | 1713 | /// Add additional context that is otherwise hard to convey.
|
1701 | 1714 | static void AnnotateDiagnostics(DiagnosticManager &diagnostic_manager) {
|
1702 | 1715 | bool append_missing_library_note = false;
|
@@ -2086,6 +2099,17 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
|
2086 | 2099 | m_module.reset(ContextAndModule.second);
|
2087 | 2100 | }
|
2088 | 2101 |
|
| 2102 | + // In rare cases missing type information results in IRGen lowering |
| 2103 | + // values into SILUndef. This may be for a variable that isn't even |
| 2104 | + // used in the expression, so just warn about it. This is reported |
| 2105 | + // as an out-of-band warning, because LLDB suppresses warnings on |
| 2106 | + // successful expressions. |
| 2107 | + if (m_sc.target_sp && m_module && ContainsUB(*m_module)) |
| 2108 | + Debugger::ReportWarning( |
| 2109 | + "Expression contains undefined behavior. Expression results may be " |
| 2110 | + "incorrect. This may be due to incomplete Swift type information.", |
| 2111 | + m_sc.target_sp->GetDebugger().GetID()); |
| 2112 | + |
2089 | 2113 | // If IRGen failed without errors, the root cause may be a fatal
|
2090 | 2114 | // Clang diagnostic.
|
2091 | 2115 | using ErrorKind = SwiftASTContext::ScopedDiagnostics::ErrorKind;
|
|
0 commit comments