[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:48 PDT 2025
================
@@ -0,0 +1,96 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/FunctionUnitStreamer.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCDwarf.h"
+#include "llvm/MC/MCInstrInfo.h"
+#include "llvm/MC/MCStreamer.h"
+#include <cstdio>
+#include <optional>
+
+using namespace llvm;
+
+std::pair<unsigned, unsigned> FunctionUnitStreamer::updateDirectivesRange() {
+ auto Frames = getDwarfFrameInfos();
+ unsigned CurrentCFIDirectiveIndex = 0;
+ if (hasUnfinishedDwarfFrameInfo()) {
+ assert(!FrameIndices.empty() && "FunctionUnitStreamer frame indices should "
+ "be synced with MCStreamer's");
+ assert(FrameIndices.back() < Frames.size());
+ CurrentCFIDirectiveIndex = Frames[FrameIndices.back()].Instructions.size();
+ }
+
+ assert(CurrentCFIDirectiveIndex >= LastDirectiveIndex);
+ std::pair<unsigned, unsigned> CFIDirectivesRange(LastDirectiveIndex,
+ CurrentCFIDirectiveIndex);
+ LastDirectiveIndex = CurrentCFIDirectiveIndex;
+ return CFIDirectivesRange;
+}
+
+void FunctionUnitStreamer::updateAnalyzer() {
+ if (FrameIndices.empty()) {
+ auto CFIDirectivesRange = updateDirectivesRange();
+ assert(CFIDirectivesRange.first == CFIDirectivesRange.second &&
+ "CFI directives should be in some frame");
+ return;
+ }
+
+ const auto *LastFrame = &getDwarfFrameInfos()[FrameIndices.back()];
----------------
ilovepi wrote:
Nit: generally prefer to use a real type over `auto`. `using` statements are a good option if you have some types that are hard to spell, plus that usually makes the code easier to read anyway. The style guide has more to say here: https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable
https://github.com/llvm/llvm-project/pull/145633
More information about the llvm-commits
mailing list