[llvm-commits] [llvm] r95856 - in /llvm/trunk: include/llvm/DerivedTypes.h include/llvm/Support/SourceMgr.h lib/VMCore/LLVMContextImpl.h lib/VMCore/Type.cpp unittests/VMCore/DerivedTypesTest.cpp

Jeffrey Yasskin jyasskin at google.com
Wed Feb 10 22:41:30 PST 2010


Author: jyasskin
Date: Thu Feb 11 00:41:30 2010
New Revision: 95856

URL: http://llvm.org/viewvc/llvm-project?rev=95856&view=rev
Log:
Fix some of the memcheck errors found in the JIT unittests.

Modified:
    llvm/trunk/include/llvm/DerivedTypes.h
    llvm/trunk/include/llvm/Support/SourceMgr.h
    llvm/trunk/lib/VMCore/LLVMContextImpl.h
    llvm/trunk/lib/VMCore/Type.cpp
    llvm/trunk/unittests/VMCore/DerivedTypesTest.cpp

Modified: llvm/trunk/include/llvm/DerivedTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DerivedTypes.h?rev=95856&r1=95855&r2=95856&view=diff

==============================================================================
--- llvm/trunk/include/llvm/DerivedTypes.h (original)
+++ llvm/trunk/include/llvm/DerivedTypes.h Thu Feb 11 00:41:30 2010
@@ -496,6 +496,7 @@
 /// OpaqueType - Class to represent abstract types
 ///
 class OpaqueType : public DerivedType {
+  friend class LLVMContextImpl;
   OpaqueType(const OpaqueType &);                   // DO NOT IMPLEMENT
   const OpaqueType &operator=(const OpaqueType &);  // DO NOT IMPLEMENT
   OpaqueType(LLVMContext &C);

Modified: llvm/trunk/include/llvm/Support/SourceMgr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/SourceMgr.h?rev=95856&r1=95855&r2=95856&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/SourceMgr.h (original)
+++ llvm/trunk/include/llvm/Support/SourceMgr.h Thu Feb 11 00:41:30 2010
@@ -132,7 +132,7 @@
   unsigned ShowLine : 1;
 
 public:
-  SMDiagnostic() : LineNo(0), ColumnNo(0) {}
+  SMDiagnostic() : LineNo(0), ColumnNo(0), ShowLine(0) {}
   SMDiagnostic(const std::string &FN, int Line, int Col,
                const std::string &Msg, const std::string &LineStr,
                bool showline = true)

Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=95856&r1=95855&r2=95856&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Thu Feb 11 00:41:30 2010
@@ -164,7 +164,10 @@
   // Opaque types are not structurally uniqued, so don't use TypeMap.
   typedef SmallPtrSet<const OpaqueType*, 8> OpaqueTypesTy;
   OpaqueTypesTy OpaqueTypes;
-  
+
+  /// Used as an abstract type that will never be resolved.
+  OpaqueType *const AlwaysOpaqueTy;
+
 
   /// ValueHandles - This map keeps track of all of the value handles that are
   /// watching a Value*.  The Value::HasValueHandle bit is used to know
@@ -196,7 +199,12 @@
     Int8Ty(C, 8),
     Int16Ty(C, 16),
     Int32Ty(C, 32),
-    Int64Ty(C, 64) { }
+    Int64Ty(C, 64),
+    AlwaysOpaqueTy(new OpaqueType(C)) {
+    // Make sure the AlwaysOpaqueTy stays alive as long as the Context.
+    AlwaysOpaqueTy->addRef();
+    OpaqueTypes.insert(AlwaysOpaqueTy);
+  }
 
   ~LLVMContextImpl() {
     ExprConstants.freeConstants();
@@ -217,6 +225,7 @@
         delete I->second;
     }
     MDNodeSet.clear();
+    AlwaysOpaqueTy->dropRef();
     for (OpaqueTypesTy::iterator I = OpaqueTypes.begin(), E = OpaqueTypes.end();
         I != E; ++I) {
       (*I)->AbstractTypeUsers.clear();

Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=95856&r1=95855&r2=95856&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Thu Feb 11 00:41:30 2010
@@ -507,30 +507,7 @@
   if (NumContainedTys != 0) {
     // The type must stay abstract.  To do this, we insert a pointer to a type
     // that will never get resolved, thus will always be abstract.
-    static Type *AlwaysOpaqueTy = 0;
-    static PATypeHolder* Holder = 0;
-    Type *tmp = AlwaysOpaqueTy;
-    if (llvm_is_multithreaded()) {
-      sys::MemoryFence();
-      if (!tmp) {
-        llvm_acquire_global_lock();
-        tmp = AlwaysOpaqueTy;
-        if (!tmp) {
-          tmp = OpaqueType::get(getContext());
-          PATypeHolder* tmp2 = new PATypeHolder(tmp);
-          sys::MemoryFence();
-          AlwaysOpaqueTy = tmp;
-          Holder = tmp2;
-        }
-      
-        llvm_release_global_lock();
-      }
-    } else if (!AlwaysOpaqueTy) {
-      AlwaysOpaqueTy = OpaqueType::get(getContext());
-      Holder = new PATypeHolder(AlwaysOpaqueTy);
-    } 
-        
-    ContainedTys[0] = AlwaysOpaqueTy;
+    ContainedTys[0] = getContext().pImpl->AlwaysOpaqueTy;
 
     // Change the rest of the types to be Int32Ty's.  It doesn't matter what we
     // pick so long as it doesn't point back to this type.  We choose something

Modified: llvm/trunk/unittests/VMCore/DerivedTypesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/VMCore/DerivedTypesTest.cpp?rev=95856&r1=95855&r2=95856&view=diff

==============================================================================
--- llvm/trunk/unittests/VMCore/DerivedTypesTest.cpp (original)
+++ llvm/trunk/unittests/VMCore/DerivedTypesTest.cpp Thu Feb 11 00:41:30 2010
@@ -18,14 +18,16 @@
 
 TEST(OpaqueTypeTest, RegisterWithContext) {
   LLVMContext C;
-  LLVMContextImpl *pImpl = C.pImpl;  
+  LLVMContextImpl *pImpl = C.pImpl;
 
-  EXPECT_EQ(0u, pImpl->OpaqueTypes.size());
+  // 1 refers to the AlwaysOpaqueTy allocated in the Context's constructor and
+  // destroyed in the destructor.
+  EXPECT_EQ(1u, pImpl->OpaqueTypes.size());
   {
     PATypeHolder Type = OpaqueType::get(C);
-    EXPECT_EQ(1u, pImpl->OpaqueTypes.size());
+    EXPECT_EQ(2u, pImpl->OpaqueTypes.size());
   }
-  EXPECT_EQ(0u, pImpl->OpaqueTypes.size());
+  EXPECT_EQ(1u, pImpl->OpaqueTypes.size());
 }
 
 }  // namespace





More information about the llvm-commits mailing list