[cfe-commits] r98263 - in /cfe/trunk: include/clang/Driver/Action.h lib/Driver/Action.cpp lib/Driver/Driver.cpp

Daniel Dunbar daniel at zuster.org
Thu Mar 11 10:04:58 PST 2010


Author: ddunbar
Date: Thu Mar 11 12:04:58 2010
New Revision: 98263

URL: http://llvm.org/viewvc/llvm-project?rev=98263&view=rev
Log:
Driver: Free Action objects.

Modified:
    cfe/trunk/include/clang/Driver/Action.h
    cfe/trunk/lib/Driver/Action.cpp
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/include/clang/Driver/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Action.h?rev=98263&r1=98262&r2=98263&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Action.h (original)
+++ cfe/trunk/include/clang/Driver/Action.h Thu Mar 11 12:04:58 2010
@@ -66,17 +66,23 @@
 
   ActionList Inputs;
 
+  unsigned OwnsInputs : 1;
+
 protected:
-  Action(ActionClass _Kind, types::ID _Type) : Kind(_Kind), Type(_Type) {}
+  Action(ActionClass _Kind, types::ID _Type)
+    : Kind(_Kind), Type(_Type), OwnsInputs(true)  {}
   Action(ActionClass _Kind, Action *Input, types::ID _Type)
-    : Kind(_Kind), Type(_Type), Inputs(&Input, &Input + 1) {}
+    : Kind(_Kind), Type(_Type), Inputs(&Input, &Input + 1), OwnsInputs(true) {}
   Action(ActionClass _Kind, const ActionList &_Inputs, types::ID _Type)
-    : Kind(_Kind), Type(_Type), Inputs(_Inputs) {}
+    : Kind(_Kind), Type(_Type), Inputs(_Inputs), OwnsInputs(true) {}
 public:
   virtual ~Action();
 
   const char *getClassName() const { return Action::getClassName(getKind()); }
 
+  bool getOwnsInputs() { return OwnsInputs; }
+  void setOwnsInputs(bool Value) { OwnsInputs = Value; }
+
   ActionClass getKind() const { return Kind; }
   types::ID getType() const { return Type; }
 

Modified: cfe/trunk/lib/Driver/Action.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Action.cpp?rev=98263&r1=98262&r2=98263&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Action.cpp (original)
+++ cfe/trunk/lib/Driver/Action.cpp Thu Mar 11 12:04:58 2010
@@ -13,8 +13,10 @@
 using namespace clang::driver;
 
 Action::~Action() {
-  // FIXME: Free the inputs. The problem is that BindArchAction shares
-  // inputs; so we can't just walk the inputs.
+  if (OwnsInputs) {
+    for (iterator it = begin(), ie = end(); it != ie; ++it)
+      delete *it;
+  }
 }
 
 const char *Action::getClassName(ActionClass AC) {

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=98263&r1=98262&r2=98263&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu Mar 11 12:04:58 2010
@@ -503,8 +503,11 @@
         << types::getTypeName(Act->getType());
 
     ActionList Inputs;
-    for (unsigned i = 0, e = Archs.size(); i != e; ++i)
+    for (unsigned i = 0, e = Archs.size(); i != e; ++i) {
       Inputs.push_back(new BindArchAction(Act, Archs[i]));
+      if (i != 0)
+        Inputs.back()->setOwnsInputs(false);
+    }
 
     // Lipo if necessary, we do it this way because we need to set the arch flag
     // so that -Xarch_ gets overwritten.





More information about the cfe-commits mailing list