[clang] 6b41de3 - [clang][Interp] Implement ptrauth builtins
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 24 04:03:07 PDT 2024
Author: Timm Bäder
Date: 2024-06-24T13:02:55+02:00
New Revision: 6b41de3605658069eb69b8684c2760e54bd1bea3
URL: https://github.com/llvm/llvm-project/commit/6b41de3605658069eb69b8684c2760e54bd1bea3
DIFF: https://github.com/llvm/llvm-project/commit/6b41de3605658069eb69b8684c2760e54bd1bea3.diff
LOG: [clang][Interp] Implement ptrauth builtins
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/CodeGen/ptrauth-intrinsics.c
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index cb5962466f35f..3c96059375360 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3572,6 +3572,7 @@ bool ByteCodeExprGen<Emitter>::VisitBuiltinCallExpr(const CallExpr *E) {
unsigned Builtin = E->getBuiltinCallee();
if (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
+ Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
Builtin == Builtin::BI__builtin_function_start) {
if (std::optional<unsigned> GlobalOffset = P.createGlobal(E))
return this->emitGetPtrGlobal(*GlobalOffset, E);
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp
index af8841c8b4ef8..aeb6ec42eb39e 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -13,6 +13,7 @@
#include "clang/AST/RecordLayout.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/TargetInfo.h"
+#include "llvm/Support/SipHash.h"
namespace clang {
namespace interp {
@@ -1100,6 +1101,18 @@ static bool interp__builtin_os_log_format_buffer_size(InterpState &S,
return true;
}
+static bool interp__builtin_ptrauth_string_discriminator(
+ InterpState &S, CodePtr OpPC, const InterpFrame *Frame,
+ const Function *Func, const CallExpr *Call) {
+ const auto &Ptr = S.Stk.peek<Pointer>();
+ assert(Ptr.getFieldDesc()->isPrimitiveArray());
+
+ StringRef R(&Ptr.deref<char>(), Ptr.getFieldDesc()->getNumElems() - 1);
+ uint64_t Result = getPointerAuthStableSipHash(R);
+ pushInteger(S, Result, Call->getType());
+ return true;
+}
+
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
const CallExpr *Call) {
const InterpFrame *Frame = S.Current;
@@ -1424,6 +1437,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
return false;
break;
+ case Builtin::BI__builtin_ptrauth_string_discriminator:
+ if (!interp__builtin_ptrauth_string_discriminator(S, OpPC, Frame, F, Call))
+ return false;
+ break;
+
default:
S.FFDiag(S.Current->getLocation(OpPC),
diag::note_invalid_subexpr_in_const_expr)
diff --git a/clang/test/CodeGen/ptrauth-intrinsics.c b/clang/test/CodeGen/ptrauth-intrinsics.c
index db37d78553769..50bf1898e4b37 100644
--- a/clang/test/CodeGen/ptrauth-intrinsics.c
+++ b/clang/test/CodeGen/ptrauth-intrinsics.c
@@ -1,5 +1,8 @@
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple aarch64-elf -fptrauth-intrinsics -emit-llvm %s -o - | FileCheck %s
+//
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-elf -fptrauth-intrinsics -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s
void (*fnptr)(void);
long int_discriminator;
More information about the cfe-commits
mailing list