clang.c 990 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "tests.h"
  3. #include "c++/clang-c.h"
  4. #include <linux/kernel.h>
  5. static struct {
  6. int (*func)(void);
  7. const char *desc;
  8. } clang_testcase_table[] = {
  9. #ifdef HAVE_LIBCLANGLLVM_SUPPORT
  10. {
  11. .func = test__clang_to_IR,
  12. .desc = "builtin clang compile C source to IR",
  13. },
  14. {
  15. .func = test__clang_to_obj,
  16. .desc = "builtin clang compile C source to ELF object",
  17. },
  18. #endif
  19. };
  20. int test__clang_subtest_get_nr(void)
  21. {
  22. return (int)ARRAY_SIZE(clang_testcase_table);
  23. }
  24. const char *test__clang_subtest_get_desc(int i)
  25. {
  26. if (i < 0 || i >= (int)ARRAY_SIZE(clang_testcase_table))
  27. return NULL;
  28. return clang_testcase_table[i].desc;
  29. }
  30. #ifndef HAVE_LIBCLANGLLVM_SUPPORT
  31. int test__clang(struct test *test __maybe_unused, int i __maybe_unused)
  32. {
  33. return TEST_SKIP;
  34. }
  35. #else
  36. int test__clang(struct test *test __maybe_unused, int i)
  37. {
  38. if (i < 0 || i >= (int)ARRAY_SIZE(clang_testcase_table))
  39. return TEST_FAIL;
  40. return clang_testcase_table[i].func();
  41. }
  42. #endif