llvm-project/llvm
Miod Vallat 877c84acd4 [Support] unsafe pointer arithmetic in llvm_regcomp()
regcomp.c uses the "start + count < end" idiom to check that there are
"count" bytes available in an array of char "start" and "end" both point
to.

This is fine, unless "start + count" goes beyond the last element of the
array. In this case, pedantic interpretation of the C standard makes
the comparison of such a pointer against "end" undefined, and optimizers
from hell will happily remove as much code as possible because of this.

An example of this occurs in regcomp.c's bothcases(), which defines
bracket[3], sets "next" to "bracket" and "end" to "bracket + 2". Then it
invokes p_bracket(), which starts with "if (p->next + 5 < p->end)"...

Because bothcases() and p_bracket() are static functions in regcomp.c,
there is a real risk of miscompilation if aggressive inlining happens.

The following diff rewrites the "start + count < end" constructs into
"end - start > count". Assuming "end" and "start" are always pointing in
the array (such as "bracket[3]" above), "end - start" is well-defined
and can be compared without trouble.

As a bonus, MORE2() implies MORE() therefore SEETWO() can be simplified
a bit.

Bug report: https://github.com/llvm/llvm-project/issues/47993

Reviewed By: MaskRay, vitalybuka

Differential Revision: https://reviews.llvm.org/D97129
2022-02-03 19:59:27 -05:00
..
benchmarks
bindings
cmake [cmake] Increase -fms-compatibility-version in Windows toolchain file 2022-02-03 13:41:46 -08:00
docs AMDGPU [NFC]: Fix a few typos in docs AMDGPUUsage.rst 2022-02-02 14:22:52 -08:00
examples Cleanup header dependencies in LLVMCore 2022-02-02 06:54:20 +01:00
include Revert "[ProfileData] Read and symbolize raw memprof profiles." 2022-02-03 16:14:05 -08:00
lib [Support] unsafe pointer arithmetic in llvm_regcomp() 2022-02-03 19:59:27 -05:00
projects
resources
runtimes [CMake] Passthrough OSX CMake options to builtins and runtimes 2022-01-21 16:54:22 -08:00
test Revert "[ProfileData] Read and symbolize raw memprof profiles." 2022-02-03 16:14:05 -08:00
tools Revert "[ProfileData] Read and symbolize raw memprof profiles." 2022-02-03 16:14:05 -08:00
unittests Revert "[ProfileData] Read and symbolize raw memprof profiles." 2022-02-03 16:14:05 -08:00
utils [gn build] Set -fmsc-version=1920 on Windows 2022-02-03 15:56:02 -08:00
.clang-format
.clang-tidy
.gitattributes [split-file] Respect input file's line endings 2022-01-21 18:45:03 -06:00
.gitignore
CMakeLists.txt Bump the trunk major version to 15 2022-02-01 23:54:52 -08:00
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in

README.txt

The LLVM Compiler Infrastructure
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.