[clang] [clang][bytecode][NFC] Add assert to ptrauth_string_discriminator (PR #132527)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 21 23:14:30 PDT 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/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.
>From ed5dd8936d615c19f7b6d7d3ec607374f28ebf47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sat, 22 Mar 2025 07:12:51 +0100
Subject: [PATCH] [clang][bytecode][NFC] Add assert to
ptrauth_string_discriminator
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.
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 57037b674feba..a6e1884404287 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1477,6 +1477,9 @@ static bool interp__builtin_ptrauth_string_discriminator(
const auto &Ptr = S.Stk.peek<Pointer>();
assert(Ptr.getFieldDesc()->isPrimitiveArray());
+ // This should be created for a StringLiteral, so should alway shold at least
+ // one array element.
+ assert(Ptr.getFieldDesc()->getNumElems() >= 1);
StringRef R(&Ptr.deref<char>(), Ptr.getFieldDesc()->getNumElems() - 1);
uint64_t Result = getPointerAuthStableSipHash(R);
pushInteger(S, Result, Call->getType());
More information about the cfe-commits
mailing list