InlineHelpers: add post-inlining no-GEP verifier

Add `PostInlineHelpersVerifyPass`, a `ModulePass` derived class that
aborts on any `getelementptr` instruction found in any Isolated
function. `inline-helpers` is the only pass in the post-isolate chain
that could import a GEP into an Isolated function by inlining a helper
body that contains one, so the verifier is invoked at the end of
`InlineHelpersPass::runOnModule`. In this way, we early catch this
invariant on the IR.
This commit is contained in:
Andrea Gussoni
2026-05-29 17:12:35 +02:00
committed by Alessandro Di Federico
parent 9c8808fd9e
commit 35b0da291a
4 changed files with 63 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@ revng_add_analyses_library_internal(
InlineHelpers.cpp
InvokeIsolatedFunctions.cpp
IsolateFunctions.cpp
PostInlineHelpersVerifyPass.cpp
PromoteCSVs.cpp
RemoveExceptionalCalls.cpp
StripDebugInfoFromHelpers.cpp
+8
View File
@@ -24,6 +24,8 @@
#include "revng/Support/OpaqueFunctionsPool.h"
#include "revng/Support/ResourceFinder.h"
#include "PostInlineHelpersVerifyPass.h"
using namespace llvm;
static Logger Log("inline-helpers");
@@ -272,5 +274,11 @@ bool InlineHelpersPass::runOnModule(llvm::Module &M) {
deleteOnlyBody(F);
}
// Verify that no `getelementptr` instruction was dragged into an Isolated
// function by the inlining above. The downstream pipeline relies on this
// invariant.
// TODO: convert this from a pass to a free-standing function
PostInlineHelpersVerifyPass{}.runOnModule(M);
return true;
}
@@ -0,0 +1,34 @@
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "revng/Model/FunctionTags.h"
#include "revng/Support/Assert.h"
#include "revng/Support/IRHelpers.h"
#include "PostInlineHelpersVerifyPass.h"
using namespace llvm;
bool PostInlineHelpersVerifyPass::runOnModule(Module &M) {
for (Function &F : M) {
if (not FunctionTags::Isolated.isTagOf(&F))
continue;
for (Instruction &I : instructions(F))
if (isa<GetElementPtrInst>(&I))
revng_abort(("post-inline-helpers-verify: "
"getelementptr in Isolated function "
+ F.getName().str())
.c_str());
}
return false;
}
char PostInlineHelpersVerifyPass::ID;
@@ -0,0 +1,20 @@
#pragma once
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "llvm/Pass.h"
/// Module pass that asserts no `getelementptr` instruction remains in any
/// `Isolated` function after the `inline-helpers` pass has run.
class PostInlineHelpersVerifyPass : public llvm::ModulePass {
public:
static char ID;
public:
PostInlineHelpersVerifyPass() : llvm::ModulePass(ID) {}
public:
bool runOnModule(llvm::Module &M) final;
};