diff options
author | Rahul Joshi <rjoshi@nvidia.com> | 2025-07-15 11:07:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-15 11:07:48 -0700 |
commit | 183f1ac412c1a0c69c7dc6aef85c28c0749609cb (patch) | |
tree | 2e1cfe8ccdebe408411ff5deb31b493b7e3833eb /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | c9f03b8c6ece968a6a413f5ea3a33e23f0aed5ef (diff) | |
download | llvm-183f1ac412c1a0c69c7dc6aef85c28c0749609cb.zip llvm-183f1ac412c1a0c69c7dc6aef85c28c0749609cb.tar.gz llvm-183f1ac412c1a0c69c7dc6aef85c28c0749609cb.tar.bz2 |
[LLVM] Fix an ASAN error in `lookupLLVMIntrinsicByName` (#147444)
Fix unnecessary conversion of C-String to StringRef in the `Cmp` lambda
inside `lookupLLVMIntrinsicByName`. This both fixes an ASAN error in the
code that happens when the `Name` StringRef passed in is not a Null
terminated StringRef, and additionally can potentially speed up the code
as well by eliminating the unnecessary computation of string length
every time a C String is converted to StringRef in this code (It seems
practically this computation is eliminated in optimized builds, but this
will avoid it in O0 builds as well).
Added a unit test that demonstrates this issue by building LLVM with
these options:
```
CMAKE_BUILD_TYPE=Debug
LLVM_USE_SANITIZER=Address
LLVM_OPTIMIZE_SANITIZED_BUILDS=OFF
```
The error reported is as follows:
```
==462665==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x5030000391a2 at pc 0x56525cc30bbf bp 0x7fff9e4ccc60 sp 0x7fff9e4cc428
READ of size 19 at 0x5030000391a2 thread T0
#0 0x56525cc30bbe in strlen (upstream-llvm-second/llvm-project/build/unittests/IR/IRTests+0x713bbe) (BuildId: 0651acf1e582a4d2)
#1 0x7f8ff22ad334 in std::char_traits<char>::length(char const*) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/char_traits.h:399:9
#2 0x7f8ff22a34a0 in llvm::StringRef::StringRef(char const*) /home/rjoshi/upstream-llvm-second/llvm-project/llvm/include/llvm/ADT/StringRef.h:96:33
#3 0x7f8ff28ca184 in _ZZL25lookupLLVMIntrinsicByNameN4llvm8ArrayRefIjEENS_9StringRefES2_ENK3$_0clIjPKcEEDaT_T0_ upstream-llvm-second/llvm-project/llvm/lib/IR/Intrinsics.cpp:673:18
```
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
0 files changed, 0 insertions, 0 deletions