[cfe-commits] r47565 - /cfe/trunk/Lex/HeaderSearch.cpp

Chris Lattner sabre at nondot.org
Mon Feb 25 13:38:22 PST 2008


Author: lattner
Date: Mon Feb 25 15:38:21 2008
New Revision: 47565

URL: http://llvm.org/viewvc/llvm-project?rev=47565&view=rev
Log:
clarify comment, this is undefined behavior in any case, even if it only
bits VC++ right now.

Modified:
    cfe/trunk/Lex/HeaderSearch.cpp

Modified: cfe/trunk/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/HeaderSearch.cpp?rev=47565&r1=47564&r2=47565&view=diff

==============================================================================
--- cfe/trunk/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/Lex/HeaderSearch.cpp Mon Feb 25 15:38:21 2008
@@ -228,22 +228,12 @@
     if (const FileEntry *FE = FileMgr.getFile(TmpDir.begin(), TmpDir.end())) {
       // Leave CurDir unset.
       // This file is a system header or C++ unfriendly if the old file is.
-      
-      // Note: Don't use:
       //
-      //  getFileInfo(FE).DirInfo = getFileInfo(CurFileEnt).DirInfo;
-      //
-      // MSVC, behind the scenes, does this:
-      //
-      //  PerFileInfo &pf1 = getFileInfo(CurFileEnt);
-      //  PerFileInfo &pf2 = getFileInfo(FE);
-      //  pf2.DirInfo = pf1.DirInfo
-      //
-      // The problem is that if there's a resize() of the FileInfo vector during
-      // the getFileInfo(FE) call, pf1 will point to invalid data.  To fix
-      // this problem, make the assignment through a temporary.
-      unsigned int tmp = getFileInfo(CurFileEnt).DirInfo;
-      getFileInfo(FE).DirInfo = tmp;
+      // Note that the temporary 'DirInfo' is required here, as either call to
+      // getFileInfo could resize the vector and we don't want to rely on order
+      // of evaluation.
+      unsigned DirInfo = getFileInfo(CurFileEnt).DirInfo;
+      getFileInfo(FE).DirInfo = DirInfo;
       return FE;
     }
   }
@@ -372,22 +362,12 @@
   }
   
   // This file is a system header or C++ unfriendly if the old file is.
-
-  // Note: Don't use:
-  //
-  //  getFileInfo(FE).DirInfo = getFileInfo(ContextFileEnt).DirInfo;
-  //
-  // MSVC, behind the scenes, does this:
-  //
-  //  PerFileInfo &pf1 = getFileInfo(ContextFileEnt);
-  //  PerFileInfo &pf2 = getFileInfo(FE);
-  //  pf2.DirInfo = pf1.DirInfo
   //
-  // The problem is that if there's a resize() of the FileInfo vector during
-  // the getFileInfo(FE) call, pf1 will point to invalid data.  The solution
-  // is to make the assignment through a temporary.
-  unsigned int tmp = getFileInfo(ContextFileEnt).DirInfo;
-  getFileInfo(FE).DirInfo = tmp;
+  // Note that the temporary 'DirInfo' is required here, as either call to
+  // getFileInfo could resize the vector and we don't want to rely on order
+  // of evaluation.
+  unsigned DirInfo = getFileInfo(ContextFileEnt).DirInfo;
+  getFileInfo(FE).DirInfo = DirInfo;
   return FE;
 }
 





More information about the cfe-commits mailing list