clang.c 1.0 KB

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