- struct ExternalFunctionsPassedConstants : public Pass {
- virtual bool run(Module &M) {
- for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
- if (I->isExternal()) {
- bool PrintedFn = false;
- for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
- UI != E; ++UI)
- if (Instruction *User = dyn_cast<Instruction>(*UI)) {
- CallSite CS = CallSite::get(User);
- if (CS.getInstruction()) {
- for (CallSite::arg_iterator AI = CS.arg_begin(),
- E = CS.arg_end(); AI != E; ++AI)
- if (isa<Constant>(*AI)) {
- if (!PrintedFn) {
- std::cerr << "Function '" << I->getName() << "':\n";
- PrintedFn = true;
- }
- std::cerr << *User;
- break;
- }
- }
+ struct ExternalFunctionsPassedConstants : public ModulePass {
+ static char ID; // Pass ID, replacement for typeid
+ ExternalFunctionsPassedConstants() : ModulePass(ID) {}
+ bool runOnModule(Module &M) override {
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
+ if (!I->isDeclaration()) continue;
+
+ bool PrintedFn = false;
+ for (User *U : I->users()) {
+ Instruction *UI = dyn_cast<Instruction>(U);
+ if (!UI) continue;
+
+ CallSite CS(cast<Value>(UI));
+ if (!CS) continue;
+
+ for (CallSite::arg_iterator AI = CS.arg_begin(),
+ E = CS.arg_end(); AI != E; ++AI) {
+ if (!isa<Constant>(*AI)) continue;
+
+ if (!PrintedFn) {
+ errs() << "Function '" << I->getName() << "':\n";
+ PrintedFn = true;