[llvm] Minimal unwinding information (DWARF CFI) checker (PR #145633)
Paul Kirth via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 25 12:49:49 PDT 2025
================
@@ -0,0 +1,299 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/UnwindInfoChecker/UnwindInfoAnalysis.h"
+#include "Registers.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCDwarf.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCInstrInfo.h"
+#include "llvm/MC/MCRegister.h"
+#include "llvm/MC/MCRegisterInfo.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCSubtargetInfo.h"
+#include "llvm/MC/TargetRegistry.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/UnwindInfoChecker/UnwindInfoState.h"
+#include <cstdint>
+#include <optional>
+#include <set>
+
+using namespace llvm;
+
+struct CFARegOffsetInfo {
+ DWARFRegNum Reg;
+ int64_t Offset;
+
+ CFARegOffsetInfo(DWARFRegNum Reg, int64_t Offset)
+ : Reg(Reg), Offset(Offset) {}
+};
+
+static std::optional<CFARegOffsetInfo>
+getCFARegOffsetInfo(const dwarf::UnwindTable::const_iterator &UnwindRow) {
+ auto CFALocation = UnwindRow->getCFAValue();
+ if (CFALocation.getLocation() !=
+ dwarf::UnwindLocation::Location::RegPlusOffset) {
+ return std::nullopt;
+ }
+
+ return CFARegOffsetInfo(CFALocation.getRegister(), CFALocation.getOffset());
+}
+
+static std::optional<DWARFRegNum>
+getUnwindRuleRefReg(const dwarf::UnwindTable::const_iterator &UnwindRow,
+ DWARFRegNum Reg) {
+ auto MaybeLoc = UnwindRow->getRegisterLocations().getRegisterLocation(Reg);
+ assert(MaybeLoc &&
+ "The register should be tracked inside the register states");
+ auto Loc = *MaybeLoc;
+
+ switch (Loc.getLocation()) {
+ case dwarf::UnwindLocation::Location::Undefined:
+ case dwarf::UnwindLocation::Location::Constant:
+ case dwarf::UnwindLocation::Location::Unspecified:
+ case dwarf::UnwindLocation::Location::DWARFExpr:
+ // TODO here should look into expr and find the registers.
----------------
ilovepi wrote:
```suggestion
// TODO: here should look into expr and find the registers.
```
Most tooling works on `TODO:` or `FIXME:`. Please update the other instances.
https://github.com/llvm/llvm-project/pull/145633
More information about the llvm-commits
mailing list