[ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types
authorHubert Tong <hubert.reinterpretcast@gmail.com>
Wed, 12 Dec 2018 16:53:43 +0000 (16:53 +0000)
committerHubert Tong <hubert.reinterpretcast@gmail.com>
Wed, 12 Dec 2018 16:53:43 +0000 (16:53 +0000)
commit147b743602e480845d9ae10ccd35977070614e5a
tree5acfa2ea1d55084bb50a18ad37ff4039f8f48a0a
parent76504a4c5e196aac50afe65f1db55345b9a01b7e
[ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types

Summary:
`memchr` and `memcmp` operate upon the character units of the object
representation; that is, the `size_t` parameter expresses the number of
character units. The constant folding implementation is updated in this
patch to account for multibyte element types in the arrays passed to
`memchr`/`memcmp` and, in the case of `memcmp`, to account for the
possibility that the arrays may have differing element types (even when
they are byte-sized).

Actual inspection of the object representation is not implemented.
Comparisons are done only between elements with the same object size;
that is, `memchr` will fail when inspecting at least one character unit
of a multibyte element. The integer types are assumed to have two's
complement representation with 0 for `false`, 1 for `true`, and no
padding bits.

`memcmp` on multibyte elements will only be able to fold in cases where
enough elements are equal for the answer to be 0.

Various tests are added to guard against incorrect folding for cases
that miscompile on some system or other prior to this patch. At the same
time, the unsigned 32-bit `wchar_t` testing in
`test/SemaCXX/constexpr-string.cpp` is restored.

Reviewers: rsmith, aaron.ballman, hfinkel

Reviewed By: rsmith

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D55510

llvm-svn: 348938
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constexpr-string.cpp