1 //===----- CGPointerAuthInfo.h - -------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Pointer auth info class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_CODEGEN_CGPOINTERAUTHINFO_H
14 #define LLVM_CLANG_LIB_CODEGEN_CGPOINTERAUTHINFO_H
16 #include "clang/AST/Type.h"
17 #include "clang/Basic/LangOptions.h"
18 #include "llvm/IR/Type.h"
19 #include "llvm/IR/Value.h"
24 class CGPointerAuthInfo
{
26 PointerAuthenticationMode AuthenticationMode
: 2;
27 unsigned IsIsaPointer
: 1;
28 unsigned AuthenticatesNullValues
: 1;
30 llvm::Value
*Discriminator
;
34 : AuthenticationMode(PointerAuthenticationMode::None
),
35 IsIsaPointer(false), AuthenticatesNullValues(false), Key(0),
36 Discriminator(nullptr) {}
37 CGPointerAuthInfo(unsigned Key
, PointerAuthenticationMode AuthenticationMode
,
38 bool IsIsaPointer
, bool AuthenticatesNullValues
,
39 llvm::Value
*Discriminator
)
40 : AuthenticationMode(AuthenticationMode
), IsIsaPointer(IsIsaPointer
),
41 AuthenticatesNullValues(AuthenticatesNullValues
), Key(Key
),
42 Discriminator(Discriminator
) {
43 assert(!Discriminator
|| Discriminator
->getType()->isIntegerTy() ||
44 Discriminator
->getType()->isPointerTy());
47 explicit operator bool() const { return isSigned(); }
49 bool isSigned() const {
50 return AuthenticationMode
!= PointerAuthenticationMode::None
;
53 unsigned getKey() const {
57 llvm::Value
*getDiscriminator() const {
62 PointerAuthenticationMode
getAuthenticationMode() const {
63 return AuthenticationMode
;
66 bool isIsaPointer() const { return IsIsaPointer
; }
68 bool authenticatesNullValues() const { return AuthenticatesNullValues
; }
70 bool shouldStrip() const {
71 return AuthenticationMode
== PointerAuthenticationMode::Strip
||
72 AuthenticationMode
== PointerAuthenticationMode::SignAndStrip
;
75 bool shouldSign() const {
76 return AuthenticationMode
== PointerAuthenticationMode::SignAndStrip
||
77 AuthenticationMode
== PointerAuthenticationMode::SignAndAuth
;
80 bool shouldAuth() const {
81 return AuthenticationMode
== PointerAuthenticationMode::SignAndAuth
;
84 friend bool operator!=(const CGPointerAuthInfo
&LHS
,
85 const CGPointerAuthInfo
&RHS
) {
86 return LHS
.Key
!= RHS
.Key
|| LHS
.Discriminator
!= RHS
.Discriminator
||
87 LHS
.AuthenticationMode
!= RHS
.AuthenticationMode
;
90 friend bool operator==(const CGPointerAuthInfo
&LHS
,
91 const CGPointerAuthInfo
&RHS
) {
96 } // end namespace CodeGen
97 } // end namespace clang