[clang] [clang][bytecode] Do a full CheckLoad in builtin_memcmp() (PR #181337)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 13 01:11:25 PST 2026


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/181337

This handles unknown size arrays as well and prints the expected diagnostics.

>From 4840d5c16eba7fdad2889288c97333d98e294ceb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 13 Feb 2026 10:08:32 +0100
Subject: [PATCH] [clang][bytecode] Do a full CheckLoad in builtin_memcmp()

This handles unknown size arrays as well and prints the expected
diagnostics.
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp      | 6 +-----
 clang/test/AST/ByteCode/builtin-functions.cpp | 4 ++++
 2 files changed, 5 insertions(+), 5 deletions(-)

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);



More information about the cfe-commits mailing list