test-error-gcc_jit_block_end_with_switch-NULL-case.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.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. int
  11. test_switch (int x)
  12. {
  13. switch (x)
  14. {
  15. case x:
  16. return 3;
  17. default:
  18. return 10;
  19. }
  20. }
  21. and verify that we get a sane error about the non-const
  22. case.
  23. */
  24. gcc_jit_type *t_int =
  25. gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
  26. gcc_jit_type *return_type = t_int;
  27. gcc_jit_param *x =
  28. gcc_jit_context_new_param (ctxt, NULL, t_int, "x");
  29. gcc_jit_param *params[1] = {x};
  30. gcc_jit_function *func =
  31. gcc_jit_context_new_function (ctxt, NULL,
  32. GCC_JIT_FUNCTION_EXPORTED,
  33. return_type,
  34. "test_switch",
  35. 1, params, 0);
  36. gcc_jit_block *b_initial =
  37. gcc_jit_function_new_block (func, "initial");
  38. gcc_jit_block *b_default =
  39. gcc_jit_function_new_block (func, "default");
  40. gcc_jit_case *cases[1] = {
  41. NULL
  42. };
  43. gcc_jit_block_end_with_switch (
  44. b_initial, NULL,
  45. gcc_jit_param_as_rvalue (x),
  46. b_default,
  47. 1,
  48. cases);
  49. }
  50. void
  51. verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
  52. {
  53. CHECK_VALUE (result, NULL);
  54. CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
  55. "gcc_jit_block_end_with_switch: NULL case 0");
  56. }