[PATCH] D82932: [BPF] Fix a bug for __builtin_preserve_field_info() processing

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 30 22:43:08 PDT 2020


yonghong-song created this revision.
yonghong-song added reviewers: ast, anakryiko.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Andrii discovered a problem where a simple case similar to below
will generate wrong relocation kind:

  enum { FIELD_EXISTENCE = 2, };
  struct s1 { int a1; };
  int test() {
    struct s1 *v = 0;
    return __builtin_preserve_field_info(v[0], FIELD_EXISTENCE);
  }

The expected relocation kind should be FIELD_EXISTENCE, but 
recorded reloc kind in the final object file is FIELD_BYTE_OFFSET,
which is incorrect.

This exposed a bug in generating access strings from intrinsics.
The current access string generation has two steps:

  step 1: find the base struct/union type,
  step 2: traverse members in the base type.

The current implementation relies on at lease one member access
in step 2 to get the correct relocation kind, which is true
in typical cases. But if there is no member accesses, the current
implementation falls to the default info kind FIELD_BYTE_OFFSET.
This is incorrect, we should still record the reloc kind
based on the user input. This patch fixed this issue by properly
recording the reloc kind in such cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82932

Files:
  llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
  llvm/test/CodeGen/BPF/CORE/intrinsic-array-2.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82932.274686.patch
Type: text/x-patch
Size: 5536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200701/c00bd7ea/attachment.bin>


More information about the llvm-commits mailing list