test-error-missing-return.c 879 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "libgccjit.h"
  4. #include "harness.h"
  5. void
  6. create_code (gcc_jit_context *ctxt, void *user_data)
  7. {
  8. /* Let's try to inject the equivalent of:
  9. int
  10. test_fn ()
  11. {
  12. }
  13. and verify that the API complains about the lack of
  14. a returned value.
  15. */
  16. gcc_jit_type *int_type =
  17. gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
  18. (void)gcc_jit_context_new_function (ctxt, NULL,
  19. GCC_JIT_FUNCTION_EXPORTED,
  20. int_type,
  21. "test_fn",
  22. 0, NULL,
  23. 0);
  24. }
  25. void
  26. verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
  27. {
  28. CHECK_VALUE (result, NULL);
  29. /* Verify that the correct error message was emitted. */
  30. CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
  31. "function test_fn returns non-void (type: int)"
  32. " but has no blocks");
  33. }