test-error-block-in-wrong-function.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. goto label;
  14. }
  15. void
  16. other_fn ()
  17. {
  18. label:
  19. };
  20. where the destination block is in another function.
  21. */
  22. gcc_jit_type *void_t =
  23. gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
  24. /* Build the test_fn. */
  25. gcc_jit_function *test_fn =
  26. gcc_jit_context_new_function (ctxt, NULL,
  27. GCC_JIT_FUNCTION_EXPORTED,
  28. void_t,
  29. "test_fn",
  30. 0, NULL,
  31. 0);
  32. /* Build the other_fn. */
  33. gcc_jit_function *other_fn =
  34. gcc_jit_context_new_function (ctxt, NULL,
  35. GCC_JIT_FUNCTION_EXPORTED,
  36. void_t,
  37. "other_fn",
  38. 0, NULL,
  39. 0);
  40. gcc_jit_block *initial =
  41. gcc_jit_function_new_block (test_fn, "initial");
  42. gcc_jit_block *block_within_other_fn =
  43. gcc_jit_function_new_block (other_fn, "block_within_other_fn");
  44. gcc_jit_block_end_with_jump (initial, NULL, block_within_other_fn);
  45. }
  46. void
  47. verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
  48. {
  49. CHECK_VALUE (result, NULL);
  50. CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
  51. "gcc_jit_block_end_with_jump:"
  52. " target block is not in same function:"
  53. " source block initial is in function test_fn"
  54. " whereas target block block_within_other_fn"
  55. " is in function other_fn");
  56. /* Example of a testcase in which the last error != first error. */
  57. CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt),
  58. "unterminated block in other_fn: block_within_other_fn");
  59. }