Skip to content

Commit 6c8e9a6

Browse files
authored
[clang][bytecode][NFC] Add assert to ptrauth_string_discriminator (#132527)
As pointed out by @shafik, this confuses static analysis and most probably humans as well. Add an assertion to ensure the given array has at least one element.
1 parent 20b5728 commit 6c8e9a6

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,9 @@ static bool interp__builtin_ptrauth_string_discriminator(
14771477
const auto &Ptr = S.Stk.peek<Pointer>();
14781478
assert(Ptr.getFieldDesc()->isPrimitiveArray());
14791479

1480+
// This should be created for a StringLiteral, so should alway shold at least
1481+
// one array element.
1482+
assert(Ptr.getFieldDesc()->getNumElems() >= 1);
14801483
StringRef R(&Ptr.deref<char>(), Ptr.getFieldDesc()->getNumElems() - 1);
14811484
uint64_t Result = getPointerAuthStableSipHash(R);
14821485
pushInteger(S, Result, Call->getType());

0 commit comments

Comments
 (0)