1 | //===----- CGPointerAuthInfo.h - -------------------------------*- C++ -*-===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // Pointer auth info class. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGPOINTERAUTHINFO_H |
14 | #define LLVM_CLANG_LIB_CODEGEN_CGPOINTERAUTHINFO_H |
15 | |
16 | #include "clang/AST/Type.h" |
17 | #include "clang/Basic/LangOptions.h" |
18 | #include "llvm/IR/Type.h" |
19 | #include "llvm/IR/Value.h" |
20 | |
21 | namespace clang { |
22 | namespace CodeGen { |
23 | |
24 | class CGPointerAuthInfo { |
25 | private: |
26 | PointerAuthenticationMode AuthenticationMode : 2; |
27 | unsigned IsIsaPointer : 1; |
28 | unsigned AuthenticatesNullValues : 1; |
29 | unsigned Key : 2; |
30 | llvm::Value *Discriminator; |
31 | |
32 | public: |
33 | CGPointerAuthInfo() |
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()); |
45 | } |
46 | |
47 | explicit operator bool() const { return isSigned(); } |
48 | |
49 | bool isSigned() const { |
50 | return AuthenticationMode != PointerAuthenticationMode::None; |
51 | } |
52 | |
53 | unsigned getKey() const { |
54 | assert(isSigned()); |
55 | return Key; |
56 | } |
57 | llvm::Value *getDiscriminator() const { |
58 | assert(isSigned()); |
59 | return Discriminator; |
60 | } |
61 | |
62 | PointerAuthenticationMode getAuthenticationMode() const { |
63 | return AuthenticationMode; |
64 | } |
65 | |
66 | bool isIsaPointer() const { return IsIsaPointer; } |
67 | |
68 | bool authenticatesNullValues() const { return AuthenticatesNullValues; } |
69 | |
70 | bool shouldStrip() const { |
71 | return AuthenticationMode == PointerAuthenticationMode::Strip || |
72 | AuthenticationMode == PointerAuthenticationMode::SignAndStrip; |
73 | } |
74 | |
75 | bool shouldSign() const { |
76 | return AuthenticationMode == PointerAuthenticationMode::SignAndStrip || |
77 | AuthenticationMode == PointerAuthenticationMode::SignAndAuth; |
78 | } |
79 | |
80 | bool shouldAuth() const { |
81 | return AuthenticationMode == PointerAuthenticationMode::SignAndAuth; |
82 | } |
83 | |
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; |
88 | } |
89 | |
90 | friend bool operator==(const CGPointerAuthInfo &LHS, |
91 | const CGPointerAuthInfo &RHS) { |
92 | return !(LHS != RHS); |
93 | } |
94 | }; |
95 | |
96 | } // end namespace CodeGen |
97 | } // end namespace clang |
98 | |
99 | #endif |
100 | |