1 /* PR jit/63969: libgccjit would segfault inside gcc_jit_context_compile
2    if the driver wasn't found on PATH if GCC_JIT_STR_OPTION_PROGNAME was
3    NULL.  */
4 
5 #include <stdlib.h>
6 #include <stdio.h>
7 
8 #include "libgccjit.h"
9 
10 #include "harness.h"
11 
12 void
create_code(gcc_jit_context * ctxt,void * user_data)13 create_code (gcc_jit_context *ctxt, void *user_data)
14 {
15   /* Create nothing within the context.  */
16 
17   /* harness.h's set_options has set a sane value for
18      GCC_JIT_STR_OPTION_PROGNAME, but PR jit/63969 only segfaulted if it's
19      NULL.
20 
21      Unset it.  */
22   gcc_jit_context_set_str_option (ctxt, GCC_JIT_STR_OPTION_PROGNAME, NULL);
23 
24   /* By default, we use an embedded copy of the driver.
25      Opt-in to using an external copy of the driver.  */
26   gcc_jit_context_set_bool_use_external_driver (ctxt, 1);
27 
28   /* Break PATH, so that the driver can't be found
29      by gcc::jit::playback::context::compile ()
30      within gcc_jit_context_compile.  */
31   unsetenv ("PATH");
32 }
33 
34 void
verify_code(gcc_jit_context * ctxt,gcc_jit_result * result)35 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
36 {
37   CHECK_VALUE (result, NULL);
38 
39   /* Verify that a sane error message was emitted.  */
40   CHECK_STRING_STARTS_WITH (gcc_jit_context_get_first_error (ctxt),
41 			    "error invoking gcc driver");
42 }
43