010-llvm15.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. From 0544c547682b878758eea731ef4b8e64e5ec91fb Mon Sep 17 00:00:00 2001
  2. From: Luc Van Oostenryck <[email protected]>
  3. Date: Sat, 20 Jan 2024 01:24:12 +0100
  4. Subject: llvm: fix LLVM 15 deprecation warnings
  5. LLVM 15 switched to opaque pointers by default and no longer supports typed pointers.
  6. Remove deprecated LLVM calls and update test.
  7. Original-patch-by: Vladimir Petko <[email protected]>
  8. Signed-off-by: Luc Van Oostenryck <[email protected]>
  9. ---
  10. sparse-llvm.c | 35 ++++++++++++++++++++++++++++++++++-
  11. validation/backend/call-variadic.c | 16 ++++------------
  12. 2 files changed, 38 insertions(+), 13 deletions(-)
  13. --- a/sparse-llvm.c
  14. +++ b/sparse-llvm.c
  15. @@ -32,6 +32,20 @@ static LLVMTypeRef func_return_type(stru
  16. return symbol_type(sym->ctype.base_type);
  17. }
  18. +#if LLVM_VERSION_MAJOR > 14
  19. +// A call can be done either with a SYM_FN or a SYM_PTR (pointing to a SYM_FN).
  20. +// Return the type corresponding to the SYM_FN.
  21. +static LLVMTypeRef func_full_type(struct symbol *type)
  22. +{
  23. + if (type->type == SYM_NODE) {
  24. + struct symbol *btype = type->ctype.base_type;
  25. + if (btype->type == SYM_PTR)
  26. + type = btype->ctype.base_type;
  27. + }
  28. + return symbol_type(type);
  29. +}
  30. +#endif
  31. +
  32. static LLVMTypeRef sym_func_type(struct symbol *sym)
  33. {
  34. int n_arg = symbol_list_size(sym->arguments);
  35. @@ -302,7 +316,11 @@ static LLVMValueRef get_sym_value(LLVMMo
  36. LLVMSetGlobalConstant(data, 1);
  37. LLVMSetInitializer(data, LLVMConstString(strdup(s), strlen(s) + 1, true));
  38. +#if LLVM_VERSION_MAJOR > 14
  39. + result = LLVMConstGEP2(LLVMTypeOf(data), data, indices, ARRAY_SIZE(indices));
  40. +#else
  41. result = LLVMConstGEP(data, indices, ARRAY_SIZE(indices));
  42. +#endif
  43. return result;
  44. }
  45. default:
  46. @@ -485,7 +503,11 @@ static LLVMValueRef calc_gep(LLVMBuilder
  47. /* convert base to char* type */
  48. base = LLVMBuildPointerCast(builder, base, bytep, name);
  49. /* addr = base + off */
  50. +#if LLVM_VERSION_MAJOR > 14
  51. + addr = LLVMBuildInBoundsGEP2(builder, LLVMTypeOf(base), base, &off, 1, name);
  52. +#else
  53. addr = LLVMBuildInBoundsGEP(builder, base, &off, 1, name);
  54. +#endif
  55. /* convert back to the actual pointer type */
  56. addr = LLVMBuildPointerCast(builder, addr, type, name);
  57. return addr;
  58. @@ -711,7 +733,11 @@ static void output_op_load(struct functi
  59. /* perform load */
  60. pseudo_name(insn->target, name);
  61. +#if LLVM_VERSION_MAJOR > 14
  62. + target = LLVMBuildLoad2(fn->builder, symbol_type(insn->type), addr, name);
  63. +#else
  64. target = LLVMBuildLoad(fn->builder, addr, name);
  65. +#endif
  66. insn->target->priv = target;
  67. }
  68. @@ -797,6 +823,7 @@ static void output_op_switch(struct func
  69. static void output_op_call(struct function *fn, struct instruction *insn)
  70. {
  71. LLVMValueRef target, func;
  72. + struct symbol *fntype;
  73. struct symbol *ctype;
  74. int n_arg = 0, i;
  75. struct pseudo *arg;
  76. @@ -812,14 +839,20 @@ static void output_op_call(struct functi
  77. else
  78. func = pseudo_to_value(fn, ctype, insn->func);
  79. i = 0;
  80. + fntype = ctype; // first symbol in the list is the function 'true' type
  81. FOR_EACH_PTR(insn->arguments, arg) {
  82. - NEXT_PTR_LIST(ctype);
  83. + NEXT_PTR_LIST(ctype); // the remaining ones are the arguments' type
  84. args[i++] = pseudo_to_rvalue(fn, ctype, arg);
  85. } END_FOR_EACH_PTR(arg);
  86. FINISH_PTR_LIST(ctype);
  87. pseudo_name(insn->target, name);
  88. +#if LLVM_VERSION_MAJOR > 14
  89. + target = LLVMBuildCall2(fn->builder, func_full_type(fntype), func, args, n_arg, name);
  90. +#else
  91. + (void) fntype;
  92. target = LLVMBuildCall(fn->builder, func, args, n_arg, name);
  93. +#endif
  94. insn->target->priv = target;
  95. }
  96. --- a/validation/backend/call-variadic.c
  97. +++ b/validation/backend/call-variadic.c
  98. @@ -11,17 +11,9 @@ int foo(const char *fmt, int a, long l,
  99. /*
  100. * check-name: call-variadic
  101. * check-command: sparse-llvm-dis -m64 $file
  102. + * check-output-ignore
  103. + * check-output-contains: , ...) @print(\\(i8\\*\\|ptr\\) %ARG1., i32 120, i32 %ARG2., i32 8, i64 %ARG3., i64 0, \\(i32\\*\\|ptr\\) %ARG4., \\(i8\\*\\|ptr\\) null)
  104. + * check-output-contains: define i32 @foo(
  105. + * check-output-contains: declare i32 @print(
  106. *
  107. - * check-output-start
  108. -; ModuleID = '<stdin>'
  109. -source_filename = "sparse"
  110. -
  111. -define i32 @foo(i8* %ARG1., i32 %ARG2., i64 %ARG3., i32* %ARG4.) {
  112. -L0:
  113. - %R5. = call i32 (i8*, ...) @print(i8* %ARG1., i32 120, i32 %ARG2., i32 8, i64 %ARG3., i64 0, i32* %ARG4., i8* null)
  114. - ret i32 %R5.
  115. -}
  116. -
  117. -declare i32 @print(i8*, ...)
  118. - * check-output-end
  119. */