Index: llvm/lib/Transforms/IPO/OpenMPOpt.cpp =================================================================== --- llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -388,6 +388,30 @@ /// Helper to initialize all runtime function information for those defined in /// OpenMPKinds.def. void initializeRuntimeFunctions() { + // Helper to check the types in the declaration against the expected types. + auto CheckTypes = [&](RuntimeFunctionInfo &RFI) { + if (!RFI.Declaration) + return true; + + Function *F = RFI.Declaration; + if (F->getReturnType()->getTypeID() != RFI.ReturnType->getTypeID()) + return false; + + if (F->arg_size() != RFI.getNumArgs()) + return false; + + SmallVector::iterator RTFTyIt; + RTFTyIt = RFI.ArgumentTypes.begin(); + for (Argument &Arg : F->args()) { + if (Arg.getType()->getTypeID() != (*RTFTyIt)->getTypeID()) + return false; + + ++RTFTyIt; + } + + return true; + }; + // Helper to collect all uses of the decleration in the UsesMap. auto CollectUses = [&](RuntimeFunctionInfo &RFI) { unsigned NumUses = 0; @@ -422,6 +446,8 @@ RFI.ReturnType = _ReturnType; \ RFI.ArgumentTypes = SmallVector({__VA_ARGS__}); \ RFI.Declaration = M.getFunction(_Name); \ + bool TypesMatch = CheckTypes(RFI); \ + (void)TypesMatch; \ unsigned NumUses = CollectUses(RFI); \ (void)NumUses; \ LLVM_DEBUG({ \ @@ -434,7 +460,6 @@ } #include "llvm/Frontend/OpenMP/OMPKinds.def" - // TODO: We should validate the declaration agains the types we expect. // TODO: We should attach the attributes defined in OMPKinds.def. }