5 ms·
c = pMem->flags; sqlite3VdbeMemRelease(pMem); pMem->flags = MEM_Str|MEM_Term|(c&(MEM_AffMask|MEM_Subtype)); 'pMem->flags' is a u16[1]. Shouldn't it
by fctorial 6y ago
c = pMem->flags;
sqlite3VdbeMemRelease(pMem);
pMem->flags = MEM_Str|MEM_Term|(c&(MEM_AffMask|MEM_Subtype));
'pMem->flags' is a u16[1]. Shouldn't it be copied to 'c'. How can 'sqlite3VdbeMemRelease' alter the value of 'c'.
[1]https://github.com/smparkes/sqlite/blob/8caf9219240123fbe6cff67b1e0da778c62d7621/src/vdbeInt.h#L148 https://github.com/smparkes/sqlite/blob/8caf9219240123fbe6cf...
- aidenn0 6y agopMem is a pointer; the contents of pMem will not be copied. [edit] I see what you're asking. The point is that the compiler changes: c = pMem->flags; sqlite3VdbeMemRelease(pMem); To something equivalent to: sqlite3VdbeMemRelease(pMem); c = pMem->flags; Which is correct only if sqlite3VdbMemRelease doesn't change pMem->flags
- bilalhusain 6y ago'sqlite3VdbeMemRelease' doesn't alter the value of 'c' but may alter the value of 'pmem->flags' which is what the compiler replaced 'c' with. from the post by Dr. Richard Hipp "From the -S output, it looks like Clang-11.0.0 is compiling these three lines as if there were written as:" sqlite3VdbeMemRelease(pMem); pMem->flags = MEM_Str|MEM_Term|(pMem->flags&(MEM_AffMask|MEM_Subtype));
- outsomnia 6y agoHe said >> Clang seems to be assuming that the sqlite3VdbeMemRelease() function does not change the value of pMem->flags.
- amake 6y agoIt doesn't. The compiler is moving the access to `pMem->flags` to come later in the sequence, after `pMem` has been modified by `sqlite3VdbeMemRelease`.
- raverbashing 6y agoYou're right. But for some reason, it's thinking it can just reread the flags from the structure after that function, which has a non-const pointer void sqlite3VdbeMemRelease(Mem *p); I'll be waiting for the excuses of the "C standard evangelists" and the extreme optimization people on how the SQLite developers are wrong on this case and how it's funny to pull the rug under them.
- saagarjha 6y agoLooks like an average compiler bug rather than malformed code?
- account42 6y ago> But for some reason, it's thinking it can just reread the flags from the structure after that function, which has a non-const pointer The pointer being const would not give the compiler any more guarantees that would allow it to reorder the read.