pfunct: Generate a valid return type for the --compile bodies

Before:

  $ pfunct --compile examples/tcp.o > tcp.pahole.c
  $ clang --target=bpf -c -g tcp.pahole.c |& tail
  tcp.pahole.c:6154:1: warning: control reaches end of non-void function [-Wreturn-type]
  }
  ^
  tcp.pahole.c:6158:1: warning: control reaches end of non-void function [-Wreturn-type]
  }
  ^
  tcp.pahole.c:6170:1: warning: control reaches end of non-void function [-Wreturn-type]
  }
  ^
  192 warnings generated.
  $ head -6170 tcp.pahole.c | tail -3
  inline int arch_atomic_read(const atomic_t  * v)
  {
  }
  $

After:

  $ pfunct --compile examples/tcp.o > tcp.pahole.c
  $ clang --target=bpf -c -g tcp.pahole.c
  $ grep -A3 -w arch_atomic_read tcp.pahole.c
  inline int arch_atomic_read(const atomic_t  * v)
  {
	  return 0;
  }
  $

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2019-04-05 16:33:43 -03:00
parent 881aabd6fc
commit 99750f244c
1 changed files with 14 additions and 2 deletions

View File

@ -361,8 +361,20 @@ static void function__show(struct function *func, struct cu *cu)
if (expand_types)
function__emit_type_definitions(func, cu, stdout);
tag__fprintf(tag, cu, &conf, stdout);
if (compilable_output)
fprintf(stdout, "\n{\n}\n");
if (compilable_output) {
struct tag *type = tag__strip_typedefs_and_modifiers(&func->proto.tag, cu);
fprintf(stdout, "\n{");
if (type != NULL) { /* NULL == void */
if (tag__is_pointer(type))
fprintf(stdout, "\n\treturn (void *)0;");
else if (tag__is_struct(type))
fprintf(stdout, "\n\treturn *(struct %s *)1;", class__name(tag__class(type), cu));
else
fprintf(stdout, "\n\treturn 0;");
}
fprintf(stdout, "\n}\n");
}
putchar('\n');
if (show_variables || show_inline_expansions)
function__fprintf_stats(tag, cu, &conf, stdout);