test-error-pr63969-missing-driver.c 1012 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include "libgccjit.h"
  7. #include "harness.h"
  8. void
  9. create_code (gcc_jit_context *ctxt, void *user_data)
  10. {
  11. /* Create nothing within the context. */
  12. /* harness.h's set_options has set a sane value for
  13. GCC_JIT_STR_OPTION_PROGNAME, but PR jit/63969 only segfaulted if it's
  14. NULL.
  15. Unset it. */
  16. gcc_jit_context_set_str_option (ctxt, GCC_JIT_STR_OPTION_PROGNAME, NULL);
  17. /* Break PATH, so that the driver can't be found
  18. by gcc::jit::playback::context::compile ()
  19. within gcc_jit_context_compile. */
  20. unsetenv ("PATH");
  21. }
  22. void
  23. verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
  24. {
  25. CHECK_VALUE (result, NULL);
  26. /* Verify that a sane error message was emitted. */
  27. CHECK_STRING_STARTS_WITH (gcc_jit_context_get_first_error (ctxt),
  28. "error invoking gcc driver");
  29. }