[clang] [clang][bytecode] Do a full CheckLoad in builtin_memcmp() (PR #181337)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 13 01:12:04 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
This handles unknown size arrays as well and prints the expected diagnostics.
---
Full diff: https://github.com/llvm/llvm-project/pull/181337.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+1-5)
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+4)
``````````diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 2f86877d31ffb..e5a66ef7de5e4 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1987,11 +1987,7 @@ static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
return false;
}
- if (PtrA.isDummy() || PtrB.isDummy())
- return false;
-
- if (!CheckRange(S, OpPC, PtrA, AK_Read) ||
- !CheckRange(S, OpPC, PtrB, AK_Read))
+ if (!CheckLoad(S, OpPC, PtrA, AK_Read) || !CheckLoad(S, OpPC, PtrB, AK_Read))
return false;
// Now, read both pointers to a buffer and compare those.
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 77ba9ca4ce05c..f637ae235193d 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1576,6 +1576,10 @@ namespace Memcmp {
static_assert(__builtin_bcmp("abab\0banana", "abab\0canada", 6) != 0);
static_assert(__builtin_bcmp("abab\0banana", "abab\0canada", 5) == 0);
+ constexpr char abc[] = /* missing */; // both-error {{expected expression}} \
+ // both-note {{declared here}}
+ static_assert(__builtin_bcmp(abc, abc, 2) == 0); // both-error {{not an integral constant expression}} \
+ // both-note {{initializer of 'abc' is unknown}}
static_assert(__builtin_wmemcmp(L"abaa", L"abba", 3) == -1);
static_assert(__builtin_wmemcmp(L"abaa", L"abba", 2) == 0);
``````````
</details>
https://github.com/llvm/llvm-project/pull/181337
More information about the cfe-commits
mailing list