CodeGeneration: Fix double free in vector for

We now use __isl_take to annotate the uses of the isl_set where we got the
memory management wrong.

Thanks to Rafael! His pipefail work hardened our test environment and exposed
this bug nicely.

llvm-svn: 187338
diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp
index 950a06a7..ec7b111 100644
--- a/polly/lib/CodeGen/CodeGeneration.cpp
+++ b/polly/lib/CodeGen/CodeGeneration.cpp
@@ -275,7 +275,8 @@
                             std::vector<LoopToScevMapT> *VLTS = 0);
 
   void codegen(const clast_user_stmt *u, std::vector<Value *> *IVS = NULL,
-               const char *iterator = NULL, isl_set *scatteringDomain = 0);
+               const char *iterator = NULL,
+               __isl_take isl_set *scatteringDomain = 0);
 
   void codegen(const clast_block *b);
 
@@ -417,19 +418,21 @@
 // PartialSchedule, where the PartialSchedule contains all the dimensions that
 // have been code generated up to this point.
 static __isl_give isl_map *extractPartialSchedule(ScopStmt *Statement,
-                                                  isl_set *Domain) {
+                                                  __isl_take isl_set *Domain) {
   isl_map *Schedule = Statement->getScattering();
   int ScheduledDimensions = isl_set_dim(Domain, isl_dim_set);
   int UnscheduledDimensions =
       isl_map_dim(Schedule, isl_dim_out) - ScheduledDimensions;
 
+  isl_set_free(Domain);
+
   return isl_map_project_out(Schedule, isl_dim_out, ScheduledDimensions,
                              UnscheduledDimensions);
 }
 
 void ClastStmtCodeGen::codegen(const clast_user_stmt *u,
                                std::vector<Value *> *IVS, const char *iterator,
-                               isl_set *Domain) {
+                               __isl_take isl_set *Domain) {
   ScopStmt *Statement = (ScopStmt *)u->statement->usr;
 
   if (u->substitutions)
@@ -819,7 +822,7 @@
   for (int i = 1; i < VectorWidth; i++)
     IVS[i] = Builder.CreateAdd(IVS[i - 1], StrideValue, "p_vector_iv");
 
-  isl_set *Domain = isl_set_from_cloog_domain(F->domain);
+  isl_set *Domain = isl_set_copy(isl_set_from_cloog_domain(F->domain));
 
   // Add loop iv to symbols.
   ClastVars[F->iterator] = LB;
@@ -838,12 +841,12 @@
 }
 
 bool ClastStmtCodeGen::isParallelFor(const clast_for *f) {
-  isl_set *Domain = isl_set_from_cloog_domain(f->domain);
+  isl_set *Domain = isl_set_copy(isl_set_from_cloog_domain(f->domain));
   assert(Domain && "Cannot access domain of loop");
 
   Dependences &D = P->getAnalysis<Dependences>();
 
-  return D.isParallelDimension(isl_set_copy(Domain), isl_set_n_dim(Domain));
+  return D.isParallelDimension(Domain, isl_set_n_dim(Domain));
 }
 
 void ClastStmtCodeGen::codegen(const clast_for *f) {