When addresspacecast is generated resulting pointer should preserve TBAA information from original value.
Details
Diff Detail
Event Timeline
LGTM. Although this also fixes bugs with unaligned pointers that you might consider adding tests for.
The code was dropping all the original l-value information, which includes alignment. So if you start with an l-value that refers to under-aligned memory (or over-aligned), we were losing that information on the resulting l-value. The test case would be something like:
struct __attribute__((packed)) A { int x; }; int test(__global A *a) { return static_cast<__generic A &>(*a).x; // this load should have alignment 1 }
Oh, sorry, that wasn't a good example because that's still the natural alignment for A. It should be static_cast<__generic int &>(GPtr->X).
I'm getting the same IR for both examples you provided. And for both load of X value is aligned on 4 bytes wo patch and on 1 byte with.
That's odd, because the natural type alignment for A ought to be 1, since it's a packed type. What does the AST look like?
Sorry, I was compiling the first version two times.
With second example clang crashes :)
Oh! Yes, that's even more broken than I thought.
lib/CodeGen/CGExpr.cpp | ||
---|---|---|
4271–4272 | This call to getAddressSpace() doesn't look right: we just constructed DestTy as an unqualified pointer type. It needs to be E->getType().getAddressSpace(). |
Sorry. Can you post the result of passing -ast-dump instead of -emit-llvm to the compiler?
Actually, nevermind, I don't need that. If you can fix the address-space issue I pointed out, I think this is ready to go.
This call to getAddressSpace() doesn't look right: we just constructed DestTy as an unqualified pointer type. It needs to be E->getType().getAddressSpace().