Re: [libcxx-dev] [clang] 4ede887 - PR45402: Make the restrictions on constant evaluation of memcmp and
On Sun, 5 Apr 2020 at 15:41, David Zarzycki via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Subjectively speaking, using char8_t instead of char shouldn’t feel like a > regression. So yes, making the builtin mem* functions work with char8_t > again seems right. As for strlen, I can see arguments either way. > Personally, if you’re concerned about clever macros, then I’d make the > overload only visible in C++20 mode where char8_t was introduced. > I don't think that solves the problem. For example, the glibc headers do clever things with __builtin_strlen (which they do, at least in some cases), then this may still result in miscompiles. Eg, consider: struct microseconds { operator const char*() { return "us"; } operator const char8_t*() { return "µs"; } }; char buffer[32]; strcpy(buffer, microseconds()); This should compile, but won't if the implementation of strcpy is a macro that calls __builtin_strlen (as it sometimes is with glibc). Worse would be if the char8_t conversion function is preferred over the char conversion function for some reason, where strcpy might expand to `memcpy(buffer, microseconds(), __builtin_strlen(microseconds()))`, potentially resulting in a buffer overflow (copying using the length of the char8_t string but the content of the char string). If we want to introduce a strlen builtin for char8_t, I think we should give it a different name. I've realized that my suggestion of using __builtin_memchr(p, 0) - p for strlen doesn't actually work, for the usual reason that memchr is mostly useless in constant expressions (because it returns a void*). So maybe we should add a __builtin_memchr_char8_t to parallel the existing __builtin_memchr_char, or maybe make __builtin_memchr_char overloaded on character type? -- > Sent from my iPhone > > On Apr 5, 2020, at 18:18, Richard Smith wrote: > > > On Sun, 5 Apr 2020 at 14:44, David Zarzycki via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> We have overloaded builtins. Can that not solve __builtin_strlen? >> > > I suppose it could, but we generally want __builtin_ to behave > the same as . (The difference would not be visible most of the > time, but there's enough pre-existing use of __builtin_strlen through > "clever" macros and the like that I'd be worried that this would break > something important.) Maybe we should just make the mem* functions work > again for char8_t; then you can use __builtin_memchr(p, 0) - p as an > optimized compile-time strlen. > > >> -- >> Sent from my iPhone >> >> On Apr 5, 2020, at 14:53, Richard Smith wrote: >> >> >> Thanks. We need to figure out what the right way to support char8_t with >> string builtins is. These ones could work in principle, whereas things like >> __builtin_strlen would never work because they take operands of the wrong >> types (and we can't cast const char8_t* -> const char* in a constant >> expression). >> >> On Sun, 5 Apr 2020 at 04:14, David Zarzycki via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> >>> Hi Richard, >>> >>> I'm going to commit a narrow fix to clang to make the libcxx test suite >>> pass again by allowing char8_t again. If you feel that this is the wrong >>> long-term solution, please help the libcxx folks with whatever adjustments >>> they need. >>> >>> Thanks! >>> >>> Dave >>> >>> >>> On Sat, Apr 4, 2020, at 9:55 AM, David Zarzycki via libcxx-dev wrote: >>> > Hi Richard, >>> > >>> > This breaks libcxx. Can we please revert this or is a quick fix to >>> > libcxx possible? >>> > >>> > >>> > FAIL: libc++ :: >>> > >>> std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp >>> (58624 of 62672) >>> > TEST 'libc++ :: >>> > >>> std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp' >>> FAILED >>> > Command: ['/p/tllvm/bin/clang++', '-o', >>> > >>> '/tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o', >>> '-x', 'c++', >>> '/home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp', >>> '-c', '-v', '-Werror=thread-safety', '-std=c++2a', '-include', >>> '/home/dave/s/lp/libcxx/test/support/nasty_macros.h', '-nostdinc++', >>> '-I/home/dave/s/lp/libcxx/include', >>> '-I/tmp/_update_lc/t/projects/libcxx/include/c++build', >>> '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', >>> '-D__STDC_CONSTANT_MACROS', '-I/home/dave/s/lp/libcxx/test/support', >>> '-ftemplate-depth=270', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-Wall', >>> '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', >>> '-Wno-unused-command-line-argument', '-Wno-attributes', >>> '-Wno-pessimizing-move', '-Wno-c++11-extensions', >>> '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', >>> '-Wunused-variable', '-Wunused-parameter', '-Wunrea
Re: [libcxx-dev] [clang] 4ede887 - PR45402: Make the restrictions on constant evaluation of memcmp and
Subjectively speaking, using char8_t instead of char shouldn’t feel like a regression. So yes, making the builtin mem* functions work with char8_t again seems right. As for strlen, I can see arguments either way. Personally, if you’re concerned about clever macros, then I’d make the overload only visible in C++20 mode where char8_t was introduced. -- Sent from my iPhone > On Apr 5, 2020, at 18:18, Richard Smith wrote: > > >> On Sun, 5 Apr 2020 at 14:44, David Zarzycki via cfe-commits >> wrote: > >> We have overloaded builtins. Can that not solve __builtin_strlen? > > I suppose it could, but we generally want __builtin_ to behave the > same as . (The difference would not be visible most of the time, but > there's enough pre-existing use of __builtin_strlen through "clever" macros > and the like that I'd be worried that this would break something important.) > Maybe we should just make the mem* functions work again for char8_t; then you > can use __builtin_memchr(p, 0) - p as an optimized compile-time strlen. > >> -- >> Sent from my iPhone >> On Apr 5, 2020, at 14:53, Richard Smith wrote: >>> >>> Thanks. We need to figure out what the right way to support char8_t with >>> string builtins is. These ones could work in principle, whereas things like >>> __builtin_strlen would never work because they take operands of the wrong >>> types (and we can't cast const char8_t* -> const char* in a constant >>> expression). >>> On Sun, 5 Apr 2020 at 04:14, David Zarzycki via cfe-commits wrote: Hi Richard, I'm going to commit a narrow fix to clang to make the libcxx test suite pass again by allowing char8_t again. If you feel that this is the wrong long-term solution, please help the libcxx folks with whatever adjustments they need. Thanks! Dave On Sat, Apr 4, 2020, at 9:55 AM, David Zarzycki via libcxx-dev wrote: > Hi Richard, > > This breaks libcxx. Can we please revert this or is a quick fix to > libcxx possible? > > > FAIL: libc++ :: > std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp > (58624 of 62672) > TEST 'libc++ :: > std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp' > FAILED > Command: ['/p/tllvm/bin/clang++', '-o', > '/tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o', > '-x', 'c++', > '/home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp', > '-c', '-v', '-Werror=thread-safety', '-std=c++2a', '-include', > '/home/dave/s/lp/libcxx/test/support/nasty_macros.h', '-nostdinc++', > '-I/home/dave/s/lp/libcxx/include', > '-I/tmp/_update_lc/t/projects/libcxx/include/c++build', > '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', > '-D__STDC_CONSTANT_MACROS', '-I/home/dave/s/lp/libcxx/test/support', > '-ftemplate-depth=270', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', > '-Wall', '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', > '-Wno-unused-command-line-argument', '-Wno-attributes', > '-Wno-pessimizing-move', '-Wno-c++11-extensions', > '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', > '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-c'] > Exit Code: 1 > Standard Error: > -- > clang version 11.0.0 (https://github.com/llvm/llvm-project.git > 22127da8f17c03c69231f3631472f7f99ad9cb7f) > Target: x86_64-unknown-linux-gnu > Thread model: posix > InstalledDir: /p/tllvm/bin > Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 > Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 > Candidate multilib: .;@m64 > Candidate multilib: 32;@m32 > Selected multilib: .;@m64 > (in-process) > "/p/tllvm/bin/clang-11" -cc1 -triple x86_64-unknown-linux-gnu > -emit-obj -mrelax-all -disable-free -disable-llvm-verifier > -discard-value-names -main-file-name compare.pass.cpp > -mrelocation-model static -mthread-model posix -mframe-pointer=all > -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables > -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining > -debugger-tuning=gdb -v -nostdinc++ -resource-dir > /p/tllvm/lib64/clang/11.0.0 -include > /home/dave/s/lp/libcxx/test/support/nasty_macros.h -I > /home/dave/s/lp/libcxx/include -I > /tmp/_update_lc/t/projects/libcxx/include/c++build -D > __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS > -I /home/dave/s/lp/libcx
Re: [libcxx-dev] [clang] 4ede887 - PR45402: Make the restrictions on constant evaluation of memcmp and
On Sun, 5 Apr 2020 at 15:17, Richard Smith wrote: > On Sun, 5 Apr 2020 at 14:44, David Zarzycki via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> We have overloaded builtins. Can that not solve __builtin_strlen? >> > > I suppose it could, but we generally want __builtin_ to behave > the same as . (The difference would not be visible most of the > time, but there's enough pre-existing use of __builtin_strlen through > "clever" macros and the like that I'd be worried that this would break > something important.) Maybe we should just make the mem* functions work > again for char8_t; then you can use __builtin_memchr(p, 0) - p as an > optimized compile-time strlen. > I see you already did this for memcmp in llvmorg-11-init-7822-g2c88a485c71 :) I added documentation and testing and extended this to also cover memchr in llvmorg-11-init-7851-g7f24db01751. > >> -- >> Sent from my iPhone >> >> On Apr 5, 2020, at 14:53, Richard Smith wrote: >> >> >> Thanks. We need to figure out what the right way to support char8_t with >> string builtins is. These ones could work in principle, whereas things like >> __builtin_strlen would never work because they take operands of the wrong >> types (and we can't cast const char8_t* -> const char* in a constant >> expression). >> >> On Sun, 5 Apr 2020 at 04:14, David Zarzycki via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> >>> Hi Richard, >>> >>> I'm going to commit a narrow fix to clang to make the libcxx test suite >>> pass again by allowing char8_t again. If you feel that this is the wrong >>> long-term solution, please help the libcxx folks with whatever adjustments >>> they need. >>> >>> Thanks! >>> >>> Dave >>> >>> >>> On Sat, Apr 4, 2020, at 9:55 AM, David Zarzycki via libcxx-dev wrote: >>> > Hi Richard, >>> > >>> > This breaks libcxx. Can we please revert this or is a quick fix to >>> > libcxx possible? >>> > >>> > >>> > FAIL: libc++ :: >>> > >>> std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp >>> (58624 of 62672) >>> > TEST 'libc++ :: >>> > >>> std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp' >>> FAILED >>> > Command: ['/p/tllvm/bin/clang++', '-o', >>> > >>> '/tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o', >>> '-x', 'c++', >>> '/home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp', >>> '-c', '-v', '-Werror=thread-safety', '-std=c++2a', '-include', >>> '/home/dave/s/lp/libcxx/test/support/nasty_macros.h', '-nostdinc++', >>> '-I/home/dave/s/lp/libcxx/include', >>> '-I/tmp/_update_lc/t/projects/libcxx/include/c++build', >>> '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', >>> '-D__STDC_CONSTANT_MACROS', '-I/home/dave/s/lp/libcxx/test/support', >>> '-ftemplate-depth=270', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-Wall', >>> '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', >>> '-Wno-unused-command-line-argument', '-Wno-attributes', >>> '-Wno-pessimizing-move', '-Wno-c++11-extensions', >>> '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', >>> '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-c'] >>> > Exit Code: 1 >>> > Standard Error: >>> > -- >>> > clang version 11.0.0 (https://github.com/llvm/llvm-project.git >>> > 22127da8f17c03c69231f3631472f7f99ad9cb7f) >>> > Target: x86_64-unknown-linux-gnu >>> > Thread model: posix >>> > InstalledDir: /p/tllvm/bin >>> > Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 >>> > Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 >>> > Candidate multilib: .;@m64 >>> > Candidate multilib: 32;@m32 >>> > Selected multilib: .;@m64 >>> > (in-process) >>> > "/p/tllvm/bin/clang-11" -cc1 -triple x86_64-unknown-linux-gnu >>> > -emit-obj -mrelax-all -disable-free -disable-llvm-verifier >>> > -discard-value-names -main-file-name compare.pass.cpp >>> > -mrelocation-model static -mthread-model posix -mframe-pointer=all >>> > -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables >>> > -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining >>> > -debugger-tuning=gdb -v -nostdinc++ -resource-dir >>> > /p/tllvm/lib64/clang/11.0.0 -include >>> > /home/dave/s/lp/libcxx/test/support/nasty_macros.h -I >>> > /home/dave/s/lp/libcxx/include -I >>> > /tmp/_update_lc/t/projects/libcxx/include/c++build -D >>> > __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS >>> > -I /home/dave/s/lp/libcxx/test/support -D >>> > _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -internal-isystem >>> > /usr/local/include -internal-isystem >>> > /p/tllvm/lib64/clang/11.0.0/include -internal-externc-isystem /include >>> > -internal-externc-isystem /usr/include -Werror=thread-safety -Wall >>> > -Wextra -Werror
Re: [libcxx-dev] [clang] 4ede887 - PR45402: Make the restrictions on constant evaluation of memcmp and
On Sun, 5 Apr 2020 at 14:44, David Zarzycki via cfe-commits < cfe-commits@lists.llvm.org> wrote: > We have overloaded builtins. Can that not solve __builtin_strlen? > I suppose it could, but we generally want __builtin_ to behave the same as . (The difference would not be visible most of the time, but there's enough pre-existing use of __builtin_strlen through "clever" macros and the like that I'd be worried that this would break something important.) Maybe we should just make the mem* functions work again for char8_t; then you can use __builtin_memchr(p, 0) - p as an optimized compile-time strlen. > -- > Sent from my iPhone > > On Apr 5, 2020, at 14:53, Richard Smith wrote: > > > Thanks. We need to figure out what the right way to support char8_t with > string builtins is. These ones could work in principle, whereas things like > __builtin_strlen would never work because they take operands of the wrong > types (and we can't cast const char8_t* -> const char* in a constant > expression). > > On Sun, 5 Apr 2020 at 04:14, David Zarzycki via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Hi Richard, >> >> I'm going to commit a narrow fix to clang to make the libcxx test suite >> pass again by allowing char8_t again. If you feel that this is the wrong >> long-term solution, please help the libcxx folks with whatever adjustments >> they need. >> >> Thanks! >> >> Dave >> >> >> On Sat, Apr 4, 2020, at 9:55 AM, David Zarzycki via libcxx-dev wrote: >> > Hi Richard, >> > >> > This breaks libcxx. Can we please revert this or is a quick fix to >> > libcxx possible? >> > >> > >> > FAIL: libc++ :: >> > >> std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp >> (58624 of 62672) >> > TEST 'libc++ :: >> > >> std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp' >> FAILED >> > Command: ['/p/tllvm/bin/clang++', '-o', >> > >> '/tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o', >> '-x', 'c++', >> '/home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp', >> '-c', '-v', '-Werror=thread-safety', '-std=c++2a', '-include', >> '/home/dave/s/lp/libcxx/test/support/nasty_macros.h', '-nostdinc++', >> '-I/home/dave/s/lp/libcxx/include', >> '-I/tmp/_update_lc/t/projects/libcxx/include/c++build', >> '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', >> '-D__STDC_CONSTANT_MACROS', '-I/home/dave/s/lp/libcxx/test/support', >> '-ftemplate-depth=270', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-Wall', >> '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', >> '-Wno-unused-command-line-argument', '-Wno-attributes', >> '-Wno-pessimizing-move', '-Wno-c++11-extensions', >> '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', >> '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-c'] >> > Exit Code: 1 >> > Standard Error: >> > -- >> > clang version 11.0.0 (https://github.com/llvm/llvm-project.git >> > 22127da8f17c03c69231f3631472f7f99ad9cb7f) >> > Target: x86_64-unknown-linux-gnu >> > Thread model: posix >> > InstalledDir: /p/tllvm/bin >> > Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 >> > Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 >> > Candidate multilib: .;@m64 >> > Candidate multilib: 32;@m32 >> > Selected multilib: .;@m64 >> > (in-process) >> > "/p/tllvm/bin/clang-11" -cc1 -triple x86_64-unknown-linux-gnu >> > -emit-obj -mrelax-all -disable-free -disable-llvm-verifier >> > -discard-value-names -main-file-name compare.pass.cpp >> > -mrelocation-model static -mthread-model posix -mframe-pointer=all >> > -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables >> > -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining >> > -debugger-tuning=gdb -v -nostdinc++ -resource-dir >> > /p/tllvm/lib64/clang/11.0.0 -include >> > /home/dave/s/lp/libcxx/test/support/nasty_macros.h -I >> > /home/dave/s/lp/libcxx/include -I >> > /tmp/_update_lc/t/projects/libcxx/include/c++build -D >> > __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS >> > -I /home/dave/s/lp/libcxx/test/support -D >> > _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -internal-isystem >> > /usr/local/include -internal-isystem >> > /p/tllvm/lib64/clang/11.0.0/include -internal-externc-isystem /include >> > -internal-externc-isystem /usr/include -Werror=thread-safety -Wall >> > -Wextra -Werror -Wuser-defined-warnings -Wshadow >> > -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move >> > -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type >> > -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code >> > -std=c++2a -fdeprecated-macro -fdebug-compilation-dir >> > >> /tmp/_update_lc/t/projects/libcxx
Re: [libcxx-dev] [clang] 4ede887 - PR45402: Make the restrictions on constant evaluation of memcmp and
We have overloaded builtins. Can that not solve __builtin_strlen? -- Sent from my iPhone > On Apr 5, 2020, at 14:53, Richard Smith wrote: > > > Thanks. We need to figure out what the right way to support char8_t with > string builtins is. These ones could work in principle, whereas things like > __builtin_strlen would never work because they take operands of the wrong > types (and we can't cast const char8_t* -> const char* in a constant > expression). > >> On Sun, 5 Apr 2020 at 04:14, David Zarzycki via cfe-commits >> wrote: >> Hi Richard, >> >> I'm going to commit a narrow fix to clang to make the libcxx test suite pass >> again by allowing char8_t again. If you feel that this is the wrong >> long-term solution, please help the libcxx folks with whatever adjustments >> they need. >> >> Thanks! >> >> Dave >> >> >> On Sat, Apr 4, 2020, at 9:55 AM, David Zarzycki via libcxx-dev wrote: >> > Hi Richard, >> > >> > This breaks libcxx. Can we please revert this or is a quick fix to >> > libcxx possible? >> > >> > >> > FAIL: libc++ :: >> > std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp >> > (58624 of 62672) >> > TEST 'libc++ :: >> > std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp' >> > FAILED >> > Command: ['/p/tllvm/bin/clang++', '-o', >> > '/tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o', >> > '-x', 'c++', >> > '/home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp', >> > '-c', '-v', '-Werror=thread-safety', '-std=c++2a', '-include', >> > '/home/dave/s/lp/libcxx/test/support/nasty_macros.h', '-nostdinc++', >> > '-I/home/dave/s/lp/libcxx/include', >> > '-I/tmp/_update_lc/t/projects/libcxx/include/c++build', >> > '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', >> > '-D__STDC_CONSTANT_MACROS', '-I/home/dave/s/lp/libcxx/test/support', >> > '-ftemplate-depth=270', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-Wall', >> > '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', >> > '-Wno-unused-command-line-argument', '-Wno-attributes', >> > '-Wno-pessimizing-move', '-Wno-c++11-extensions', >> > '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', >> > '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-c'] >> > Exit Code: 1 >> > Standard Error: >> > -- >> > clang version 11.0.0 (https://github.com/llvm/llvm-project.git >> > 22127da8f17c03c69231f3631472f7f99ad9cb7f) >> > Target: x86_64-unknown-linux-gnu >> > Thread model: posix >> > InstalledDir: /p/tllvm/bin >> > Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 >> > Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 >> > Candidate multilib: .;@m64 >> > Candidate multilib: 32;@m32 >> > Selected multilib: .;@m64 >> > (in-process) >> > "/p/tllvm/bin/clang-11" -cc1 -triple x86_64-unknown-linux-gnu >> > -emit-obj -mrelax-all -disable-free -disable-llvm-verifier >> > -discard-value-names -main-file-name compare.pass.cpp >> > -mrelocation-model static -mthread-model posix -mframe-pointer=all >> > -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables >> > -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining >> > -debugger-tuning=gdb -v -nostdinc++ -resource-dir >> > /p/tllvm/lib64/clang/11.0.0 -include >> > /home/dave/s/lp/libcxx/test/support/nasty_macros.h -I >> > /home/dave/s/lp/libcxx/include -I >> > /tmp/_update_lc/t/projects/libcxx/include/c++build -D >> > __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS >> > -I /home/dave/s/lp/libcxx/test/support -D >> > _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -internal-isystem >> > /usr/local/include -internal-isystem >> > /p/tllvm/lib64/clang/11.0.0/include -internal-externc-isystem /include >> > -internal-externc-isystem /usr/include -Werror=thread-safety -Wall >> > -Wextra -Werror -Wuser-defined-warnings -Wshadow >> > -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move >> > -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type >> > -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code >> > -std=c++2a -fdeprecated-macro -fdebug-compilation-dir >> > /tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t >> > -ftemplate-depth 270 -ferror-limit 19 -fgnuc-version=4.2.1 >> > -fno-implicit-modules -fcxx-exceptions -fexceptions -faddrsig -o >> > /tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o >> > -x c++ >> > /home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.tra
Re: [libcxx-dev] [clang] 4ede887 - PR45402: Make the restrictions on constant evaluation of memcmp and
Thanks. We need to figure out what the right way to support char8_t with string builtins is. These ones could work in principle, whereas things like __builtin_strlen would never work because they take operands of the wrong types (and we can't cast const char8_t* -> const char* in a constant expression). On Sun, 5 Apr 2020 at 04:14, David Zarzycki via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Hi Richard, > > I'm going to commit a narrow fix to clang to make the libcxx test suite > pass again by allowing char8_t again. If you feel that this is the wrong > long-term solution, please help the libcxx folks with whatever adjustments > they need. > > Thanks! > > Dave > > > On Sat, Apr 4, 2020, at 9:55 AM, David Zarzycki via libcxx-dev wrote: > > Hi Richard, > > > > This breaks libcxx. Can we please revert this or is a quick fix to > > libcxx possible? > > > > > > FAIL: libc++ :: > > > std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp > (58624 of 62672) > > TEST 'libc++ :: > > > std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp' > FAILED > > Command: ['/p/tllvm/bin/clang++', '-o', > > > '/tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o', > '-x', 'c++', > '/home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp', > '-c', '-v', '-Werror=thread-safety', '-std=c++2a', '-include', > '/home/dave/s/lp/libcxx/test/support/nasty_macros.h', '-nostdinc++', > '-I/home/dave/s/lp/libcxx/include', > '-I/tmp/_update_lc/t/projects/libcxx/include/c++build', > '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', > '-D__STDC_CONSTANT_MACROS', '-I/home/dave/s/lp/libcxx/test/support', > '-ftemplate-depth=270', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-Wall', > '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', > '-Wno-unused-command-line-argument', '-Wno-attributes', > '-Wno-pessimizing-move', '-Wno-c++11-extensions', > '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', > '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-c'] > > Exit Code: 1 > > Standard Error: > > -- > > clang version 11.0.0 (https://github.com/llvm/llvm-project.git > > 22127da8f17c03c69231f3631472f7f99ad9cb7f) > > Target: x86_64-unknown-linux-gnu > > Thread model: posix > > InstalledDir: /p/tllvm/bin > > Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 > > Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 > > Candidate multilib: .;@m64 > > Candidate multilib: 32;@m32 > > Selected multilib: .;@m64 > > (in-process) > > "/p/tllvm/bin/clang-11" -cc1 -triple x86_64-unknown-linux-gnu > > -emit-obj -mrelax-all -disable-free -disable-llvm-verifier > > -discard-value-names -main-file-name compare.pass.cpp > > -mrelocation-model static -mthread-model posix -mframe-pointer=all > > -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables > > -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining > > -debugger-tuning=gdb -v -nostdinc++ -resource-dir > > /p/tllvm/lib64/clang/11.0.0 -include > > /home/dave/s/lp/libcxx/test/support/nasty_macros.h -I > > /home/dave/s/lp/libcxx/include -I > > /tmp/_update_lc/t/projects/libcxx/include/c++build -D > > __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS > > -I /home/dave/s/lp/libcxx/test/support -D > > _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -internal-isystem > > /usr/local/include -internal-isystem > > /p/tllvm/lib64/clang/11.0.0/include -internal-externc-isystem /include > > -internal-externc-isystem /usr/include -Werror=thread-safety -Wall > > -Wextra -Werror -Wuser-defined-warnings -Wshadow > > -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move > > -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type > > -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code > > -std=c++2a -fdeprecated-macro -fdebug-compilation-dir > > > /tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t > -ftemplate-depth 270 -ferror-limit 19 -fgnuc-version=4.2.1 > -fno-implicit-modules -fcxx-exceptions -fexceptions -faddrsig -o > /tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o > -x c++ > /home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp > > clang -cc1 version 11.0.0 based upon LLVM 11.0.0git default target > > x86_64-unknown-linux-gnu > > ignoring nonexistent directory "/include" > > #include "..." search starts here: > > #include <...> search starts here: > > /home/dave/s/lp/libcxx/include > > /tmp/_up
Re: [libcxx-dev] [clang] 4ede887 - PR45402: Make the restrictions on constant evaluation of memcmp and
Hi Richard, I'm going to commit a narrow fix to clang to make the libcxx test suite pass again by allowing char8_t again. If you feel that this is the wrong long-term solution, please help the libcxx folks with whatever adjustments they need. Thanks! Dave On Sat, Apr 4, 2020, at 9:55 AM, David Zarzycki via libcxx-dev wrote: > Hi Richard, > > This breaks libcxx. Can we please revert this or is a quick fix to > libcxx possible? > > > FAIL: libc++ :: > std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp > (58624 of 62672) > TEST 'libc++ :: > std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp' > FAILED > Command: ['/p/tllvm/bin/clang++', '-o', > '/tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o', > '-x', 'c++', > '/home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp', > '-c', '-v', '-Werror=thread-safety', '-std=c++2a', '-include', > '/home/dave/s/lp/libcxx/test/support/nasty_macros.h', '-nostdinc++', > '-I/home/dave/s/lp/libcxx/include', > '-I/tmp/_update_lc/t/projects/libcxx/include/c++build', > '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', > '-D__STDC_CONSTANT_MACROS', '-I/home/dave/s/lp/libcxx/test/support', > '-ftemplate-depth=270', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-Wall', > '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', > '-Wno-unused-command-line-argument', '-Wno-attributes', > '-Wno-pessimizing-move', '-Wno-c++11-extensions', > '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', > '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-c'] > Exit Code: 1 > Standard Error: > -- > clang version 11.0.0 (https://github.com/llvm/llvm-project.git > 22127da8f17c03c69231f3631472f7f99ad9cb7f) > Target: x86_64-unknown-linux-gnu > Thread model: posix > InstalledDir: /p/tllvm/bin > Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 > Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 > Candidate multilib: .;@m64 > Candidate multilib: 32;@m32 > Selected multilib: .;@m64 > (in-process) > "/p/tllvm/bin/clang-11" -cc1 -triple x86_64-unknown-linux-gnu > -emit-obj -mrelax-all -disable-free -disable-llvm-verifier > -discard-value-names -main-file-name compare.pass.cpp > -mrelocation-model static -mthread-model posix -mframe-pointer=all > -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables > -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining > -debugger-tuning=gdb -v -nostdinc++ -resource-dir > /p/tllvm/lib64/clang/11.0.0 -include > /home/dave/s/lp/libcxx/test/support/nasty_macros.h -I > /home/dave/s/lp/libcxx/include -I > /tmp/_update_lc/t/projects/libcxx/include/c++build -D > __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS > -I /home/dave/s/lp/libcxx/test/support -D > _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -internal-isystem > /usr/local/include -internal-isystem > /p/tllvm/lib64/clang/11.0.0/include -internal-externc-isystem /include > -internal-externc-isystem /usr/include -Werror=thread-safety -Wall > -Wextra -Werror -Wuser-defined-warnings -Wshadow > -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move > -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type > -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code > -std=c++2a -fdeprecated-macro -fdebug-compilation-dir > /tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t > -ftemplate-depth 270 -ferror-limit 19 -fgnuc-version=4.2.1 > -fno-implicit-modules -fcxx-exceptions -fexceptions -faddrsig -o > /tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o > -x c++ > /home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp > clang -cc1 version 11.0.0 based upon LLVM 11.0.0git default target > x86_64-unknown-linux-gnu > ignoring nonexistent directory "/include" > #include "..." search starts here: > #include <...> search starts here: > /home/dave/s/lp/libcxx/include > /tmp/_update_lc/t/projects/libcxx/include/c++build > /home/dave/s/lp/libcxx/test/support > /usr/local/include > /p/tllvm/lib64/clang/11.0.0/include > /usr/include > End of search list. > /home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp:53:19: > error: static_assert expression is not an integral constant expression > static_assert(test_constexpr(), "" ); > ^~~~ > /home/dave/
Re: [clang] 4ede887 - PR45402: Make the restrictions on constant evaluation of memcmp and
Hi Richard, This breaks libcxx. Can we please revert this or is a quick fix to libcxx possible? FAIL: libc++ :: std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp (58624 of 62672) TEST 'libc++ :: std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp' FAILED Command: ['/p/tllvm/bin/clang++', '-o', '/tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o', '-x', 'c++', '/home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp', '-c', '-v', '-Werror=thread-safety', '-std=c++2a', '-include', '/home/dave/s/lp/libcxx/test/support/nasty_macros.h', '-nostdinc++', '-I/home/dave/s/lp/libcxx/include', '-I/tmp/_update_lc/t/projects/libcxx/include/c++build', '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-I/home/dave/s/lp/libcxx/test/support', '-ftemplate-depth=270', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-Wall', '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', '-Wno-unused-command-line-argument', '-Wno-attributes', '-Wno-pessimizing-move', '-Wno-c++11-extensions', '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-c'] Exit Code: 1 Standard Error: -- clang version 11.0.0 (https://github.com/llvm/llvm-project.git 22127da8f17c03c69231f3631472f7f99ad9cb7f) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /p/tllvm/bin Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64 (in-process) "/p/tllvm/bin/clang-11" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name compare.pass.cpp -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -v -nostdinc++ -resource-dir /p/tllvm/lib64/clang/11.0.0 -include /home/dave/s/lp/libcxx/test/support/nasty_macros.h -I /home/dave/s/lp/libcxx/include -I /tmp/_update_lc/t/projects/libcxx/include/c++build -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -I /home/dave/s/lp/libcxx/test/support -D _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -internal-isystem /usr/local/include -internal-isystem /p/tllvm/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Werror=thread-safety -Wall -Wextra -Werror -Wuser-defined-warnings -Wshadow -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -std=c++2a -fdeprecated-macro -fdebug-compilation-dir /tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t -ftemplate-depth 270 -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -faddrsig -o /tmp/_update_lc/t/projects/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/Output/compare.pass.cpp.o -x c++ /home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp clang -cc1 version 11.0.0 based upon LLVM 11.0.0git default target x86_64-unknown-linux-gnu ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /home/dave/s/lp/libcxx/include /tmp/_update_lc/t/projects/libcxx/include/c++build /home/dave/s/lp/libcxx/test/support /usr/local/include /p/tllvm/lib64/clang/11.0.0/include /usr/include End of search list. /home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp:53:19: error: static_assert expression is not an integral constant expression static_assert(test_constexpr(), "" ); ^~~~ /home/dave/s/lp/libcxx/include/__string:662:12: note: constant evaluation of '__builtin_memcmp' between arrays of types 'const char8_t' and 'const char8_t' is not supported; only arrays of narrow character types can be compared return __builtin_memcmp(__s1, __s2, __n); ^ /home/dave/s/lp/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/compare.pass.cpp:24:12: note: in call to 'compare(&u8"123"[0], &u8"223"[0], 3)' return std::char_traits::compare
[clang] 4ede887 - PR45402: Make the restrictions on constant evaluation of memcmp and
Author: Richard Smith Date: 2020-04-03T18:26:14-07:00 New Revision: 4ede8879924c08ae5b495d3f421c167d822a60be URL: https://github.com/llvm/llvm-project/commit/4ede8879924c08ae5b495d3f421c167d822a60be DIFF: https://github.com/llvm/llvm-project/commit/4ede8879924c08ae5b495d3f421c167d822a60be.diff LOG: PR45402: Make the restrictions on constant evaluation of memcmp and memchr consistent and comprehensible, and document them. We previously allowed evaluation of memcmp on arrays of integers of any size, so long as the call evaluated to 0, and allowed evaluation of memchr on any array of integral type of size 1 (including enums). The purpose of constant-evaluating these builtins is only to support constexpr std::char_traits, so we now consistently allow them on arrays of (possibly signed or unsigned) char only. Added: Modified: clang/docs/LanguageExtensions.rst clang/include/clang/Basic/DiagnosticASTKinds.td clang/lib/AST/ExprConstant.cpp clang/test/SemaCXX/constexpr-string.cpp Removed: diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 558ce7dee653..6dcfd1a49f06 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -2333,10 +2333,11 @@ String builtins --- Clang provides constant expression evaluation support for builtins forms of -the following functions from the C standard library header: +the following functions from the C standard library headers + and : * ``memchr`` -* ``memcmp`` +* ``memcmp`` (and its deprecated BSD / POSIX alias ``bcmp``) * ``strchr`` * ``strcmp`` * ``strlen`` @@ -2366,7 +2367,11 @@ In addition to the above, one further builtin is provided: constant expressions in C++11 onwards (where a cast from ``void*`` to ``char*`` is disallowed in general). -Support for constant expression evaluation for the above builtins be detected +Constant evaluation support for the ``__builtin_mem*`` functions is provided +only for arrays of ``char``, ``signed char``, or ``unsigned char``, despite +these functions accepting an argument of type ``const void*``. + +Support for constant expression evaluation for the above builtins can be detected with ``__has_feature(cxx_constexpr_string_builtins)``. Memory builtins @@ -2386,6 +2391,25 @@ more information. Note that the `size` argument must be a compile time constant. +Clang provides constant expression evaluation support for builtin forms of the +following functions from the C standard library headers + and : + +* ``memcpy`` +* ``memmove`` +* ``wmemcpy`` +* ``wmemmove`` + +In each case, the builtin form has the name of the C library function prefixed +by ``__builtin_``. + +Constant evaluation support is only provided when the source and destination +are pointers to arrays with the same trivially copyable element type, and the +given size is an exact multiple of the element size that is no greater than +the number of elements accessible through the source and destination operands. + +Constant evaluation support is not yet provided for ``__builtin_memcpy_inline``. + Atomic Min/Max builtins with memory ordering diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td b/clang/include/clang/Basic/DiagnosticASTKinds.td index 544573edffdf..a1415f9ec0e1 100644 --- a/clang/include/clang/Basic/DiagnosticASTKinds.td +++ b/clang/include/clang/Basic/DiagnosticASTKinds.td @@ -244,6 +244,12 @@ def note_constexpr_unsupported_unsized_array : Note< def note_constexpr_unsized_array_indexed : Note< "indexing of array without known bound is not allowed " "in a constant expression">; +def note_constexpr_memcmp_unsupported : Note< + "constant evaluation of %0 between arrays of types %1 and %2 " + "is not supported; only arrays of narrow character types can be compared">; +def note_constexpr_memchr_unsupported : Note< + "constant evaluation of %0 on array of type %1 " + "is not supported; only arrays of narrow character types can be searched">; def note_constexpr_memcpy_null : Note< "%select{source|destination}2 of " "'%select{%select{memcpy|wmemcpy}1|%select{memmove|wmemmove}1}0' " diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index c6e1cc7b67df..a83b2e24e17f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -8469,8 +8469,12 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, } // Give up on byte-oriented matching against multibyte elements. // FIXME: We can compare the bytes in the correct order. -if (IsRawByte && Info.Ctx.getTypeSizeInChars(CharTy) != CharUnits::One()) +if (IsRawByte && !CharTy->isCharType()) { + Info.FFDiag(E, diag::note_constexpr_memchr_unsupported) + << (std::string("'") + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'") +