Blame SOURCES/bcc-0.25.0-Fix-clang-15-int-to-pointer-conversion-errors.patch

6fc629
From f5a6c22f613d0566ba542f38f349be379e3844e8 Mon Sep 17 00:00:00 2001
6fc629
From: Jerome Marchand <jmarchan@redhat.com>
6fc629
Date: Wed, 26 Oct 2022 14:41:54 +0200
6fc629
Subject: [PATCH 2/2] Fix clang 15 int to pointer conversion errors
6fc629
6fc629
Since version 15, clang issues error for implicit conversion of
6fc629
integer to pointer. Several tools are broken. This patch add explicit
6fc629
pointer cast where needed.
6fc629
6fc629
Fixes the following errors:
6fc629
/virtual/main.c:37:18: error: incompatible integer to pointer conversion initializing 'struct request *' with an expression of type 'unsigned long' [-Wint-conversion]
6fc629
 struct request *req = ctx->di;
6fc629
                 ^     ~~~~~~~
6fc629
/virtual/main.c:49:18: error: incompatible integer to pointer conversion initializing 'struct request *' with an expression of type 'unsigned long' [-Wint-conversion]
6fc629
 struct request *req = ctx->di;
6fc629
                 ^     ~~~~~~~
6fc629
2 errors generated.
6fc629
6fc629
/virtual/main.c:73:19: error: incompatible integer to pointer conversion initializing 'struct pt_regs *' with an expression of type 'unsigned long' [-Wint-conversion]
6fc629
 struct pt_regs * __ctx = ctx->di;
6fc629
                  ^       ~~~~~~~
6fc629
/virtual/main.c:100:240: error: incompatible integer to pointer conversion passing 'u64' (aka 'unsigned long long') to parameter of type 'const void *' [-Wint-conversion]
6fc629
    data.ppid = ({ typeof(pid_t) _val; __builtin_memset(&_val, 0, sizeof(_val)); bpf_probe_read(&_val, sizeof(_val), (u64)&({ typeof(struct task_struct *) _val; __builtin_memset(&_val, 0, sizeof(_val)); bpf_probe_read(&_val, sizeof(_val), (u64)&task->real_parent); _val; })->tgid); _val; });
6fc629
                                                                                                                                                                                                                                               ^~~~~~~~~~~~~~~~~~~~~~~
6fc629
/virtual/main.c:100:118: error: incompatible integer to pointer conversion passing 'u64' (aka 'unsigned long long') to parameter of type 'const void *' [-Wint-conversion]
6fc629
    data.ppid = ({ typeof(pid_t) _val; __builtin_memset(&_val, 0, sizeof(_val)); bpf_probe_read(&_val, sizeof(_val), (u64)&({ typeof(struct task_struct *) _val; __builtin_memset(&_val, 0, sizeof(_val)); bpf_probe_read(&_val, sizeof(_val), (u64)&task->real_parent); _val; })->tgid); _val; });
6fc629
                                                                                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6fc629
6fc629
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
6fc629
---
6fc629
 src/cc/frontends/clang/b_frontend_action.cc | 18 +++++++++---------
6fc629
 1 file changed, 9 insertions(+), 9 deletions(-)
6fc629
6fc629
diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc
6fc629
index dbeba3e4..c0582464 100644
6fc629
--- a/src/cc/frontends/clang/b_frontend_action.cc
6fc629
+++ b/src/cc/frontends/clang/b_frontend_action.cc
6fc629
@@ -517,9 +517,9 @@ bool ProbeVisitor::VisitUnaryOperator(UnaryOperator *E) {
6fc629
   string pre, post;
6fc629
   pre = "({ typeof(" + E->getType().getAsString() + ") _val; __builtin_memset(&_val, 0, sizeof(_val));";
6fc629
   if (cannot_fall_back_safely)
6fc629
-    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (u64)";
6fc629
+    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (void *)";
6fc629
   else
6fc629
-    pre += " bpf_probe_read(&_val, sizeof(_val), (u64)";
6fc629
+    pre += " bpf_probe_read(&_val, sizeof(_val), (void *)";
6fc629
   post = "); _val; })";
6fc629
   rewriter_.ReplaceText(expansionLoc(E->getOperatorLoc()), 1, pre);
6fc629
   rewriter_.InsertTextAfterToken(expansionLoc(GET_ENDLOC(sub)), post);
6fc629
@@ -581,9 +581,9 @@ bool ProbeVisitor::VisitMemberExpr(MemberExpr *E) {
6fc629
   string pre, post;
6fc629
   pre = "({ typeof(" + E->getType().getAsString() + ") _val; __builtin_memset(&_val, 0, sizeof(_val));";
6fc629
   if (cannot_fall_back_safely)
6fc629
-    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (u64)&";
6fc629
+    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (void *)&";
6fc629
   else
6fc629
-    pre += " bpf_probe_read(&_val, sizeof(_val), (u64)&";
6fc629
+    pre += " bpf_probe_read(&_val, sizeof(_val), (void *)&";
6fc629
   post = rhs + "); _val; })";
6fc629
   rewriter_.InsertText(expansionLoc(GET_BEGINLOC(E)), pre);
6fc629
   rewriter_.ReplaceText(expansionRange(SourceRange(member, GET_ENDLOC(E))), post);
6fc629
@@ -635,9 +635,9 @@ bool ProbeVisitor::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
6fc629
 
6fc629
   pre = "({ typeof(" + E->getType().getAsString() + ") _val; __builtin_memset(&_val, 0, sizeof(_val));";
6fc629
   if (cannot_fall_back_safely)
6fc629
-    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (u64)((";
6fc629
+    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (void *)((";
6fc629
   else
6fc629
-    pre += " bpf_probe_read(&_val, sizeof(_val), (u64)((";
6fc629
+    pre += " bpf_probe_read(&_val, sizeof(_val), (void *)((";
6fc629
   if (isMemberDereference(base)) {
6fc629
     pre += "&";
6fc629
     // If the base of the array subscript is a member dereference, we'll rewrite
6fc629
@@ -747,8 +747,8 @@ void BTypeVisitor::genParamDirectAssign(FunctionDecl *D, string& preamble,
6fc629
       arg->addAttr(UnavailableAttr::CreateImplicit(C, "ptregs"));
6fc629
       size_t d = idx - 1;
6fc629
       const char *reg = calling_conv_regs[d];
6fc629
-      preamble += " " + text + " = " + fn_args_[0]->getName().str() + "->" +
6fc629
-                  string(reg) + ";";
6fc629
+      preamble += " " + text + " = (" + arg->getType().getAsString() + ")" +
6fc629
+                  fn_args_[0]->getName().str() + "->" + string(reg) + ";";
6fc629
     }
6fc629
   }
6fc629
 }
6fc629
@@ -762,7 +762,7 @@ void BTypeVisitor::genParamIndirectAssign(FunctionDecl *D, string& preamble,
6fc629
 
6fc629
     if (idx == 0) {
6fc629
       new_ctx = "__" + arg->getName().str();
6fc629
-      preamble += " struct pt_regs * " + new_ctx + " = " +
6fc629
+      preamble += " struct pt_regs * " + new_ctx + " = (void *)" +
6fc629
                   arg->getName().str() + "->" +
6fc629
                   string(calling_conv_regs[0]) + ";";
6fc629
     } else {
6fc629
-- 
6fc629
2.38.1
6fc629