test-error-adding-to-terminated-block.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. */
  17. gcc_jit_type *void_t =
  18. gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
  19. /* Build the test_fn. */
  20. gcc_jit_function *test_fn =
  21. gcc_jit_context_new_function (ctxt, NULL,
  22. GCC_JIT_FUNCTION_EXPORTED,
  23. void_t,
  24. "test_fn",
  25. 0, NULL,
  26. 0);
  27. gcc_jit_block *initial =
  28. gcc_jit_function_new_block (test_fn, "initial");
  29. gcc_jit_block_end_with_void_return (initial, NULL);
  30. /* Error: "initial" has already been terminated. */
  31. gcc_jit_block_end_with_void_return (initial, NULL);
  32. }
  33. void
  34. verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
  35. {
  36. CHECK_VALUE (result, NULL);
  37. CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
  38. "gcc_jit_block_end_with_void_return:"
  39. " adding to terminated block:"
  40. " initial (already terminated by: return;)");
  41. }