Rename GetLanguageInfo to GetLanguageSpecificData (#117012)
[llvm-project.git] / clang / lib / CodeGen / CGPointerAuthInfo.h
blob0a0c11fb423f25e5693989b32d8b2dbc3a8f6ad0
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.
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"
21 namespace clang {
22 namespace CodeGen {
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;
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());
47 explicit operator bool() const { return isSigned(); }
49 bool isSigned() const {
50 return AuthenticationMode != PointerAuthenticationMode::None;
53 unsigned getKey() const {
54 assert(isSigned());
55 return Key;
57 llvm::Value *getDiscriminator() const {
58 assert(isSigned());
59 return Discriminator;
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) {
92 return !(LHS != RHS);
96 } // end namespace CodeGen
97 } // end namespace clang
99 #endif