test-validly-unreachable-block.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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, but have it
  17. survive validation (PR jit/66546).
  18. */
  19. gcc_jit_context_set_bool_allow_unreachable_blocks (ctxt, 1);
  20. gcc_jit_type *void_t =
  21. gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
  22. /* Build the test_fn. */
  23. gcc_jit_function *test_fn =
  24. gcc_jit_context_new_function (ctxt, NULL,
  25. GCC_JIT_FUNCTION_EXPORTED,
  26. void_t,
  27. "test_fn",
  28. 0, NULL,
  29. 0);
  30. gcc_jit_block *initial =
  31. gcc_jit_function_new_block (test_fn, "a");
  32. gcc_jit_block *unreachable =
  33. gcc_jit_function_new_block (test_fn, "b");
  34. gcc_jit_block_end_with_void_return (initial, NULL);
  35. gcc_jit_block_end_with_void_return (unreachable, NULL);
  36. }
  37. void
  38. verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
  39. {
  40. /* Ensure that the "unreachable blocks" validator was ignored. */
  41. CHECK_NON_NULL (result);
  42. }