https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103964
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Ilya Maximets from comment #5) > (In reply to Richard Biener from comment #4) > > the IVOPTs reference is likely due to the fact that while IVOPTs uses > > uintptrs to create the base pointer the TARGET_MEM_REF contained arithmetic > > itself is still considered pointer arithmetic (like also here the embedded > > MEM_REF pointer offsetting) and the base "pointer" cannot be a non-pointer > > to disable that behavior. > > Does this mean that this is UB and the GCC itself relies on a certain result > of it? If GCC through optimizations introduces UB in a code which wasn't there in the user's code, then it would be a GCC bug and something the compiler needs to fix. > Maybe there is a way to not treat a &pos->elem as a pointer arithmetic? > Maybe there should be one? I mean, compilers allows users to perform > computations with offsets of structure fields where the base pointer > is NULL, and NULL obviously doesn't point to any valid object. I'm not > sure if it's an UB or not, but constructions like '&((struct s > *)NULL)->field' > are very common. &((struct s *)NULL)->field is not valid in C or C++, but for many years the offsetof macro which is valid in those has been defined like that and various projects occassionally still use the above, so GCC supports those as an extension (poor man's offsetof). See e.g. spots with comments like Cope with user tricks that amount to offsetof. etc. in GCC sources. That doesn't change anything about this case, the poor man's offsetof is folded into a constant very early (well, with variable offsets in array refs in there could also into an expression, but still integral expression, the pointer arithmetics is gone from there). What is the reason why OVS (and kernel) doesn't use 2 variables, one for the iterator that is a pointer to the prev/next structure only and one assigned e.g. in the condition from the iterator that is used only when it isn't the start? At least if targetting C99 and above (or C++) one can declare one of those iterators in the for loop init expression...