aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/jit.dg/test-error-pr63969-missing-driver.c
blob: 13f5e3b5b83ba1123e9691233c4c99675946842f (plain)
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
/* PR jit/63969: libgccjit would segfault inside gcc_jit_context_compile
   if the driver wasn't found on PATH if GCC_JIT_STR_OPTION_PROGNAME was
   NULL.  */

#include <stdlib.h>
#include <stdio.h>

#include "libgccjit.h"

#include "harness.h"

void
create_code (gcc_jit_context *ctxt, void *user_data)
{
  /* Create nothing within the context.  */

  /* harness.h's set_options has set a sane value for
     GCC_JIT_STR_OPTION_PROGNAME, but PR jit/63969 only segfaulted if it's
     NULL.

     Unset it.  */
  gcc_jit_context_set_str_option (ctxt, GCC_JIT_STR_OPTION_PROGNAME, NULL);

  /* Break PATH, so that the driver can't be found
     by gcc::jit::playback::context::compile ()
     within gcc_jit_context_compile.  */
  unsetenv ("PATH");
}

void
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
{
  CHECK_VALUE (result, NULL);

  /* Verify that a sane error message was emitted.  */
  CHECK_STRING_STARTS_WITH (gcc_jit_context_get_first_error (ctxt),
			    "error invoking gcc driver");
}