Skip to content

Commit 5d1e1cf

Browse files
authored
[clang][bytecode] Check memcmp for block pointers (llvm#165070)
We can't read from non-block pointers anyway. Fixes llvm#165061
1 parent 046ed90 commit 5d1e1cf

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,9 @@ static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
19411941
return true;
19421942
}
19431943

1944+
if (!PtrA.isBlockPointer() || !PtrB.isBlockPointer())
1945+
return false;
1946+
19441947
bool IsWide =
19451948
(ID == Builtin::BIwmemcmp || ID == Builtin::BI__builtin_wmemcmp);
19461949

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,8 @@ namespace Memcmp {
15101510
static_assert(f());
15111511
#endif
15121512

1513+
int unknown;
1514+
void foo(void) { unknown *= __builtin_memcmp(0, 0, 2); }
15131515
}
15141516

15151517
namespace Memchr {

0 commit comments

Comments
 (0)