Skip to content

Instantly share code, notes, and snippets.

@maleadt
Created September 9, 2015 11:38
Show Gist options
  • Save maleadt/d555de9cf83c2186fe9b to your computer and use it in GitHub Desktop.
Save maleadt/d555de9cf83c2186fe9b to your computer and use it in GitHub Desktop.
// At this point, there shouldn't be any external references in the module
llvm::SmallVector<const llvm::GlobalValue*, 2> ExternalReferences;
for (const auto& GV : M->getGlobalList())
if (GV.isDeclaration())
ExternalReferences.push_back(&GV);
for (const auto& F : M->getFunctionList())
if (F.isDeclaration() && !F.isIntrinsic())
ExternalReferences.push_back(&F);
for (const auto* V: ExternalReferences) {
JL_PRINTF(JL_STDERR, "Warning: detected use of external value '%s'\n",
V->getName());
for (const auto& Use: V->uses()) {
if (auto* I = llvm::dyn_cast<Instruction>(Use.getUser())) {
if (llvm::MDNode *N = I->getMetadata("dbg")) {
llvm::DILocation Loc(N);
JL_PRINTF(JL_STDERR, " - at %s:%i\n",
Loc.getFilename().str().data(),
Loc.getLineNumber());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment