DebugInfo: provide the ability to add members to a class after it has been constructed
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 9 Aug 2013 17:17:12 +0000 (17:17 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 9 Aug 2013 17:17:12 +0000 (17:17 +0000)
This is necessary to allow Clang to only emit implicit members when
there is code generated for them, rather than whenever they are ODR
used.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188082 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo.h
lib/IR/DebugInfo.cpp

index 74416db217528f77d9975594a6e4012f60d164f8..b02446abbbfdd0e4957b6a785f8d07a924664bbb 100644 (file)
@@ -323,6 +323,7 @@ namespace llvm {
 
     DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
     void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
+    void addMember(DISubprogram S);
     unsigned getRunTimeLang() const { return getUnsignedField(11); }
     DICompositeType getContainingType() const {
       return getFieldAs<DICompositeType>(12);
index fc9324949d0d960e8f0afd53fbcd0191fd5f65a7..0f7ddb5961c856d92a039455c4cdec369b71a89d 100644 (file)
@@ -647,6 +647,19 @@ void DICompositeType::setTypeArray(DIArray Elements, DIArray TParams) {
   DbgNode = N;
 }
 
+void DICompositeType::addMember(DISubprogram S) {
+  SmallVector<llvm::Value *, 16> M;
+  DIArray OrigM = getTypeArray();
+  unsigned Elements = OrigM.getNumElements();
+  if (Elements == 1 && !OrigM.getElement(0))
+    Elements = 0;
+  M.reserve(Elements + 1);
+  for (unsigned i = 0; i != Elements; ++i)
+    M.push_back(OrigM.getElement(i));
+  M.push_back(S);
+  setTypeArray(DIArray(MDNode::get(DbgNode->getContext(), M)));
+}
+
 /// \brief Set the containing type.
 void DICompositeType::setContainingType(DICompositeType ContainingType) {
   TrackingVH<MDNode> N(*this);