mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-20 03:23:01 +02:00
[BPF] Generate array dimension size properly for zero-size elements
Currently, if an array element type size is 0, the number of array elements will be set to 0, regardless of what user specified. This implementation is done in the beginning where BTF is mostly used to calculate the member offset. For example, struct s {}; struct s1 { int b; struct s a[2]; }; struct s1 s1; The BTF will have struct "s1" member "a" with element count 0. Now BTF types are used for compile-once and run-everywhere relocations and we need more precise type representation for type comparison. Andrii reported the issue as there are differences between original structure and BTF-generated structure. This patch made the change to correctly assign "2" as the number elements of member "a". Some dead codes related to ElemSize compuation are also removed. Differential Revision: https://reviews.llvm.org/D67979 llvm-svn: 372785
This commit is contained in:
parent
5a01f5b084
commit
3cc43e7b0b
@ -473,17 +473,10 @@ void BTFDebug::visitStructType(const DICompositeType *CTy, bool IsStruct,
|
||||
|
||||
void BTFDebug::visitArrayType(const DICompositeType *CTy, uint32_t &TypeId) {
|
||||
// Visit array element type.
|
||||
uint32_t ElemTypeId, ElemSize;
|
||||
uint32_t ElemTypeId;
|
||||
const DIType *ElemType = CTy->getBaseType();
|
||||
visitTypeEntry(ElemType, ElemTypeId, false, false);
|
||||
|
||||
// Strip qualifiers from element type to get accurate element size.
|
||||
ElemSize = ElemType->getSizeInBits() >> 3;
|
||||
|
||||
if (!CTy->getSizeInBits()) {
|
||||
auto TypeEntry = std::make_unique<BTFTypeArray>(ElemTypeId, 0);
|
||||
ElemTypeId = addType(std::move(TypeEntry), CTy);
|
||||
} else {
|
||||
// Visit array dimensions.
|
||||
DINodeArray Elements = CTy->getElements();
|
||||
for (int I = Elements.size() - 1; I >= 0; --I) {
|
||||
@ -493,14 +486,15 @@ void BTFDebug::visitArrayType(const DICompositeType *CTy, uint32_t &TypeId) {
|
||||
auto *CI = SR->getCount().dyn_cast<ConstantInt *>();
|
||||
int64_t Count = CI->getSExtValue();
|
||||
|
||||
// For struct s { int b; char c[]; }, the c[] will be represented
|
||||
// as an array with Count = -1.
|
||||
auto TypeEntry =
|
||||
std::make_unique<BTFTypeArray>(ElemTypeId, Count);
|
||||
std::make_unique<BTFTypeArray>(ElemTypeId,
|
||||
Count >= 0 ? Count : 0);
|
||||
if (I == 0)
|
||||
ElemTypeId = addType(std::move(TypeEntry), CTy);
|
||||
else
|
||||
ElemTypeId = addType(std::move(TypeEntry));
|
||||
ElemSize = ElemSize * Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
; CHECK-NEXT: .long 0
|
||||
; CHECK-NEXT: .long 1
|
||||
; CHECK-NEXT: .long 3
|
||||
; CHECK-NEXT: .long 0
|
||||
; CHECK-NEXT: .long 10
|
||||
; CHECK-NEXT: .long 3 # BTF_KIND_INT(id = 3)
|
||||
; CHECK-NEXT: .long 16777216 # 0x1000000
|
||||
; CHECK-NEXT: .long 4
|
||||
|
Loading…
Reference in New Issue
Block a user