test-error-unreachable-block.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include "libgccjit.h"
  5. #include "harness.h"
  6. void
  7. create_code (gcc_jit_context *ctxt, void *user_data)
  8. {
  9. /* Let's try to inject the equivalent of:
  10. void
  11. test_fn ()
  12. {
  13. return;
  14. return;
  15. }
  16. where the second block is unreachable.
  17. */
  18. gcc_jit_type *void_t =
  19. gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
  20. /* Build the test_fn. */
  21. gcc_jit_function *test_fn =
  22. gcc_jit_context_new_function (ctxt, NULL,
  23. GCC_JIT_FUNCTION_EXPORTED,
  24. void_t,
  25. "test_fn",
  26. 0, NULL,
  27. 0);
  28. gcc_jit_block *initial =
  29. gcc_jit_function_new_block (test_fn, "a");
  30. gcc_jit_block *unreachable =
  31. gcc_jit_function_new_block (test_fn, "b");
  32. gcc_jit_block_end_with_void_return (initial, NULL);
  33. gcc_jit_block_end_with_void_return (unreachable, NULL);
  34. }
  35. void
  36. verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
  37. {
  38. CHECK_VALUE (result, NULL);
  39. CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
  40. "unreachable block: b");
  41. }