Coverage Report

Created: 2020-09-19 12:23

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Sema/Ownership.h
Line
Count
Source (jump to first uncovered line)
1
//===- Ownership.h - Parser ownership helpers -------------------*- 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
//  This file contains classes for managing ownership of Stmt and Expr nodes.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_SEMA_OWNERSHIP_H
14
#define LLVM_CLANG_SEMA_OWNERSHIP_H
15
16
#include "clang/AST/Expr.h"
17
#include "clang/Basic/LLVM.h"
18
#include "llvm/ADT/ArrayRef.h"
19
#include "llvm/Support/PointerLikeTypeTraits.h"
20
#include "llvm/Support/type_traits.h"
21
#include <cassert>
22
#include <cstddef>
23
#include <cstdint>
24
25
//===----------------------------------------------------------------------===//
26
// OpaquePtr
27
//===----------------------------------------------------------------------===//
28
29
namespace clang {
30
31
class CXXBaseSpecifier;
32
class CXXCtorInitializer;
33
class Decl;
34
class Expr;
35
class ParsedTemplateArgument;
36
class QualType;
37
class Stmt;
38
class TemplateName;
39
class TemplateParameterList;
40
41
  /// Wrapper for void* pointer.
42
  /// \tparam PtrTy Either a pointer type like 'T*' or a type that behaves like
43
  ///               a pointer.
44
  ///
45
  /// This is a very simple POD type that wraps a pointer that the Parser
46
  /// doesn't know about but that Sema or another client does.  The PtrTy
47
  /// template argument is used to make sure that "Decl" pointers are not
48
  /// compatible with "Type" pointers for example.
49
  template <class PtrTy>
50
  class OpaquePtr {
51
    void *Ptr = nullptr;
52
53
88.5M
    explicit OpaquePtr(void *Ptr) : Ptr(Ptr) {}
clang::OpaquePtr<clang::QualType>::OpaquePtr(void*)
Line
Count
Source
53
88.5M
    explicit OpaquePtr(void *Ptr) : Ptr(Ptr) {}
clang::OpaquePtr<clang::TemplateName>::OpaquePtr(void*)
Line
Count
Source
53
6.36k
    explicit OpaquePtr(void *Ptr) : Ptr(Ptr) {}
54
55
    using Traits = llvm::PointerLikeTypeTraits<PtrTy>;
56
57
  public:
58
297M
    OpaquePtr(std::nullptr_t = nullptr) {}
clang::OpaquePtr<clang::DeclGroupRef>::OpaquePtr(std::nullptr_t)
Line
Count
Source
58
40.0M
    OpaquePtr(std::nullptr_t = nullptr) {}
clang::OpaquePtr<clang::TemplateName>::OpaquePtr(std::nullptr_t)
Line
Count
Source
58
27.9M
    OpaquePtr(std::nullptr_t = nullptr) {}
clang::OpaquePtr<clang::QualType>::OpaquePtr(std::nullptr_t)
Line
Count
Source
58
229M
    OpaquePtr(std::nullptr_t = nullptr) {}
59
60
96.6M
    static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; }
clang::OpaquePtr<clang::QualType>::make(clang::QualType)
Line
Count
Source
60
71.8M
    static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; }
clang::OpaquePtr<clang::TemplateName>::make(clang::TemplateName)
Line
Count
Source
60
2.66M
    static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; }
clang::OpaquePtr<clang::DeclGroupRef>::make(clang::DeclGroupRef)
Line
Count
Source
60
22.1M
    static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; }
61
62
    /// Returns plain pointer to the entity pointed by this wrapper.
63
    /// \tparam PointeeT Type of pointed entity.
64
    ///
65
    /// It is identical to getPtrAs<PointeeT*>.
66
    template <typename PointeeT> PointeeT* getPtrTo() const {
67
      return get();
68
    }
69
70
    /// Returns pointer converted to the specified type.
71
    /// \tparam PtrT Result pointer type.  There must be implicit conversion
72
    ///              from PtrTy to PtrT.
73
    ///
74
    /// In contrast to getPtrTo, this method allows the return type to be
75
    /// a smart pointer.
76
    template <typename PtrT> PtrT getPtrAs() const {
77
      return get();
78
    }
79
80
114M
    PtrTy get() const {
81
114M
      return Traits::getFromVoidPointer(Ptr);
82
114M
    }
clang::OpaquePtr<clang::DeclGroupRef>::get() const
Line
Count
Source
80
17.1M
    PtrTy get() const {
81
17.1M
      return Traits::getFromVoidPointer(Ptr);
82
17.1M
    }
clang::OpaquePtr<clang::QualType>::get() const
Line
Count
Source
80
95.0M
    PtrTy get() const {
81
95.0M
      return Traits::getFromVoidPointer(Ptr);
82
95.0M
    }
clang::OpaquePtr<clang::TemplateName>::get() const
Line
Count
Source
80
2.68M
    PtrTy get() const {
81
2.68M
      return Traits::getFromVoidPointer(Ptr);
82
2.68M
    }
83
84
96.6M
    void set(PtrTy P) {
85
96.6M
      Ptr = Traits::getAsVoidPointer(P);
86
96.6M
    }
clang::OpaquePtr<clang::QualType>::set(clang::QualType)
Line
Count
Source
84
71.8M
    void set(PtrTy P) {
85
71.8M
      Ptr = Traits::getAsVoidPointer(P);
86
71.8M
    }
clang::OpaquePtr<clang::TemplateName>::set(clang::TemplateName)
Line
Count
Source
84
2.66M
    void set(PtrTy P) {
85
2.66M
      Ptr = Traits::getAsVoidPointer(P);
86
2.66M
    }
clang::OpaquePtr<clang::DeclGroupRef>::set(clang::DeclGroupRef)
Line
Count
Source
84
22.1M
    void set(PtrTy P) {
85
22.1M
      Ptr = Traits::getAsVoidPointer(P);
86
22.1M
    }
87
88
238M
    explicit operator bool() const { return Ptr != nullptr; }
clang::OpaquePtr<clang::DeclGroupRef>::operator bool() const
Line
Count
Source
88
15.9M
    explicit operator bool() const { return Ptr != nullptr; }
clang::OpaquePtr<clang::QualType>::operator bool() const
Line
Count
Source
88
219M
    explicit operator bool() const { return Ptr != nullptr; }
clang::OpaquePtr<clang::TemplateName>::operator bool() const
Line
Count
Source
88
2.53M
    explicit operator bool() const { return Ptr != nullptr; }
89
90
98.8M
    void *getAsOpaquePtr() const { return Ptr; }
clang::OpaquePtr<clang::QualType>::getAsOpaquePtr() const
Line
Count
Source
90
98.8M
    void *getAsOpaquePtr() const { return Ptr; }
clang::OpaquePtr<clang::TemplateName>::getAsOpaquePtr() const
Line
Count
Source
90
5.06k
    void *getAsOpaquePtr() const { return Ptr; }
clang::OpaquePtr<clang::DeclGroupRef>::getAsOpaquePtr() const
Line
Count
Source
90
2
    void *getAsOpaquePtr() const { return Ptr; }
91
88.5M
    static OpaquePtr getFromOpaquePtr(void *P) { return OpaquePtr(P); }
clang::OpaquePtr<clang::QualType>::getFromOpaquePtr(void*)
Line
Count
Source
91
88.5M
    static OpaquePtr getFromOpaquePtr(void *P) { return OpaquePtr(P); }
clang::OpaquePtr<clang::TemplateName>::getFromOpaquePtr(void*)
Line
Count
Source
91
6.36k
    static OpaquePtr getFromOpaquePtr(void *P) { return OpaquePtr(P); }
92
  };
93
94
  /// UnionOpaquePtr - A version of OpaquePtr suitable for membership
95
  /// in a union.
96
  template <class T> struct UnionOpaquePtr {
97
    void *Ptr;
98
99
    static UnionOpaquePtr make(OpaquePtr<T> P) {
100
      UnionOpaquePtr OP = { P.getAsOpaquePtr() };
101
      return OP;
102
    }
103
104
62.9M
    OpaquePtr<T> get() const { return OpaquePtr<T>::getFromOpaquePtr(Ptr); }
clang::UnionOpaquePtr<clang::QualType>::get() const
Line
Count
Source
104
62.9M
    OpaquePtr<T> get() const { return OpaquePtr<T>::getFromOpaquePtr(Ptr); }
clang::UnionOpaquePtr<clang::TemplateName>::get() const
Line
Count
Source
104
1.67k
    OpaquePtr<T> get() const { return OpaquePtr<T>::getFromOpaquePtr(Ptr); }
105
62.9M
    operator OpaquePtr<T>() const { return get(); }
106
107
73.5M
    UnionOpaquePtr &operator=(OpaquePtr<T> P) {
108
73.5M
      Ptr = P.getAsOpaquePtr();
109
73.5M
      return *this;
110
73.5M
    }
clang::UnionOpaquePtr<clang::QualType>::operator=(clang::OpaquePtr<clang::QualType>)
Line
Count
Source
107
73.5M
    UnionOpaquePtr &operator=(OpaquePtr<T> P) {
108
73.5M
      Ptr = P.getAsOpaquePtr();
109
73.5M
      return *this;
110
73.5M
    }
clang::UnionOpaquePtr<clang::TemplateName>::operator=(clang::OpaquePtr<clang::TemplateName>)
Line
Count
Source
107
420
    UnionOpaquePtr &operator=(OpaquePtr<T> P) {
108
420
      Ptr = P.getAsOpaquePtr();
109
420
      return *this;
110
420
    }
111
  };
112
113
} // namespace clang
114
115
namespace llvm {
116
117
  template <class T>
118
  struct PointerLikeTypeTraits<clang::OpaquePtr<T>> {
119
    static constexpr int NumLowBitsAvailable = 0;
120
121
    static inline void *getAsVoidPointer(clang::OpaquePtr<T> P) {
122
      // FIXME: Doesn't work? return P.getAs< void >();
123
      return P.getAsOpaquePtr();
124
    }
125
126
    static inline clang::OpaquePtr<T> getFromVoidPointer(void *P) {
127
      return clang::OpaquePtr<T>::getFromOpaquePtr(P);
128
    }
129
  };
130
131
} // namespace llvm
132
133
namespace clang {
134
135
  // Basic
136
  class DiagnosticBuilder;
137
138
  // Determines whether the low bit of the result pointer for the
139
  // given UID is always zero. If so, ActionResult will use that bit
140
  // for it's "invalid" flag.
141
  template<class Ptr>
142
  struct IsResultPtrLowBitFree {
143
    static const bool value = false;
144
  };
145
146
  /// ActionResult - This structure is used while parsing/acting on
147
  /// expressions, stmts, etc.  It encapsulates both the object returned by
148
  /// the action, plus a sense of whether or not it is valid.
149
  /// When CompressInvalid is true, the "invalid" flag will be
150
  /// stored in the low bit of the Val pointer.
151
  template<class PtrTy,
152
           bool CompressInvalid = IsResultPtrLowBitFree<PtrTy>::value>
153
  class ActionResult {
154
    PtrTy Val;
155
    bool Invalid;
156
157
  public:
158
21.5M
    ActionResult(bool Invalid = false) : Val(PtrTy()), Invalid(Invalid) {}
clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::ActionResult(bool)
Line
Count
Source
158
19.6M
    ActionResult(bool Invalid = false) : Val(PtrTy()), Invalid(Invalid) {}
clang::ActionResult<clang::Decl*, false>::ActionResult(bool)
Line
Count
Source
158
1.92M
    ActionResult(bool Invalid = false) : Val(PtrTy()), Invalid(Invalid) {}
159
51.4M
    ActionResult(PtrTy val) : Val(val), Invalid(false) {}
clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::ActionResult(clang::OpaquePtr<clang::QualType>)
Line
Count
Source
159
50.9M
    ActionResult(PtrTy val) : Val(val), Invalid(false) {}
clang::ActionResult<clang::Decl*, false>::ActionResult(clang::Decl*)
Line
Count
Source
159
532k
    ActionResult(PtrTy val) : Val(val), Invalid(false) {}
160
8
    ActionResult(const DiagnosticBuilder &) : Val(PtrTy()), Invalid(true) {}
161
162
    // These two overloads prevent void* -> bool conversions.
163
    ActionResult(const void *) = delete;
164
    ActionResult(volatile void *) = delete;
165
166
89.0M
    bool isInvalid() const { return Invalid; }
clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::isInvalid() const
Line
Count
Source
166
85.1M
    bool isInvalid() const { return Invalid; }
clang::ActionResult<clang::Decl*, false>::isInvalid() const
Line
Count
Source
166
3.88M
    bool isInvalid() const { return Invalid; }
167
15.0M
    bool isUsable() const { return !Invalid && 
Val15.0M
; }
clang::ActionResult<clang::Decl*, false>::isUsable() const
Line
Count
Source
167
76.8k
    bool isUsable() const { return !Invalid && Val; }
clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::isUsable() const
Line
Count
Source
167
15.0M
    bool isUsable() const { return !Invalid && 
Val15.0M
; }
168
2.18M
    bool isUnset() const { return !Invalid && 
!Val2.18M
; }
169
170
97.2M
    PtrTy get() const { return Val; }
clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::get() const
Line
Count
Source
170
91.9M
    PtrTy get() const { return Val; }
clang::ActionResult<clang::Decl*, false>::get() const
Line
Count
Source
170
5.28M
    PtrTy get() const { return Val; }
171
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
172
173
    void set(PtrTy V) { Val = V; }
174
175
1.71M
    const ActionResult &operator=(PtrTy RHS) {
176
1.71M
      Val = RHS;
177
1.71M
      Invalid = false;
178
1.71M
      return *this;
179
1.71M
    }
clang::ActionResult<clang::Decl*, false>::operator=(clang::Decl*)
Line
Count
Source
175
1.71M
    const ActionResult &operator=(PtrTy RHS) {
176
1.71M
      Val = RHS;
177
1.71M
      Invalid = false;
178
1.71M
      return *this;
179
1.71M
    }
Unexecuted instantiation: clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::operator=(clang::OpaquePtr<clang::QualType>)
180
  };
181
182
  // This ActionResult partial specialization places the "invalid"
183
  // flag into the low bit of the pointer.
184
  template<typename PtrTy>
185
  class ActionResult<PtrTy, true> {
186
    // A pointer whose low bit is 1 if this result is invalid, 0
187
    // otherwise.
188
    uintptr_t PtrWithInvalid;
189
190
    using PtrTraits = llvm::PointerLikeTypeTraits<PtrTy>;
191
192
  public:
193
    ActionResult(bool Invalid = false)
194
176M
        : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
clang::ActionResult<clang::Expr*, true>::ActionResult(bool)
Line
Count
Source
194
158M
        : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
clang::ActionResult<clang::CXXBaseSpecifier*, true>::ActionResult(bool)
Line
Count
Source
194
241
        : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
clang::ActionResult<clang::CXXCtorInitializer*, true>::ActionResult(bool)
Line
Count
Source
194
32.5k
        : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
clang::ActionResult<clang::Stmt*, true>::ActionResult(bool)
Line
Count
Source
194
17.6M
        : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
195
196
352M
    ActionResult(PtrTy V) {
197
352M
      void *VP = PtrTraits::getAsVoidPointer(V);
198
352M
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
199
352M
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
200
352M
    }
clang::ActionResult<clang::Expr*, true>::ActionResult(clang::Expr*)
Line
Count
Source
196
340M
    ActionResult(PtrTy V) {
197
340M
      void *VP = PtrTraits::getAsVoidPointer(V);
198
340M
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
199
340M
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
200
340M
    }
clang::ActionResult<clang::CXXBaseSpecifier*, true>::ActionResult(clang::CXXBaseSpecifier*)
Line
Count
Source
196
181k
    ActionResult(PtrTy V) {
197
181k
      void *VP = PtrTraits::getAsVoidPointer(V);
198
181k
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
199
181k
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
200
181k
    }
clang::ActionResult<clang::CXXCtorInitializer*, true>::ActionResult(clang::CXXCtorInitializer*)
Line
Count
Source
196
225k
    ActionResult(PtrTy V) {
197
225k
      void *VP = PtrTraits::getAsVoidPointer(V);
198
225k
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
199
225k
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
200
225k
    }
clang::ActionResult<clang::Stmt*, true>::ActionResult(clang::Stmt*)
Line
Count
Source
196
11.8M
    ActionResult(PtrTy V) {
197
11.8M
      void *VP = PtrTraits::getAsVoidPointer(V);
198
11.8M
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
199
11.8M
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
200
11.8M
    }
201
202
314
    ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) {}
clang::ActionResult<clang::CXXCtorInitializer*, true>::ActionResult(clang::DiagnosticBuilder const&)
Line
Count
Source
202
23
    ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) {}
clang::ActionResult<clang::Stmt*, true>::ActionResult(clang::DiagnosticBuilder const&)
Line
Count
Source
202
2
    ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) {}
clang::ActionResult<clang::Expr*, true>::ActionResult(clang::DiagnosticBuilder const&)
Line
Count
Source
202
289
    ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) {}
203
204
    // These two overloads prevent void* -> bool conversions.
205
    ActionResult(const void *) = delete;
206
    ActionResult(volatile void *) = delete;
207
208
450M
    bool isInvalid() const { return PtrWithInvalid & 0x01; }
clang::ActionResult<clang::Expr*, true>::isInvalid() const
Line
Count
Source
208
440M
    bool isInvalid() const { return PtrWithInvalid & 0x01; }
clang::ActionResult<clang::Stmt*, true>::isInvalid() const
Line
Count
Source
208
10.0M
    bool isInvalid() const { return PtrWithInvalid & 0x01; }
clang::ActionResult<clang::CXXBaseSpecifier*, true>::isInvalid() const
Line
Count
Source
208
182k
    bool isInvalid() const { return PtrWithInvalid & 0x01; }
clang::ActionResult<clang::CXXCtorInitializer*, true>::isInvalid() const
Line
Count
Source
208
225k
    bool isInvalid() const { return PtrWithInvalid & 0x01; }
209
74.8M
    bool isUsable() const { return PtrWithInvalid > 0x01; }
clang::ActionResult<clang::Expr*, true>::isUsable() const
Line
Count
Source
209
67.8M
    bool isUsable() const { return PtrWithInvalid > 0x01; }
clang::ActionResult<clang::Stmt*, true>::isUsable() const
Line
Count
Source
209
6.99M
    bool isUsable() const { return PtrWithInvalid > 0x01; }
210
24.2M
    bool isUnset() const { return PtrWithInvalid == 0; }
211
212
753M
    PtrTy get() const {
213
753M
      void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
214
753M
      return PtrTraits::getFromVoidPointer(VP);
215
753M
    }
clang::ActionResult<clang::Expr*, true>::get() const
Line
Count
Source
212
735M
    PtrTy get() const {
213
735M
      void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
214
735M
      return PtrTraits::getFromVoidPointer(VP);
215
735M
    }
clang::ActionResult<clang::Stmt*, true>::get() const
Line
Count
Source
212
17.5M
    PtrTy get() const {
213
17.5M
      void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
214
17.5M
      return PtrTraits::getFromVoidPointer(VP);
215
17.5M
    }
clang::ActionResult<clang::CXXBaseSpecifier*, true>::get() const
Line
Count
Source
212
181k
    PtrTy get() const {
213
181k
      void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
214
181k
      return PtrTraits::getFromVoidPointer(VP);
215
181k
    }
clang::ActionResult<clang::CXXCtorInitializer*, true>::get() const
Line
Count
Source
212
225k
    PtrTy get() const {
213
225k
      void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
214
225k
      return PtrTraits::getFromVoidPointer(VP);
215
225k
    }
216
217
14.0M
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::StringLiteral* clang::ActionResult<clang::Expr*, true>::getAs<clang::StringLiteral>()
Line
Count
Source
217
14
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::Expr* clang::ActionResult<clang::Expr*, true>::getAs<clang::Expr>()
Line
Count
Source
217
11.6M
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::Stmt* clang::ActionResult<clang::Expr*, true>::getAs<clang::Stmt>()
Line
Count
Source
217
2.00M
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::Expr* clang::ActionResult<clang::Stmt*, true>::getAs<clang::Expr>()
Line
Count
Source
217
411
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::CXXConstructExpr* clang::ActionResult<clang::Expr*, true>::getAs<clang::CXXConstructExpr>()
Line
Count
Source
217
75
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::Stmt* clang::ActionResult<clang::Stmt*, true>::getAs<clang::Stmt>()
Line
Count
Source
217
417k
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::DeclRefExpr* clang::ActionResult<clang::Expr*, true>::getAs<clang::DeclRefExpr>()
Line
Count
Source
217
218
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
218
219
    void set(PtrTy V) {
220
      void *VP = PtrTraits::getAsVoidPointer(V);
221
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
222
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
223
    }
224
225
24.5M
    const ActionResult &operator=(PtrTy RHS) {
226
24.5M
      void *VP = PtrTraits::getAsVoidPointer(RHS);
227
24.5M
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
228
24.5M
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
229
24.5M
      return *this;
230
24.5M
    }
clang::ActionResult<clang::Expr*, true>::operator=(clang::Expr*)
Line
Count
Source
225
24.5M
    const ActionResult &operator=(PtrTy RHS) {
226
24.5M
      void *VP = PtrTraits::getAsVoidPointer(RHS);
227
24.5M
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
228
24.5M
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
229
24.5M
      return *this;
230
24.5M
    }
clang::ActionResult<clang::Stmt*, true>::operator=(clang::Stmt*)
Line
Count
Source
225
24
    const ActionResult &operator=(PtrTy RHS) {
226
24
      void *VP = PtrTraits::getAsVoidPointer(RHS);
227
24
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
228
24
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
229
24
      return *this;
230
24
    }
231
232
    // For types where we can fit a flag in with the pointer, provide
233
    // conversions to/from pointer type.
234
644k
    static ActionResult getFromOpaquePointer(void *P) {
235
644k
      ActionResult Result;
236
644k
      Result.PtrWithInvalid = (uintptr_t)P;
237
644k
      return Result;
238
644k
    }
239
644k
    void *getAsOpaquePointer() const { return (void*)PtrWithInvalid; }
240
  };
241
242
  /// An opaque type for threading parsed type information through the
243
  /// parser.
244
  using ParsedType = OpaquePtr<QualType>;
245
  using UnionParsedType = UnionOpaquePtr<QualType>;
246
247
  // We can re-use the low bit of expression, statement, base, and
248
  // member-initializer pointers for the "invalid" flag of
249
  // ActionResult.
250
  template<> struct IsResultPtrLowBitFree<Expr*> {
251
    static const bool value = true;
252
  };
253
  template<> struct IsResultPtrLowBitFree<Stmt*> {
254
    static const bool value = true;
255
  };
256
  template<> struct IsResultPtrLowBitFree<CXXBaseSpecifier*> {
257
    static const bool value = true;
258
  };
259
  template<> struct IsResultPtrLowBitFree<CXXCtorInitializer*> {
260
    static const bool value = true;
261
  };
262
263
  using ExprResult = ActionResult<Expr *>;
264
  using StmtResult = ActionResult<Stmt *>;
265
  using TypeResult = ActionResult<ParsedType>;
266
  using BaseResult = ActionResult<CXXBaseSpecifier *>;
267
  using MemInitResult = ActionResult<CXXCtorInitializer *>;
268
269
  using DeclResult = ActionResult<Decl *>;
270
  using ParsedTemplateTy = OpaquePtr<TemplateName>;
271
  using UnionParsedTemplateTy = UnionOpaquePtr<TemplateName>;
272
273
  using MultiExprArg = MutableArrayRef<Expr *>;
274
  using MultiStmtArg = MutableArrayRef<Stmt *>;
275
  using ASTTemplateArgsPtr = MutableArrayRef<ParsedTemplateArgument>;
276
  using MultiTypeArg = MutableArrayRef<ParsedType>;
277
  using MultiTemplateParamsArg = MutableArrayRef<TemplateParameterList *>;
278
279
2.42M
  inline ExprResult ExprError() { return ExprResult(true); }
280
634k
  inline StmtResult StmtError() { return StmtResult(true); }
281
773
  inline TypeResult TypeError() { return TypeResult(true); }
282
283
654
  inline ExprResult ExprError(const DiagnosticBuilder&) { return ExprError(); }
284
473
  inline StmtResult StmtError(const DiagnosticBuilder&) { return StmtError(); }
285
286
16.5M
  inline ExprResult ExprEmpty() { return ExprResult(false); }
287
70
  inline StmtResult StmtEmpty() { return StmtResult(false); }
288
289
0
  inline Expr *AssertSuccess(ExprResult R) {
290
0
    assert(!R.isInvalid() && "operation was asserted to never fail!");
291
0
    return R.get();
292
0
  }
293
294
0
  inline Stmt *AssertSuccess(StmtResult R) {
295
0
    assert(!R.isInvalid() && "operation was asserted to never fail!");
296
0
    return R.get();
297
0
  }
298
299
} // namespace clang
300
301
#endif // LLVM_CLANG_SEMA_OWNERSHIP_H