[PATCH] D55510: [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types

Hubert Tong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 10 06:29:08 PST 2018


hubert.reinterpretcast created this revision.
hubert.reinterpretcast added reviewers: rsmith, aaron.ballman, hfinkel.

`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.

CodeGen tests are added for cases that miscompile on some system or other prior to this patch.


Repository:
  rC Clang

https://reviews.llvm.org/D55510

Files:
  include/clang/Basic/DiagnosticASTKinds.td
  lib/AST/ExprConstant.cpp
  test/CodeGenCXX/builtins.cpp
  test/SemaCXX/constexpr-string.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55510.177498.patch
Type: text/x-patch
Size: 18512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181210/5553293c/attachment-0001.bin>


More information about the cfe-commits mailing list