clang 20.0.0git
FunctionPointer.h
Go to the documentation of this file.
1//===--- FunctionPointer.h - Types for the constexpr VM ---------*- 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#ifndef LLVM_CLANG_AST_INTERP_FUNCTION_POINTER_H
10#define LLVM_CLANG_AST_INTERP_FUNCTION_POINTER_H
11
12#include "Function.h"
13#include "Primitives.h"
14
15namespace clang {
16class ASTContext;
17class APValue;
18namespace interp {
19
20class FunctionPointer final {
21private:
22 const Function *Func;
23 uint64_t Offset;
24 bool Valid;
25
26public:
27 FunctionPointer() = default;
28 FunctionPointer(const Function *Func, uint64_t Offset = 0)
29 : Func(Func), Offset(Offset), Valid(true) {}
30
31 FunctionPointer(uintptr_t IntVal, const Descriptor *Desc = nullptr)
32 : Func(reinterpret_cast<const Function *>(IntVal)), Offset(0),
33 Valid(false) {}
34
35 const Function *getFunction() const { return Func; }
36 uint64_t getOffset() const { return Offset; }
37 bool isZero() const { return !Func; }
38 bool isValid() const { return Valid; }
39 bool isWeak() const {
40 if (!Func || !Valid || !Func->getDecl())
41 return false;
42
43 return Func->getDecl()->isWeak();
44 }
45
46 APValue toAPValue(const ASTContext &) const;
47 void print(llvm::raw_ostream &OS) const;
48
49 std::string toDiagnosticString(const ASTContext &Ctx) const {
50 if (!Func)
51 return "nullptr";
52
53 return toAPValue(Ctx).getAsString(Ctx, Func->getDecl()->getType());
54 }
55
56 uint64_t getIntegerRepresentation() const {
57 return static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Func));
58 }
59
61 if (Func == RHS.Func && Offset == RHS.Offset)
64 }
65};
66
67inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
68 FunctionPointer FP) {
69 FP.print(OS);
70 return OS;
71}
72
73} // namespace interp
74} // namespace clang
75
76#endif
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
Definition: APValue.cpp:946
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
void print(llvm::raw_ostream &OS) const
const Function * getFunction() const
FunctionPointer(uintptr_t IntVal, const Descriptor *Desc=nullptr)
ComparisonCategoryResult compare(const FunctionPointer &RHS) const
APValue toAPValue(const ASTContext &) const
FunctionPointer(const Function *Func, uint64_t Offset=0)
uint64_t getIntegerRepresentation() const
std::string toDiagnosticString(const ASTContext &Ctx) const
Bytecode function.
Definition: Function.h:81
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
Definition: Boolean.h:151
The JSON file list parser is used to communicate input to InstallAPI.
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26
Describes a memory block created by an allocation site.
Definition: Descriptor.h:111