test-error-param-sharing.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "libgccjit.h"
  4. #include "harness.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. extern void
  9. called_function (void *ptr);
  10. #ifdef __cplusplus
  11. }
  12. #endif
  13. void
  14. create_code (gcc_jit_context *ctxt, void *user_data)
  15. {
  16. /* Verify that we get an error (rather than a crash)
  17. if the client code reuses a gcc_jit_param * for
  18. two different functions. */
  19. gcc_jit_type *void_type =
  20. gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
  21. gcc_jit_type *int_type =
  22. gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
  23. /* Create a param. */
  24. gcc_jit_param *param =
  25. gcc_jit_context_new_param (ctxt, NULL, int_type, "i");
  26. /* Try to use it for two different functions. */
  27. gcc_jit_context_new_function (ctxt, NULL,
  28. GCC_JIT_FUNCTION_EXPORTED,
  29. void_type,
  30. "fn_one",
  31. 1, &param,
  32. 0);
  33. gcc_jit_context_new_function (ctxt, NULL,
  34. GCC_JIT_FUNCTION_EXPORTED,
  35. void_type,
  36. "fn_two",
  37. 1, &param,
  38. 0);
  39. }
  40. void
  41. verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
  42. {
  43. CHECK_VALUE (result, NULL);
  44. /* Verify that the correct error message was emitted. */
  45. CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
  46. ("gcc_jit_context_new_function:"
  47. " parameter 0 \"i\" (type: int)"
  48. " for function fn_two"
  49. " was already used for function fn_one"))
  50. }