[PATCH] D17884: Disallow duplication of imported entities

Amjad Aboud via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 13 04:16:33 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL263379: Fixed DIBuilder to verify that same imported entity will not be added twice… (authored by aaboud).

Changed prior to commit:
  http://reviews.llvm.org/D17884?vs=50112&id=50549#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17884

Files:
  llvm/trunk/lib/IR/DIBuilder.cpp
  llvm/trunk/unittests/IR/IRBuilderTest.cpp

Index: llvm/trunk/lib/IR/DIBuilder.cpp
===================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp
+++ llvm/trunk/lib/IR/DIBuilder.cpp
@@ -19,6 +19,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Dwarf.h"
+#include "LLVMContextImpl.h"
 
 using namespace llvm;
 using namespace llvm::dwarf;
@@ -168,8 +169,12 @@
 createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context,
                      Metadata *NS, unsigned Line, StringRef Name,
                      SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
+  unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
   auto *M = DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), Line, Name);
-  AllImportedModules.emplace_back(M);
+  if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
+    // A new Imported Entity was just added to the context.
+    // Add it to the Imported Modules list.
+    AllImportedModules.emplace_back(M);
   return M;
 }
 
Index: llvm/trunk/unittests/IR/IRBuilderTest.cpp
===================================================================
--- llvm/trunk/unittests/IR/IRBuilderTest.cpp
+++ llvm/trunk/unittests/IR/IRBuilderTest.cpp
@@ -418,4 +418,19 @@
 
   DIB.finalize();
 }
+
+TEST_F(IRBuilderTest, DIImportedEntity) {
+  IRBuilder<> Builder(BB);
+  DIBuilder DIB(*M);
+  auto File = DIB.createFile("F.CBL", "/");
+  auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74, "F.CBL", "/",
+    "llvm-cobol74", true, "", 0);
+  auto IE1 = DIB.createImportedDeclaration(CU, nullptr, 1);
+  auto IE2 = DIB.createImportedDeclaration(CU, nullptr, 1);
+  auto IE3 = DIB.createImportedModule(CU, (DIImportedEntity*)nullptr, 2);
+  auto IE4 = DIB.createImportedModule(CU, (DIImportedEntity*)nullptr, 2);
+  DIB.finalize();
+  EXPECT_TRUE(verifyModule(*M));
+  EXPECT_TRUE(CU->getImportedEntities().size() == 2);
+}
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17884.50549.patch
Type: text/x-patch
Size: 1910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160313/6fbc1df9/attachment.bin>


More information about the llvm-commits mailing list