This file is indexed.

/usr/src/gcc-5/debian/patches/pr69144.diff is in gcc-5-source 5.5.0-12ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
gcc/jit/

2016-01-19  David Malcolm  <dmalcolm@redhat.com>

	PR jit/69144
	* jit-playback.c (gcc::jit::playback::compile_to_file::postprocess):
	Potentially add the temporary artifact to the tempdir's list of
	tempfiles needing additional cleanup.
	(gcc::jit::playback::context::extract_any_requested_dumps): Likewise
	for the dumpfile.
	* jit-tempdir.c (gcc::jit::tempdir::~tempdir): Clean up additional
	tempfiles.
	* jit-tempdir.h (gcc::jit::tempdir::add_temp_file): New method.
	(gcc::jit::tempdir::m_tempfiles): New field.
	* docs/cp/intro/tutorial04.rst: Update for changes to toyvm.cc.
	* docs/examples/tut04-toyvm/toyvm.cc (class compilation_result):
	New.
	(toyvm_function::compile): Change return type from function ptr
	to a compilation_result.
	(toyvm_function::get_function_name): New accessor.
	(toyvm_function::m_funcname): New field.
	(get_function_name): Convert to...
	(toyvm_function::make_function_name): ...this new method.
	(toyvm_function::parse): Call make_function_name.
	(toyvm_function::compile): Convert return type from function ptr
	to a compilation_result.  Use get_function_name.
	(compilation_state::compile): Convert return type from
	gcc_jit_result * to a compilation_result.
	(test_script): Update for above changes, extracting the code from
	the compilation_result.
	(main): Likewise.

 
Index: b/src/gcc/jit/docs/cp/intro/tutorial04.rst
===================================================================
--- a/src/gcc/jit/docs/cp/intro/tutorial04.rst
+++ b/src/gcc/jit/docs/cp/intro/tutorial04.rst
@@ -297,15 +297,14 @@ Compiling the context
 Having finished looping over the blocks and populating them with
 statements, the context is complete.
 
-We can now compile it, and extract machine code from the result:
+We can now compile it, extract machine code from the result, and
+run it:
 
    .. literalinclude:: ../../examples/tut04-toyvm/toyvm.cc
-    :start-after: /* We've now finished populating the context.  Compile it.  */
-    :end-before: /* (this leaks "result" and "funcname") */
+    :start-after: /* Wrapper around a gcc_jit_result *.  */
+    :end-before: /* Functions are compiled to this function ptr type.  */
     :language: c++
 
-We can now run the result:
-
    .. literalinclude:: ../../examples/tut04-toyvm/toyvm.cc
     :start-after: /* JIT-compilation.  */
     :end-before: return 0;
Index: b/src/gcc/jit/docs/examples/tut04-toyvm/toyvm.cc
===================================================================
--- a/src/gcc/jit/docs/examples/tut04-toyvm/toyvm.cc
+++ b/src/gcc/jit/docs/examples/tut04-toyvm/toyvm.cc
@@ -28,6 +28,29 @@ along with GCC; see the file COPYING3.
 
 #include <libgccjit++.h>
 
+/* Wrapper around a gcc_jit_result *.  */
+
+class compilation_result
+{
+public:
+  compilation_result (gcc_jit_result *result) :
+    m_result (result)
+  {
+  }
+  ~compilation_result ()
+  {
+    gcc_jit_result_release (m_result);
+  }
+
+  void *get_code (const char *funcname)
+  {
+    return gcc_jit_result_get_code (m_result, funcname);
+  }
+
+private:
+  gcc_jit_result *m_result;
+};
+
 /* Functions are compiled to this function ptr type.  */
 typedef int (*toyvm_compiled_func) (int);
 
@@ -100,11 +123,19 @@ public:
   int
   interpret (int arg, FILE *trace);
 
-  toyvm_compiled_func
+  compilation_result
   compile ();
 
+  const char *
+  get_function_name () const { return m_funcname; }
+
+private:
+  void
+  make_function_name (const char *filename);
+
 private:
   const char *fn_filename;
+  char       *m_funcname;
   int         fn_num_ops;
   toyvm_op    fn_ops[MAX_OPS];
   friend struct compilation_state;
@@ -149,8 +180,8 @@ toyvm_function::add_unary_op (enum opcod
   add_op (opcode, operand, linenum);
 }
 
-static char *
-get_function_name (const char *filename)
+void
+toyvm_function::make_function_name (const char *filename)
 {
   /* Skip any path separators.  */
   const char *pathsep = strrchr (filename, '/');
@@ -158,14 +189,12 @@ get_function_name (const char *filename)
     filename = pathsep + 1;
 
   /* Copy filename to funcname.  */
-  char *funcname = (char *)malloc (strlen (filename) + 1);
+  m_funcname = (char *)malloc (strlen (filename) + 1);
 
-  strcpy (funcname, filename);
+  strcpy (m_funcname, filename);
 
   /* Convert "." to NIL terminator.  */
-  *(strchr (funcname, '.')) = '\0';
-
-  return funcname;
+  *(strchr (m_funcname, '.')) = '\0';
 }
 
 toyvm_function *
@@ -197,6 +226,7 @@ toyvm_function::parse (const char *filen
       goto error;
     }
   fn->fn_filename = filename;
+  fn->make_function_name (filename);
 
   /* Read the lines of the file.  */
   while ((linelen = getline (&line, &bufsize, f)) != -1)
@@ -420,7 +450,7 @@ public:
   void create_types ();
   void create_locations ();
   void create_function (const char *funcname);
-  gcc_jit_result *compile ();
+  compilation_result compile ();
 
 private:
   void
@@ -462,24 +492,18 @@ private:
 
 /* The main compilation hook.  */
 
-toyvm_compiled_func
+compilation_result
 toyvm_function::compile ()
 {
   compilation_state state (*this);
-  char *funcname;
-
-  funcname = get_function_name (fn_filename);
 
   state.create_context ();
   state.create_types ();
   state.create_locations ();
-  state.create_function (funcname);
+  state.create_function (get_function_name ());
 
   /* We've now finished populating the context.  Compile it.  */
-  gcc_jit_result *result = state.compile ();
-
-  return (toyvm_compiled_func)gcc_jit_result_get_code (result, funcname);
-  /* (this leaks "result" and "funcname") */
+  return state.compile ();
 }
 
 /* Stack manipulation.  */
@@ -767,7 +791,7 @@ compilation_state::create_function (cons
     } /* end of loop on PC locations.  */
 }
 
-gcc_jit_result *
+compilation_result
 compilation_state::compile ()
 {
   return ctxt.compile ();
@@ -825,7 +849,10 @@ test_script (const char *scripts_dir, co
   interpreted_result = fn->interpret (input, NULL);
   CHECK_VALUE (interpreted_result, expected_result);
 
-  code = fn->compile ();
+  compilation_result compiler_result = fn->compile ();
+
+  const char *funcname = fn->get_function_name ();
+  code = (toyvm_compiled_func)compiler_result.get_code (funcname);
   CHECK_NON_NULL (code);
 
   compiled_result = code (input);
@@ -894,7 +921,12 @@ main (int argc, char **argv)
 	  fn->interpret (atoi (argv[2]), NULL));
 
   /* JIT-compilation.  */
-  toyvm_compiled_func code = fn->compile ();
+  compilation_result compiler_result = fn->compile ();
+
+  const char *funcname = fn->get_function_name ();
+  toyvm_compiled_func code
+    = (toyvm_compiled_func)compiler_result.get_code (funcname);
+
   printf ("compiler result: %d\n",
 	  code (atoi (argv[2])));
 
Index: b/src/gcc/jit/jit-playback.c
===================================================================
--- a/src/gcc/jit/jit-playback.c
+++ b/src/gcc/jit/jit-playback.c
@@ -1954,6 +1954,7 @@ playback::compile_to_file::postprocess (
     case GCC_JIT_OUTPUT_KIND_ASSEMBLER:
       copy_file (get_tempdir ()->get_path_s_file (),
 		 m_output_path);
+      /* The .s file is automatically unlinked by tempdir::~tempdir.  */
       break;
 
     case GCC_JIT_OUTPUT_KIND_OBJECT_FILE:
@@ -1968,9 +1969,13 @@ playback::compile_to_file::postprocess (
 		       false, /* bool shared, */
 		       false);/* bool run_linker */
 	if (!errors_occurred ())
-	  copy_file (tmp_o_path,
-		     m_output_path);
-	free (tmp_o_path);
+	  {
+	    copy_file (tmp_o_path,
+		       m_output_path);
+	    get_tempdir ()->add_temp_file (tmp_o_path);
+	  }
+	else
+	  free (tmp_o_path);
       }
       break;
 
@@ -1984,6 +1989,7 @@ playback::compile_to_file::postprocess (
       if (!errors_occurred ())
 	copy_file (get_tempdir ()->get_path_so_file (),
 		   m_output_path);
+      /* The .so file is automatically unlinked by tempdir::~tempdir.  */
       break;
 
     case GCC_JIT_OUTPUT_KIND_EXECUTABLE:
@@ -1998,9 +2004,13 @@ playback::compile_to_file::postprocess (
 		       false, /* bool shared, */
 		       true);/* bool run_linker */
 	if (!errors_occurred ())
-	  copy_file (tmp_exe_path,
-		     m_output_path);
-	free (tmp_exe_path);
+	  {
+	    copy_file (tmp_exe_path,
+		       m_output_path);
+	    get_tempdir ()->add_temp_file (tmp_exe_path);
+	  }
+	else
+	  free (tmp_exe_path);
       }
       break;
 
@@ -2340,7 +2350,7 @@ extract_any_requested_dumps (vec <record
       filename = g->get_dumps ()->get_dump_file_name (dfi);
       content = read_dump_file (filename);
       *(d->m_out_ptr) = content;
-      free (filename);
+      m_tempdir->add_temp_file (filename);
     }
 }
 
Index: b/src/gcc/jit/jit-tempdir.c
===================================================================
--- a/src/gcc/jit/jit-tempdir.c
+++ b/src/gcc/jit/jit-tempdir.c
@@ -121,7 +121,7 @@ gcc::jit::tempdir::~tempdir ()
     fprintf (stderr, "intermediate files written to %s\n", m_path_tempdir);
   else
     {
-      /* Clean up .s/.so and tempdir. */
+      /* Clean up .s/.so.  */
       if (m_path_s_file)
 	{
 	  log ("unlinking .s file: %s", m_path_s_file);
@@ -132,6 +132,17 @@ gcc::jit::tempdir::~tempdir ()
 	  log ("unlinking .so file: %s", m_path_so_file);
 	  unlink (m_path_so_file);
 	}
+
+      /* Clean up any other tempfiles.  */
+      int i;
+      char *tempfile;
+      FOR_EACH_VEC_ELT (m_tempfiles, i, tempfile)
+	{
+	  log ("unlinking tempfile: %s", tempfile);
+	  unlink (tempfile);
+	}
+
+      /* The tempdir should now be empty; remove it.  */
       if (m_path_tempdir)
 	{
 	  log ("removing tempdir: %s", m_path_tempdir);
@@ -145,4 +156,9 @@ gcc::jit::tempdir::~tempdir ()
   free (m_path_c_file);
   free (m_path_s_file);
   free (m_path_so_file);
+
+  int i;
+  char *tempfile;
+  FOR_EACH_VEC_ELT (m_tempfiles, i, tempfile)
+    free (tempfile);
 }
Index: b/src/gcc/jit/jit-tempdir.h
===================================================================
--- a/src/gcc/jit/jit-tempdir.h
+++ b/src/gcc/jit/jit-tempdir.h
@@ -58,6 +58,10 @@ class tempdir : public log_user
   const char * get_path_s_file () const { return m_path_s_file; }
   const char * get_path_so_file () const { return m_path_so_file; }
 
+  /* Add PATH to the vec of tempfiles that must be unlinked.
+     Take ownership of the buffer PATH; it will be freed.  */
+  void add_temp_file (char *path) { m_tempfiles.safe_push (path); }
+
  private:
   /* Was GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES set?  If so, keep the
      on-disk tempdir around after this wrapper object goes away.  */
@@ -74,6 +78,10 @@ class tempdir : public log_user
   char *m_path_s_file;
   char *m_path_so_file;
 
+  /* Other files within the tempdir to be cleaned up:
+     - certain ahead-of-time compilation artifacts (.o and .exe files)
+     - dumpfiles that were requested via gcc_jit_context_enable_dump.  */
+  auto_vec <char *> m_tempfiles;
 };
 
 } // namespace gcc::jit