-
Notifications
You must be signed in to change notification settings - Fork 11.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NVPTX] Global of unaligned vector types cause assertion errors and buffer overflows #59179
Comments
I think the problem is here (https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp#L1817-L1823): size_t NumBytes = (Val.getBitWidth() + 7) / 8;
SmallVector<unsigned char, 16> Buf(NumBytes);
for (unsigned I = 0; I < NumBytes; ++I) {
Buf[I] = Val.extractBitsAsZExtValue(8, I * 8);
} We calculate how many bytes the value contains (rounding up), so I can work on this if someone can tell me what the expected behavior is :) |
Thanks for the analysis. If that is correct root cause, you can fix it with one line of code. |
@Artem-B @junaire After some digging I found the root cause of the crash, but I need some help fixing it. In short, the size of llvm-project/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Lines 1822 to 1829 in 8abd700
This difference is the root cause of the problem. |
Hi, I actually tried this before (squash all bits into the |
Caveat: I didn't look into the details yet, will do once I'm back at work. The stuff below are my general thoughts on this. Non-power-of-2 sized integers (let's call them PO2) are not handled particularly well in NVPTX in general. I vaguely recall that we promote scalars up to the next PO2 size, but vectors of such oddly-sized integers are likely to have problems, as you've discovered.
That's not a very strong argument.
What to do:
TBH, I'm not even quite sure what would be the right way to store such a vector in memory.
How does x64 deal with this? One of the implicit assumptions NVPTX users rely on in practice is that in-memory layout matches that of the host and the host sort of happens to be |
Description
When targeting
nvptx
ornvptx64
, the following code containing v16i20 global crashes backend withbitPosition < BitWidth && (numBits + bitPosition) <= BitWidth && "Illegal bit extraction"
failed during passNVPTX Assembly Printer
in debug build;corrupted size vs. prev_size
duringmalloc
in release build.The problem does not exist when targeting
x86_64
,aarch64
,riscv64
, orwasm64
.Minimal Reproduction
https://godbolt.org/z/jnaqz5qq3
Code
Stack Trace (Debug)
Stack Trace (Release)
The text was updated successfully, but these errors were encountered: