[llvm-dev] Potentially unsafe loop optimization
Richard Kenner via llvm-dev
llvm-dev at lists.llvm.org
Thu Feb 18 05:13:46 PST 2021
> I think there is UB in the jump based on the memcmp because only
> one byte of the 3 is initialized. To me it seems there is some type
> punning going on and the two integers are used as storage for 3 bytes
> instead of the 3 bytes array. I thought this may lead to the
> selection of the abort branch and bad consequences. However, on
> the IR level we do not recognize abort as noreturn as far as I can tell,
> thus that is not it.
The larger test that this was from didn't have an abort there, but a
call to a procedure that printed an error message, so the abort isn't
fundamental to the issue. Because of this, I wasn't looking at the
comparison, which should have been defined. However, I don't see the
UB here. The code does look wrong, because the pointer pun for %0 and
%1 should have been a GEP for the second part of the structure (and
actually, the allocated variable shouldn't include the two integers),
but everything is done with %0 and %1: they're initialized to three
characters, the second character is replaced by the loop variable, and
the three characters are compared.
More information about the llvm-dev
mailing list