Преглед на файлове

Integration from OS repo (#2541)

Includes OS PR #2130654: C++17 readiness: Enable /std:c++17 globally: Fixes for C2039 Errors
Helena Kotas преди 5 години
родител
ревизия
4391420da4

+ 7 - 4
include/llvm/ADT/STLExtras.h

@@ -35,7 +35,9 @@ namespace llvm {
 //===----------------------------------------------------------------------===//
 
 template<class Ty>
-struct identity : public std::unary_function<Ty, Ty> {
+struct identity {
+  using argument_type = Ty;
+
   Ty &operator()(Ty &self) const {
     return self;
   }
@@ -45,14 +47,14 @@ struct identity : public std::unary_function<Ty, Ty> {
 };
 
 template<class Ty>
-struct less_ptr : public std::binary_function<Ty, Ty, bool> {
+struct less_ptr {
   bool operator()(const Ty* left, const Ty* right) const {
     return *left < *right;
   }
 };
 
 template<class Ty>
-struct greater_ptr : public std::binary_function<Ty, Ty, bool> {
+struct greater_ptr {
   bool operator()(const Ty* left, const Ty* right) const {
     return *right < *left;
   }
@@ -118,7 +120,8 @@ public:
           iterator_category;
   typedef typename std::iterator_traits<RootIt>::difference_type
           difference_type;
-  typedef typename UnaryFunc::result_type value_type;
+  typedef decltype(std::declval<UnaryFunc>()(*std::declval<RootIt>()))
+          value_type;
 
   typedef void pointer;
   //typedef typename UnaryFunc::result_type *pointer;

+ 35 - 34
include/llvm/Analysis/CallGraph.h

@@ -75,7 +75,7 @@ class CallGraphNode;
 class CallGraph {
   Module &M;
 
-  typedef std::map<const Function *, CallGraphNode *> FunctionMapTy;
+  typedef std::map<const Function *, std::unique_ptr<CallGraphNode>> FunctionMapTy;
 
   /// \brief A map from \c Function* to \c CallGraphNode*.
   FunctionMapTy FunctionMap;
@@ -90,7 +90,7 @@ class CallGraph {
 
   /// \brief This node has edges to it from all functions making indirect calls
   /// or calling an external function.
-  CallGraphNode *CallsExternalNode;
+  std::unique_ptr<CallGraphNode> CallsExternalNode;
 
   /// \brief Replace the function represented by this node by another.
   ///
@@ -105,7 +105,8 @@ class CallGraph {
 
   void reset(); // HLSL Change
 public:
-  CallGraph(Module &M);
+  explicit CallGraph(Module &M);
+  CallGraph(CallGraph &&Arg);
   ~CallGraph();
 
   void print(raw_ostream &OS) const;
@@ -126,21 +127,21 @@ public:
   inline const CallGraphNode *operator[](const Function *F) const {
     const_iterator I = FunctionMap.find(F);
     assert(I != FunctionMap.end() && "Function not in callgraph!");
-    return I->second;
+    return I->second.get();
   }
 
   /// \brief Returns the call graph node for the provided function.
   inline CallGraphNode *operator[](const Function *F) {
     const_iterator I = FunctionMap.find(F);
     assert(I != FunctionMap.end() && "Function not in callgraph!");
-    return I->second;
+    return I->second.get();
   }
 
   /// \brief Returns the \c CallGraphNode which is used to represent
   /// undetermined calls into the callgraph.
   CallGraphNode *getExternalCallingNode() const { return ExternalCallingNode; }
 
-  CallGraphNode *getCallsExternalNode() const { return CallsExternalNode; }
+  CallGraphNode *getCallsExternalNode() const { return CallsExternalNode.get(); }
 
   //===---------------------------------------------------------------------
   // Functions to keep a call graph up to date with a function that has been
@@ -401,43 +402,39 @@ template <> struct GraphTraits<CallGraphNode *> {
   typedef CallGraphNode NodeType;
 
   typedef CallGraphNode::CallRecord CGNPairTy;
-  typedef std::pointer_to_unary_function<CGNPairTy, CallGraphNode *>
-  CGNDerefFun;
 
   static NodeType *getEntryNode(CallGraphNode *CGN) { return CGN; }
 
-  typedef mapped_iterator<NodeType::iterator, CGNDerefFun> ChildIteratorType;
+  static CallGraphNode *CGNGetValue(CGNPairTy P) { return P.second; }
+  typedef mapped_iterator<NodeType::iterator, decltype(&CGNGetValue)> ChildIteratorType;
 
   static inline ChildIteratorType child_begin(NodeType *N) {
-    return map_iterator(N->begin(), CGNDerefFun(CGNDeref));
+    return ChildIteratorType(N->begin(), &CGNGetValue);
   }
   static inline ChildIteratorType child_end(NodeType *N) {
-    return map_iterator(N->end(), CGNDerefFun(CGNDeref));
+    return ChildIteratorType(N->end(), &CGNGetValue);
   }
-
-  static CallGraphNode *CGNDeref(CGNPairTy P) { return P.second; }
 };
 
 template <> struct GraphTraits<const CallGraphNode *> {
   typedef const CallGraphNode NodeType;
 
   typedef CallGraphNode::CallRecord CGNPairTy;
-  typedef std::pointer_to_unary_function<CGNPairTy, const CallGraphNode *>
-      CGNDerefFun;
 
   static NodeType *getEntryNode(const CallGraphNode *CGN) { return CGN; }
 
-  typedef mapped_iterator<NodeType::const_iterator, CGNDerefFun>
+  static const CallGraphNode *CGNGetValue(CGNPairTy P) { return P.second; }
+
+  typedef mapped_iterator<NodeType::const_iterator, decltype(&CGNGetValue)>
       ChildIteratorType;
 
   static inline ChildIteratorType child_begin(NodeType *N) {
-    return map_iterator(N->begin(), CGNDerefFun(CGNDeref));
+    return ChildIteratorType(N->begin(), &CGNGetValue);
   }
   static inline ChildIteratorType child_end(NodeType *N) {
-    return map_iterator(N->end(), CGNDerefFun(CGNDeref));
+    return ChildIteratorType(N->end(), &CGNGetValue);
   }
 
-  static const CallGraphNode *CGNDeref(CGNPairTy P) { return P.second; }
 };
 
 template <>
@@ -445,19 +442,21 @@ struct GraphTraits<CallGraph *> : public GraphTraits<CallGraphNode *> {
   static NodeType *getEntryNode(CallGraph *CGN) {
     return CGN->getExternalCallingNode(); // Start at the external node!
   }
-  typedef std::pair<const Function *, CallGraphNode *> PairTy;
-  typedef std::pointer_to_unary_function<PairTy, CallGraphNode &> DerefFun;
+  typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
+      PairTy;
+
+  static CallGraphNode *CGGetValuePtr(const PairTy &P) { 
+    return P.second.get();
+  }
 
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
-  typedef mapped_iterator<CallGraph::iterator, DerefFun> nodes_iterator;
+  typedef mapped_iterator<CallGraph::iterator, decltype(&CGGetValuePtr)> nodes_iterator;
   static nodes_iterator nodes_begin(CallGraph *CG) {
-    return map_iterator(CG->begin(), DerefFun(CGdereference));
+    return nodes_iterator(CG->begin(), &CGGetValuePtr);
   }
   static nodes_iterator nodes_end(CallGraph *CG) {
-    return map_iterator(CG->end(), DerefFun(CGdereference));
+    return nodes_iterator(CG->end(), &CGGetValuePtr);
   }
-
-  static CallGraphNode &CGdereference(PairTy P) { return *P.second; }
 };
 
 template <>
@@ -466,20 +465,22 @@ struct GraphTraits<const CallGraph *> : public GraphTraits<
   static NodeType *getEntryNode(const CallGraph *CGN) {
     return CGN->getExternalCallingNode(); // Start at the external node!
   }
-  typedef std::pair<const Function *, const CallGraphNode *> PairTy;
-  typedef std::pointer_to_unary_function<PairTy, const CallGraphNode &>
-      DerefFun;
+  typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
+       PairTy;
+
+  static const CallGraphNode *CGGetValuePtr(const PairTy &P) {
+    return P.second.get();
+  }
 
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
-  typedef mapped_iterator<CallGraph::const_iterator, DerefFun> nodes_iterator;
+  typedef mapped_iterator<CallGraph::const_iterator, decltype(&CGGetValuePtr)>
+    nodes_iterator;
   static nodes_iterator nodes_begin(const CallGraph *CG) {
-    return map_iterator(CG->begin(), DerefFun(CGdereference));
+    return nodes_iterator(CG->begin(), &CGGetValuePtr);
   }
   static nodes_iterator nodes_end(const CallGraph *CG) {
-    return map_iterator(CG->end(), DerefFun(CGdereference));
+    return nodes_iterator(CG->end(), &CGGetValuePtr);
   }
-
-  static const CallGraphNode &CGdereference(PairTy P) { return *P.second; }
 };
 
 } // End llvm namespace

+ 1 - 2
include/llvm/CodeGen/MachineBasicBlock.h

@@ -714,8 +714,7 @@ private:
 raw_ostream& operator<<(raw_ostream &OS, const MachineBasicBlock &MBB);
 
 // This is useful when building IndexedMaps keyed on basic block pointers.
-struct MBB2NumberFunctor :
-  public std::unary_function<const MachineBasicBlock*, unsigned> {
+struct MBB2NumberFunctor {
   unsigned operator()(const MachineBasicBlock *MBB) const {
     return MBB->getNumber();
   }

+ 1 - 1
include/llvm/Target/TargetRegisterInfo.h

@@ -930,7 +930,7 @@ public:
 };
 
 // This is useful when building IndexedMaps keyed on virtual registers
-struct VirtReg2IndexFunctor : public std::unary_function<unsigned, unsigned> {
+struct VirtReg2IndexFunctor {
   unsigned operator()(unsigned Reg) const {
     return TargetRegisterInfo::virtReg2Index(Reg);
   }

+ 37 - 72
lib/Analysis/IPA/CallGraph.cpp

@@ -22,90 +22,62 @@ using namespace llvm;
 //
 
 CallGraph::CallGraph(Module &M)
-    : M(M), Root(nullptr), ExternalCallingNode(nullptr), // HLSL Change - no allocation here
-      CallsExternalNode(nullptr) {
-  try { // HLSL change - guard and reset
-    ExternalCallingNode = getOrInsertFunction(nullptr);
-    CallsExternalNode = new CallGraphNode(nullptr);
-    // Add every function to the call graph.
-    for (Function &F : M)
-      addToCallGraph(&F);
-
-    // If we didn't find a main function, use the external call graph node
-    if (!Root)
-      Root = ExternalCallingNode;
-  } catch (...) {
-    reset();
-    throw;
-  }
+    : M(M), ExternalCallingNode(getOrInsertFunction(nullptr)),
+      CallsExternalNode(llvm::make_unique<CallGraphNode>(nullptr)) {
+  // Add every function to the call graph.
+  for (Function &F : M)
+    addToCallGraph(&F);
+}
+
+
+
+CallGraph::CallGraph(CallGraph &&Arg)
+    : M(Arg.M), FunctionMap(std::move(Arg.FunctionMap)),
+      ExternalCallingNode(Arg.ExternalCallingNode),
+      CallsExternalNode(std::move(Arg.CallsExternalNode)) {
+  Arg.FunctionMap.clear();
+  Arg.ExternalCallingNode = nullptr;
 }
 
-// HLSL Change Starts
-CallGraph::~CallGraph() { reset(); }
-void CallGraph::reset() {
-  // This function cleans up the CallGraph, called from the destructor or
-  // an under-construction instance.
-// HLSL Change Ends
+
+
+CallGraph::~CallGraph() {
   // CallsExternalNode is not in the function map, delete it explicitly.
-  if (CallsExternalNode) // HLSL Change - guard
+  if (CallsExternalNode)
     CallsExternalNode->allReferencesDropped();
-  delete CallsExternalNode;
-  CallsExternalNode = nullptr;
 
 // Reset all node's use counts to zero before deleting them to prevent an
 // assertion from firing.
 #ifndef NDEBUG
   for (auto &I : FunctionMap)
-    if (I.second) // HLSL Change - this guard needed when slot is alloc'ed but not populated
-      I.second->allReferencesDropped();
+    I.second->allReferencesDropped();
 #endif
-  for (auto &I : FunctionMap)
-    delete I.second;
-  FunctionMap.clear();
 }
 
+
 void CallGraph::addToCallGraph(Function *F) {
   CallGraphNode *Node = getOrInsertFunction(F);
 
-  // If this function has external linkage, anything could call it.
-  if (!F->hasLocalLinkage()) {
-    ExternalCallingNode->addCalledFunction(CallSite(), Node);
-    // HLSL Change Begins.
-    if (M.HasHLModule()) {
-      if (M.GetHLModule().GetEntryFunction() == F)
-        Root = Node;
-    } else // Make sure Root not overwrite by main.
-    // HLSL Change Ends.
-    // Found the entry point?
-    if (F->getName() == "main") {
-      if (Root) // Found multiple external mains?  Don't pick one.
-        Root = ExternalCallingNode;
-      else
-        Root = Node; // Found a main, keep track of it!
-    }
-  }
-
-  // If this function has its address taken, anything could call it.
-  if (F->hasAddressTaken())
+  // If this function has external linkage or has its address taken, anything
+  // could call it.
+  if (!F->hasLocalLinkage() || F->hasAddressTaken())
     ExternalCallingNode->addCalledFunction(CallSite(), Node);
 
   // If this function is not defined in this translation unit, it could call
   // anything.
   if (F->isDeclaration() && !F->isIntrinsic())
-    Node->addCalledFunction(CallSite(), CallsExternalNode);
+    Node->addCalledFunction(CallSite(), CallsExternalNode.get());
 
   // Look for calls by this function.
-  for (Function::iterator BB = F->begin(), BBE = F->end(); BB != BBE; ++BB)
-    for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE;
-         ++II) {
-      CallSite CS(cast<Value>(II));
-      if (CS) {
+  for (BasicBlock &BB : *F)
+    for (Instruction &I : BB) {
+      if (auto CS = CallSite(&I)) {
         const Function *Callee = CS.getCalledFunction();
         if (!Callee || !Intrinsic::isLeaf(Callee->getIntrinsicID()))
           // Indirect calls of intrinsics are not allowed so no need to check.
           // We can be more precise here by using TargetArg returned by
           // Intrinsic::isLeaf.
-          Node->addCalledFunction(CS, CallsExternalNode);
+          Node->addCalledFunction(CS, CallsExternalNode.get());
         else if (!Callee->isIntrinsic())
           Node->addCalledFunction(CS, getOrInsertFunction(Callee));
       }
@@ -113,24 +85,17 @@ void CallGraph::addToCallGraph(Function *F) {
 }
 
 void CallGraph::print(raw_ostream &OS) const {
-  OS << "CallGraph Root is: ";
-  if (Function *F = Root->getFunction())
-    OS << F->getName() << "\n";
-  else {
-    OS << "<<null function: 0x" << Root << ">>\n";
-  }
-
   // Print in a deterministic order by sorting CallGraphNodes by name.  We do
   // this here to avoid slowing down the non-printing fast path.
 
   SmallVector<CallGraphNode *, 16> Nodes;
   Nodes.reserve(FunctionMap.size());
 
-  for (auto I = begin(), E = end(); I != E; ++I)
-    Nodes.push_back(I->second);
+  for (const auto &I : *this)
+    Nodes.push_back(I.second.get());
 
   std::sort(Nodes.begin(), Nodes.end(),
-            [](CallGraphNode *LHS, CallGraphNode *RHS) {
+             [](CallGraphNode *LHS, CallGraphNode *RHS) {
     if (Function *LF = LHS->getFunction())
       if (Function *RF = RHS->getFunction())
         return LF->getName() < RF->getName();
@@ -156,7 +121,6 @@ Function *CallGraph::removeFunctionFromModule(CallGraphNode *CGN) {
   assert(CGN->empty() && "Cannot remove function from call "
          "graph if it references other functions!");
   Function *F = CGN->getFunction(); // Get the function for the call graph node
-  delete CGN;                       // Delete the call graph node for this func
   FunctionMap.erase(F);             // Remove the call graph node from the map
 
   M.CallRemoveGlobalHook(F); // HLSL Change
@@ -176,7 +140,7 @@ void CallGraph::spliceFunction(const Function *From, const Function *To) {
          "Pointing CallGraphNode at a function that already exists");
   FunctionMapTy::iterator I = FunctionMap.find(From);
   I->second->F = const_cast<Function*>(To);
-  FunctionMap[To] = I->second;
+  FunctionMap[To] = std::move(I->second);
   FunctionMap.erase(I);
 }
 
@@ -184,12 +148,13 @@ void CallGraph::spliceFunction(const Function *From, const Function *To) {
 // it will insert a new CallGraphNode for the specified function if one does
 // not already exist.
 CallGraphNode *CallGraph::getOrInsertFunction(const Function *F) {
-  CallGraphNode *&CGN = FunctionMap[F];
+  auto &CGN = FunctionMap[F];
   if (CGN)
-    return CGN;
+    return CGN.get();
 
   assert((!F || F->getParent() == &M) && "Function not in current module!");
-  return CGN = new CallGraphNode(const_cast<Function*>(F));
+  CGN = llvm::make_unique<CallGraphNode>(const_cast<Function *>(F));
+  return CGN.get();
 }
 
 //===----------------------------------------------------------------------===//

+ 49 - 49
lib/Support/MSFileSystemBasic.cpp

@@ -239,7 +239,7 @@ MSFileSystemForIface::MSFileSystemForIface(IDxcSystemAccess* systemAccess)
 }
 
 _Use_decl_annotations_
-HRESULT MSFileSystemForIface::AddMappingHandle(IUnknown* mapping, HANDLE* pResult)
+HRESULT MSFileSystemForIface::AddMappingHandle(IUnknown* mapping, HANDLE* pResult) throw()
 {
   DXASSERT_NOMSG(mapping != nullptr);
   DXASSERT_NOMSG(pResult != nullptr);
@@ -256,7 +256,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-HRESULT MSFileSystemForIface::AddMappingView(ID3D10Blob* blob)
+HRESULT MSFileSystemForIface::AddMappingView(ID3D10Blob* blob) throw()
 {
   DXASSERT_NOMSG(blob != nullptr);
   LPVOID address = blob->GetBufferPointer();
@@ -273,7 +273,7 @@ HRESULT MSFileSystemForIface::AddMappingView(ID3D10Blob* blob)
 }
 
 _Use_decl_annotations_
-HRESULT MSFileSystemForIface::AddFindHandle(IEnumSTATSTG* enumStatStg, HANDLE* pResult)
+HRESULT MSFileSystemForIface::AddFindHandle(IEnumSTATSTG* enumStatStg, HANDLE* pResult) throw()
 {
   DXASSERT_NOMSG(enumStatStg != nullptr);
   DXASSERT_NOMSG(pResult != nullptr);
@@ -290,7 +290,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-HRESULT MSFileSystemForIface::AddFileHandle(IUnknown* storage, IStream* stream, HANDLE* pResult)
+HRESULT MSFileSystemForIface::AddFileHandle(IUnknown* storage, IStream* stream, HANDLE* pResult) throw()
 {
   DXASSERT_NOMSG(storage != nullptr);
   DXASSERT_NOMSG(pResult != nullptr);
@@ -306,7 +306,7 @@ Cleanup:
   return hr;
 }
 
-void MSFileSystemForIface::CloseInternalHandle(HANDLE handle)
+void MSFileSystemForIface::CloseInternalHandle(HANDLE handle) throw()
 {
   DXASSERT_NOMSG(handle != nullptr);
   DXASSERT_NOMSG(handle != INVALID_HANDLE_VALUE);
@@ -323,7 +323,7 @@ void MSFileSystemForIface::CloseInternalHandle(HANDLE handle)
 }
 
 _Use_decl_annotations_
-void MSFileSystemForIface::RemoveMappingView(LPCVOID address)
+void MSFileSystemForIface::RemoveMappingView(LPCVOID address) throw()
 {
   TViewMap::iterator i = m_mappingViews.find(address);
   DXASSERT(i != m_mappingViews.end(), "otherwise pointer to view isn't in map");
@@ -333,7 +333,7 @@ void MSFileSystemForIface::RemoveMappingView(LPCVOID address)
 }
 
 _Use_decl_annotations_
-void MSFileSystemForIface::GetFindHandle(HANDLE findHandle, IEnumSTATSTG** enumStatStg)
+void MSFileSystemForIface::GetFindHandle(HANDLE findHandle, IEnumSTATSTG** enumStatStg) throw()
 {
   DXASSERT_NOMSG(findHandle != nullptr);
   DXASSERT_NOMSG(enumStatStg != nullptr);
@@ -347,7 +347,7 @@ void MSFileSystemForIface::GetFindHandle(HANDLE findHandle, IEnumSTATSTG** enumS
   (*enumStatStg)->AddRef();
 }
 
-int MSFileSystemForIface::GetHandleFD(HANDLE fileHandle)
+int MSFileSystemForIface::GetHandleFD(HANDLE fileHandle) throw()
 {
   DXASSERT_NOMSG(fileHandle != nullptr);
 
@@ -358,7 +358,7 @@ int MSFileSystemForIface::GetHandleFD(HANDLE fileHandle)
 }
 
 _Use_decl_annotations_
-void MSFileSystemForIface::GetHandleMapping(HANDLE mapping, _Outptr_ IUnknown** pResult)
+void MSFileSystemForIface::GetHandleMapping(HANDLE mapping, _Outptr_ IUnknown** pResult) throw()
 {
   DXASSERT_NOMSG(mapping != nullptr);
   DXASSERT_NOMSG(pResult != nullptr);
@@ -373,7 +373,7 @@ void MSFileSystemForIface::GetHandleMapping(HANDLE mapping, _Outptr_ IUnknown**
 }
 
 _Use_decl_annotations_
-void MSFileSystemForIface::GetHandleStorage(HANDLE fileHandle, _Outptr_ IUnknown** pResult)
+void MSFileSystemForIface::GetHandleStorage(HANDLE fileHandle, _Outptr_ IUnknown** pResult) throw()
 {
   DXASSERT_NOMSG(fileHandle != nullptr);
   DXASSERT_NOMSG(pResult != nullptr);
@@ -388,7 +388,7 @@ void MSFileSystemForIface::GetHandleStorage(HANDLE fileHandle, _Outptr_ IUnknown
 }
 
 _Use_decl_annotations_
-void MSFileSystemForIface::GetHandleStream(HANDLE fileHandle, _Outptr_ IStream** pResult)
+void MSFileSystemForIface::GetHandleStream(HANDLE fileHandle, _Outptr_ IStream** pResult) throw()
 {
   DXASSERT_NOMSG(fileHandle != nullptr);
   DXASSERT_NOMSG(pResult != nullptr);
@@ -404,7 +404,7 @@ void MSFileSystemForIface::GetHandleStream(HANDLE fileHandle, _Outptr_ IStream**
 
 
 _Use_decl_annotations_
-HANDLE MSFileSystemForIface::FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData)
+HANDLE MSFileSystemForIface::FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IEnumSTATSTG> enumStatStg;
@@ -441,7 +441,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-BOOL MSFileSystemForIface::FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData)
+BOOL MSFileSystemForIface::FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IEnumSTATSTG> enumStatStg;
@@ -475,13 +475,13 @@ Cleanup:
   return TRUE;
 }
 
-void MSFileSystemForIface::FindClose(HANDLE findHandle)
+void MSFileSystemForIface::FindClose(HANDLE findHandle) throw()
 {
   CloseInternalHandle(findHandle);
 }
 
 _Use_decl_annotations_
-HANDLE MSFileSystemForIface::CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes)
+HANDLE MSFileSystemForIface::CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IUnknown> storage;
@@ -503,7 +503,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-BOOL MSFileSystemForIface::SetFileTime(HANDLE hFile, _In_opt_ const FILETIME *lpCreationTime, _In_opt_ const FILETIME *lpLastAccessTime, _In_opt_ const FILETIME *lpLastWriteTime)
+BOOL MSFileSystemForIface::SetFileTime(HANDLE hFile, _In_opt_ const FILETIME *lpCreationTime, _In_opt_ const FILETIME *lpLastAccessTime, _In_opt_ const FILETIME *lpLastWriteTime) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IUnknown> storage;
@@ -522,7 +522,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-BOOL MSFileSystemForIface::GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
+BOOL MSFileSystemForIface::GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IUnknown> storage;
@@ -541,7 +541,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-DWORD MSFileSystemForIface::GetFileType(HANDLE hFile)
+DWORD MSFileSystemForIface::GetFileType(HANDLE hFile) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IUnknown> storage;
@@ -565,21 +565,21 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-BOOL MSFileSystemForIface::CreateHardLinkW(LPCWSTR lpFileName, LPCWSTR lpExistingFileName)
+BOOL MSFileSystemForIface::CreateHardLinkW(LPCWSTR lpFileName, LPCWSTR lpExistingFileName) throw()
 {
   SetLastError(ERROR_FUNCTION_NOT_CALLED);
   return FALSE;
 }
 
 _Use_decl_annotations_
-BOOL MSFileSystemForIface::MoveFileExW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, DWORD dwFlags)
+BOOL MSFileSystemForIface::MoveFileExW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, DWORD dwFlags) throw()
 {
   SetLastError(ERROR_FUNCTION_NOT_CALLED);
   return FALSE;
 }
 
 _Use_decl_annotations_
-DWORD MSFileSystemForIface::GetFileAttributesW(LPCWSTR lpFileName)
+DWORD MSFileSystemForIface::GetFileAttributesW(LPCWSTR lpFileName) throw()
 {
   HRESULT hr = S_OK;
   DWORD attributes;
@@ -597,35 +597,35 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-BOOL MSFileSystemForIface::CloseHandle(HANDLE hObject)
+BOOL MSFileSystemForIface::CloseHandle(HANDLE hObject) throw()
 {
   this->CloseInternalHandle(hObject);
   return TRUE;
 }
 
 _Use_decl_annotations_
-BOOL MSFileSystemForIface::DeleteFileW(LPCWSTR lpFileName)
+BOOL MSFileSystemForIface::DeleteFileW(LPCWSTR lpFileName) throw()
 {
   SetLastError(ERROR_FUNCTION_NOT_CALLED);
   return FALSE;
 }
 
 _Use_decl_annotations_
-BOOL MSFileSystemForIface::RemoveDirectoryW(LPCWSTR lpFileName)
+BOOL MSFileSystemForIface::RemoveDirectoryW(LPCWSTR lpFileName) throw()
 {
   SetLastError(ERROR_FUNCTION_NOT_CALLED);
   return FALSE;
 }
 
 _Use_decl_annotations_
-BOOL MSFileSystemForIface::CreateDirectoryW(LPCWSTR lpPathName)
+BOOL MSFileSystemForIface::CreateDirectoryW(LPCWSTR lpPathName) throw()
 {
   SetLastError(ERROR_FUNCTION_NOT_CALLED);
   return FALSE;
 }
 
 _Use_decl_annotations_
-DWORD MSFileSystemForIface::GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer)
+DWORD MSFileSystemForIface::GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer) throw()
 {
   DWORD written = 0;
   HRESULT hr = S_OK;
@@ -643,7 +643,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-DWORD MSFileSystemForIface::GetMainModuleFileNameW(LPWSTR lpFilename, DWORD nSize)
+DWORD MSFileSystemForIface::GetMainModuleFileNameW(LPWSTR lpFilename, DWORD nSize) throw()
 {
   DWORD written = 0;
   HRESULT hr = S_OK;
@@ -661,7 +661,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-DWORD MSFileSystemForIface::GetTempPathW(DWORD nBufferLength, LPWSTR lpBuffer)
+DWORD MSFileSystemForIface::GetTempPathW(DWORD nBufferLength, LPWSTR lpBuffer) throw()
 {
   DWORD written = 0;
   HRESULT hr = S_OK;
@@ -679,19 +679,19 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-BOOLEAN MSFileSystemForIface::CreateSymbolicLinkW(LPCWSTR lpSymlinkFileName, LPCWSTR lpTargetFileName, DWORD dwFlags)
+BOOLEAN MSFileSystemForIface::CreateSymbolicLinkW(LPCWSTR lpSymlinkFileName, LPCWSTR lpTargetFileName, DWORD dwFlags) throw()
 {
   SetLastError(ERROR_FUNCTION_NOT_CALLED);
   return FALSE;
 }
 
-bool MSFileSystemForIface::SupportsCreateSymbolicLink()
+bool MSFileSystemForIface::SupportsCreateSymbolicLink() throw()
 {
   return false;
 }
 
 _Use_decl_annotations_
-BOOL MSFileSystemForIface::ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, _Out_opt_ LPDWORD lpNumberOfBytesRead)
+BOOL MSFileSystemForIface::ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, _Out_opt_ LPDWORD lpNumberOfBytesRead) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IStream> stream;
@@ -714,7 +714,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-HANDLE MSFileSystemForIface::CreateFileMappingW(HANDLE hFile, DWORD flProtect, DWORD dwMaximumSizeHigh, DWORD dwMaximumSizeLow)
+HANDLE MSFileSystemForIface::CreateFileMappingW(HANDLE hFile, DWORD flProtect, DWORD dwMaximumSizeHigh, DWORD dwMaximumSizeLow) throw()
 {
   HRESULT hr = S_OK;
   HANDLE result = INVALID_HANDLE_VALUE;
@@ -736,7 +736,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-LPVOID MSFileSystemForIface::MapViewOfFile(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap)
+LPVOID MSFileSystemForIface::MapViewOfFile(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IUnknown> mapping;
@@ -763,12 +763,12 @@ BOOL MSFileSystemForIface::UnmapViewOfFile(LPCVOID lpBaseAddress) throw()
   return TRUE;
 }
 
-bool MSFileSystemForIface::FileDescriptorIsDisplayed(int fd)
+bool MSFileSystemForIface::FileDescriptorIsDisplayed(int fd) throw()
 {
   return false;
 }
 
-unsigned MSFileSystemForIface::GetColumnCount(DWORD nStdHandle)
+unsigned MSFileSystemForIface::GetColumnCount(DWORD nStdHandle) throw()
 {
   return 0;
 }
@@ -778,16 +778,16 @@ unsigned MSFileSystemForIface::GetConsoleOutputTextAttributes() throw()
   return 0;
 }
 
-void MSFileSystemForIface::SetConsoleOutputTextAttributes(unsigned attributes)
+void MSFileSystemForIface::SetConsoleOutputTextAttributes(unsigned attributes) throw()
 {
   return;
 }
 
-void MSFileSystemForIface::ResetConsoleOutputTextAttributes()
+void MSFileSystemForIface::ResetConsoleOutputTextAttributes() throw()
 {
 }
 
-int MSFileSystemForIface::open_osfhandle(intptr_t osfhandle, int flags)
+int MSFileSystemForIface::open_osfhandle(intptr_t osfhandle, int flags) throw()
 {
   return GetHandleFD((HANDLE)osfhandle);
 }
@@ -824,7 +824,7 @@ Cleanup:
   return hr;
 }
 
-HANDLE MSFileSystemForIface::GetHandleForFD(int fd)
+HANDLE MSFileSystemForIface::GetHandleForFD(int fd) throw()
 {
   MSFileSystemHandle* ptr;
   switch (fd)
@@ -837,7 +837,7 @@ HANDLE MSFileSystemForIface::GetHandleForFD(int fd)
   return ptr->GetHandle();
 }
 
-intptr_t MSFileSystemForIface::get_osfhandle(int fd) {
+intptr_t MSFileSystemForIface::get_osfhandle(int fd) throw() {
   if (FAILED(EnsureFDAvailable(fd))) {
     errno = EBADF;
     return -1;
@@ -846,14 +846,14 @@ intptr_t MSFileSystemForIface::get_osfhandle(int fd) {
   return (intptr_t)GetHandleForFD(fd);
 }
 
-int MSFileSystemForIface::close(int fd)
+int MSFileSystemForIface::close(int fd) throw()
 {
   HANDLE h = GetHandleForFD(fd);
   this->CloseInternalHandle(h);
   return 0;
 }
 
-long MSFileSystemForIface::lseek(int fd, long offset, int origin)
+long MSFileSystemForIface::lseek(int fd, long offset, int origin) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IStream> stream;
@@ -886,19 +886,19 @@ Cleanup:
   return uli.LowPart;
 }
 
-int MSFileSystemForIface::setmode(int fd, int mode)
+int MSFileSystemForIface::setmode(int fd, int mode) throw()
 {
   return 0;
 }
 
 _Use_decl_annotations_
-errno_t MSFileSystemForIface::resize_file(LPCWSTR path, uint64_t size)
+errno_t MSFileSystemForIface::resize_file(LPCWSTR path, uint64_t size) throw()
 {
   return EBADF;
 }
 
 _Use_decl_annotations_
-int MSFileSystemForIface::Read(int fd, void* buffer, unsigned int count)
+int MSFileSystemForIface::Read(int fd, void* buffer, unsigned int count) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IStream> stream;
@@ -923,7 +923,7 @@ Cleanup:
 }
 
 _Use_decl_annotations_
-int MSFileSystemForIface::Write(int fd, const void* buffer, unsigned int count)
+int MSFileSystemForIface::Write(int fd, const void* buffer, unsigned int count) throw()
 {
   HRESULT hr = S_OK;
   CComPtr<IStream> stream;
@@ -1140,7 +1140,7 @@ MSFileSystemBlocked::MSFileSystemBlocked()
 }
 
 _Use_decl_annotations_
-DWORD MSFileSystemBlocked::GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer)
+DWORD MSFileSystemBlocked::GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer) throw()
 {
   if (nBufferLength > 1)
   {
@@ -1151,14 +1151,14 @@ DWORD MSFileSystemBlocked::GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBu
 }
 
 _Use_decl_annotations_
-DWORD MSFileSystemBlocked::GetMainModuleFileNameW(LPWSTR lpFilename, DWORD nSize)
+DWORD MSFileSystemBlocked::GetMainModuleFileNameW(LPWSTR lpFilename, DWORD nSize) throw()
 {
   SetLastError(NO_ERROR);
   return 0;
 }
 
 _Use_decl_annotations_
-DWORD MSFileSystemBlocked::GetTempPathW(DWORD nBufferLength, LPWSTR lpBuffer)
+DWORD MSFileSystemBlocked::GetTempPathW(DWORD nBufferLength, LPWSTR lpBuffer) throw()
 {
   if (nBufferLength > 1)
   {

+ 4 - 4
lib/Support/Windows/MSFileSystem.inc.cpp

@@ -148,7 +148,7 @@ error_code SetCurrentThreadFileSystem(MSFileSystemRef value) throw()
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Support for CRT-like file stream functions.
 
-int msf_read(int fd, void* buffer, unsigned int count)
+int msf_read(int fd, void* buffer, unsigned int count) throw()
 {
   MSFileSystemRef fsr = GetCurrentThreadFileSystem();
   if (fsr == nullptr) {
@@ -158,7 +158,7 @@ int msf_read(int fd, void* buffer, unsigned int count)
   return fsr->Read(fd, buffer, count);
 }
 
-int msf_write(int fd, const void* buffer, unsigned int count)
+int msf_write(int fd, const void* buffer, unsigned int count) throw()
 {
   MSFileSystemRef fsr = GetCurrentThreadFileSystem();
   if (fsr == nullptr) {
@@ -168,7 +168,7 @@ int msf_write(int fd, const void* buffer, unsigned int count)
   return fsr->Write(fd, buffer, count);
 }
 
-int msf_close(int fd)
+int msf_close(int fd) throw()
 {
   MSFileSystemRef fsr = GetCurrentThreadFileSystem();
   if (fsr == nullptr) {
@@ -188,7 +188,7 @@ long msf_lseek(int fd, long offset, int origin)
   return fsr->lseek(fd, offset, origin);
 }
 
-int msf_setmode(int fd, int mode)
+int msf_setmode(int fd, int mode) throw()
 {
   MSFileSystemRef fsr = GetCurrentThreadFileSystem();
   if (fsr == nullptr) {

+ 2 - 2
lib/Transforms/IPO/Inliner.cpp

@@ -668,8 +668,8 @@ bool Inliner::removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly) {
 
   // Scan for all of the functions, looking for ones that should now be removed
   // from the program.  Insert the dead ones in the FunctionsToRemove set.
-  for (auto I : CG) {
-    CallGraphNode *CGN = I.second;
+  for (const auto &I : CG) {
+    CallGraphNode *CGN = I.second.get();
     Function *F = CGN->getFunction();
     if (!F || F->isDeclaration())
       continue;

+ 1 - 1
lib/Transforms/Scalar/DxilLoopUnroll.cpp

@@ -619,7 +619,7 @@ static bool BreakUpArrayAllocas(bool AllowOOBIndex, IteratorT ItBegin, IteratorT
     } 
 
     if (!ElementType->isArrayTy()) {
-      std::remove(ScalarAllocas.begin(), ScalarAllocas.end(), nullptr);
+      ScalarAllocas.erase(std::remove(ScalarAllocas.begin(), ScalarAllocas.end(), nullptr), ScalarAllocas.end());
       PromoteMemToReg(ScalarAllocas, *DT, nullptr, AC);
     }
   }

+ 1 - 1
tools/clang/include/clang/AST/DeclContextInternals.h

@@ -131,7 +131,7 @@ public:
     } else {
       DeclsTy &Vec = *getAsVector();
       Vec.erase(std::remove_if(Vec.begin(), Vec.end(),
-                               std::mem_fun(&Decl::isFromASTFile)),
+                               std::mem_fn(&Decl::isFromASTFile)),
                 Vec.end());
       // Don't have any external decls any more.
       Data = DeclsAndHasExternalTy(&Vec, false);

+ 7 - 5
tools/clang/include/clang/AST/DeclObjC.h

@@ -386,15 +386,17 @@ public:
                        ArrayRef<SourceLocation> SelLocs = llvm::None);
 
   // Iterator access to parameter types.
-  typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
-  typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
-  param_type_iterator;
+  struct GetTypeFn {
+    QualType operator()(const ParmVarDecl *PD) const { return PD->getType(); }
+  };
+  typedef llvm::mapped_iterator<param_const_iterator, GetTypeFn>
+      param_type_iterator;
 
   param_type_iterator param_type_begin() const {
-    return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
+    return llvm::map_iterator(param_begin(), GetTypeFn());
   }
   param_type_iterator param_type_end() const {
-    return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
+    return llvm::map_iterator(param_end(), GetTypeFn());
   }
 
   /// createImplicitParams - Used to lazily create the self and cmd

+ 1 - 1
tools/clang/include/clang/AST/TypeOrdering.h

@@ -26,7 +26,7 @@
 namespace clang {
 
 /// \brief Function object that provides a total ordering on QualType values.
-struct QualTypeOrdering : std::binary_function<QualType, QualType, bool> {
+struct QualTypeOrdering {
   bool operator()(QualType T1, QualType T2) const {
     return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr());
   }

+ 22 - 22
tools/clang/include/clang/Analysis/CallGraph.h

@@ -173,18 +173,16 @@ namespace llvm {
 template <> struct GraphTraits<clang::CallGraphNode*> {
   typedef clang::CallGraphNode NodeType;
   typedef clang::CallGraphNode::CallRecord CallRecordTy;
-  typedef std::pointer_to_unary_function<CallRecordTy,
-                                         clang::CallGraphNode*> CGNDerefFun;
+  static clang::CallGraphNode *CGNDeref(CallRecordTy P) {
+    return P;
+  }
   static NodeType *getEntryNode(clang::CallGraphNode *CGN) { return CGN; }
-  typedef mapped_iterator<NodeType::iterator, CGNDerefFun> ChildIteratorType;
+  typedef mapped_iterator<NodeType::iterator, decltype(&CGNDeref)> ChildIteratorType;
   static inline ChildIteratorType child_begin(NodeType *N) {
-    return map_iterator(N->begin(), CGNDerefFun(CGNDeref));
+    return ChildIteratorType(N->begin(), &CGNDeref);
   }
   static inline ChildIteratorType child_end  (NodeType *N) {
-    return map_iterator(N->end(), CGNDerefFun(CGNDeref));
-  }
-  static clang::CallGraphNode *CGNDeref(CallRecordTy P) {
-    return P;
+    return ChildIteratorType(N->end(), &CGNDeref);
   }
 };
 
@@ -203,18 +201,19 @@ template <> struct GraphTraits<clang::CallGraph*>
     return CGN->getRoot();  // Start at the external node!
   }
   typedef std::pair<const clang::Decl*, clang::CallGraphNode*> PairTy;
-  typedef std::pointer_to_unary_function<PairTy, clang::CallGraphNode&> DerefFun;
+
+  static clang::CallGraphNode &CGdereference(PairTy P) {
+    return *(P.second);
+  }
+
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
-  typedef mapped_iterator<clang::CallGraph::iterator, DerefFun> nodes_iterator;
+  typedef mapped_iterator<clang::CallGraph::iterator, decltype(&CGdereference)> nodes_iterator;
 
   static nodes_iterator nodes_begin(clang::CallGraph *CG) {
-    return map_iterator(CG->begin(), DerefFun(CGdereference));
+    return nodes_iterator(CG->begin(), &CGdereference);
   }
   static nodes_iterator nodes_end  (clang::CallGraph *CG) {
-    return map_iterator(CG->end(), DerefFun(CGdereference));
-  }
-  static clang::CallGraphNode &CGdereference(PairTy P) {
-    return *(P.second);
+    return nodes_iterator(CG->end(), &CGdereference);
   }
 
   static unsigned size(clang::CallGraph *CG) {
@@ -228,19 +227,20 @@ template <> struct GraphTraits<const clang::CallGraph*> :
     return CGN->getRoot();
   }
   typedef std::pair<const clang::Decl*, clang::CallGraphNode*> PairTy;
-  typedef std::pointer_to_unary_function<PairTy, clang::CallGraphNode&> DerefFun;
+
+  static clang::CallGraphNode &CGdereference(PairTy P) {
+    return *(P.second);
+  }
+
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
   typedef mapped_iterator<clang::CallGraph::const_iterator,
-                          DerefFun> nodes_iterator;
+                          decltype(&CGdereference)> nodes_iterator;
 
   static nodes_iterator nodes_begin(const clang::CallGraph *CG) {
-    return map_iterator(CG->begin(), DerefFun(CGdereference));
+    return nodes_iterator(CG->begin(), &CGdereference);
   }
   static nodes_iterator nodes_end(const clang::CallGraph *CG) {
-    return map_iterator(CG->end(), DerefFun(CGdereference));
-  }
-  static clang::CallGraphNode &CGdereference(PairTy P) {
-    return *(P.second);
+    return nodes_iterator(CG->end(), &CGdereference);
   }
 
   static unsigned size(const clang::CallGraph *CG) {

+ 1 - 2
tools/clang/include/clang/Basic/SourceLocation.h

@@ -320,8 +320,7 @@ public:
   }
 
   /// \brief Comparison function class, useful for sorting FullSourceLocs.
-  struct BeforeThanCompare : public std::binary_function<FullSourceLoc,
-                                                         FullSourceLoc, bool> {
+  struct BeforeThanCompare {
     bool operator()(const FullSourceLoc& lhs, const FullSourceLoc& rhs) const {
       return lhs.isBeforeInTranslationUnitThan(rhs);
     }

+ 3 - 1
tools/clang/lib/Sema/Sema.cpp

@@ -702,7 +702,9 @@ void Sema::ActOnEndOfTranslationUnit() {
   UnusedFileScopedDecls.erase(
       std::remove_if(UnusedFileScopedDecls.begin(nullptr, true),
                      UnusedFileScopedDecls.end(),
-                     std::bind1st(std::ptr_fun(ShouldRemoveFromUnused), this)),
+                     [this](const DeclaratorDecl *DD) { 
+                       return ShouldRemoveFromUnused(this, DD); 
+                     }),
       UnusedFileScopedDecls.end());
 
   if (TUKind == TU_Prefix) {