clang  20.0.0git
CGPointerAuthInfo.h
Go to the documentation of this file.
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"
18 #include "llvm/IR/Type.h"
19 #include "llvm/IR/Value.h"
20 
21 namespace clang {
22 namespace CodeGen {
23 
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:
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 
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
Defines the clang::LangOptions interface.
C Language Family Type Representation.
friend bool operator==(const CGPointerAuthInfo &LHS, const CGPointerAuthInfo &RHS)
PointerAuthenticationMode getAuthenticationMode() const
llvm::Value * getDiscriminator() const
friend bool operator!=(const CGPointerAuthInfo &LHS, const CGPointerAuthInfo &RHS)
CGPointerAuthInfo(unsigned Key, PointerAuthenticationMode AuthenticationMode, bool IsIsaPointer, bool AuthenticatesNullValues, llvm::Value *Discriminator)
The JSON file list parser is used to communicate input to InstallAPI.
PointerAuthenticationMode
Definition: LangOptions.h:60
#define false
Definition: stdbool.h:26
#define bool
Definition: stdbool.h:24