Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,10 @@ static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
if (PtrA.isDummy() || PtrB.isDummy())
return false;

if (!CheckRange(S, OpPC, PtrA, AK_Read) ||
!CheckRange(S, OpPC, PtrB, AK_Read))
return false;

// Now, read both pointers to a buffer and compare those.
BitcastBuffer BufferA(
Bits(ASTCtx.getTypeSize(ElemTypeA) * PtrA.getNumElems()));
Expand Down
7 changes: 7 additions & 0 deletions clang/test/AST/ByteCode/builtin-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,13 @@ namespace Memcmp {

int unknown;
void foo(void) { unknown *= __builtin_memcmp(0, 0, 2); }

constexpr int onepasttheend(char a) {
__builtin_memcmp(&a, &a + 1, 1); // both-note {{read of dereferenced one-past-the-end pointer}}
return 1;
}
static_assert(onepasttheend(10)); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}
}

namespace Memchr {
Expand Down