Skip to content

Alive fails to typecheck valid LLVM program with struct padding #1328

Description

@Benjins

Minimal repro:

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define { i1, i64, i1, i64 } @f0() {
  %r0 = insertvalue { i1, i64, i1, i64 } poison, i64 0, 3
  ret { i1, i64, i1, i64 } %r0
}

https://alive2.llvm.org/ce/z/TJMAvb

The error it gives:

Transformation doesn't verify!
ERROR: program doesn't type check!

It looks like the error may be in this code:

alive2/ir/type.cpp

Lines 818 to 823 in 1d1bc4f

unsigned AggregateType::countPaddings(unsigned to_idx) const {
unsigned count = 0;
for (unsigned i = 0; i <= to_idx; ++i)
count += is_padding[i];
return count;
}

In its calling code, it seems like to_idx is the field index from LLVM, so w/o explicit padding included. But, we only count padding up to to_idx total fields (real or padding), so we end up undercounting the padding

for (auto idx : i.indices()) {
auto *aty = ty->getAsAggregateType();
unsigned idx_with_paddings = aty->countPaddings(idx) + idx;
inst->addIdx(idx_with_paddings);
ty = &aty->getChild(idx_with_paddings);
}

I have verified this repros on the latest master, 1d1bc4f

This code was minimised from an example generated by a fuzzer meant to test LLVM, rather than a real-world example

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions