/src/llvm-project/clang/lib/AST/Interp/IntegralAP.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- Integral.h - Wrapper for numeric types for the 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 | | // Defines the VM types and helpers operating on types. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H |
14 | | #define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H |
15 | | |
16 | | #include "clang/AST/APValue.h" |
17 | | #include "clang/AST/ComparisonCategories.h" |
18 | | #include "llvm/ADT/APSInt.h" |
19 | | #include "llvm/Support/MathExtras.h" |
20 | | #include "llvm/Support/raw_ostream.h" |
21 | | #include <cstddef> |
22 | | #include <cstdint> |
23 | | |
24 | | #include "Primitives.h" |
25 | | |
26 | | namespace clang { |
27 | | namespace interp { |
28 | | |
29 | | using APInt = llvm::APInt; |
30 | | using APSInt = llvm::APSInt; |
31 | | template <unsigned Bits, bool Signed> class Integral; |
32 | | |
33 | | template <bool Signed> class IntegralAP final { |
34 | | private: |
35 | | friend IntegralAP<!Signed>; |
36 | | APInt V; |
37 | | |
38 | | template <typename T, bool InputSigned> |
39 | 0 | static T truncateCast(const APInt &V) { |
40 | 0 | constexpr unsigned BitSize = sizeof(T) * 8; |
41 | 0 | if (BitSize >= V.getBitWidth()) { |
42 | 0 | APInt Extended; |
43 | 0 | if constexpr (InputSigned) |
44 | 0 | Extended = V.sext(BitSize); |
45 | 0 | else |
46 | 0 | Extended = V.zext(BitSize); |
47 | 0 | return std::is_signed_v<T> ? Extended.getSExtValue() |
48 | 0 | : Extended.getZExtValue(); |
49 | 0 | } |
50 | | |
51 | 0 | return std::is_signed_v<T> ? V.trunc(BitSize).getSExtValue() |
52 | 0 | : V.trunc(BitSize).getZExtValue(); |
53 | 0 | } Unexecuted instantiation: unsigned int clang::interp::IntegralAP<false>::truncateCast<unsigned int, false>(llvm::APInt const&) Unexecuted instantiation: long clang::interp::IntegralAP<false>::truncateCast<long, false>(llvm::APInt const&) Unexecuted instantiation: unsigned int clang::interp::IntegralAP<true>::truncateCast<unsigned int, true>(llvm::APInt const&) Unexecuted instantiation: long clang::interp::IntegralAP<true>::truncateCast<long, true>(llvm::APInt const&) Unexecuted instantiation: unsigned char clang::interp::IntegralAP<false>::truncateCast<unsigned char, false>(llvm::APInt const&) Unexecuted instantiation: signed char clang::interp::IntegralAP<false>::truncateCast<signed char, false>(llvm::APInt const&) Unexecuted instantiation: unsigned short clang::interp::IntegralAP<false>::truncateCast<unsigned short, false>(llvm::APInt const&) Unexecuted instantiation: short clang::interp::IntegralAP<false>::truncateCast<short, false>(llvm::APInt const&) Unexecuted instantiation: int clang::interp::IntegralAP<false>::truncateCast<int, false>(llvm::APInt const&) Unexecuted instantiation: unsigned long clang::interp::IntegralAP<false>::truncateCast<unsigned long, false>(llvm::APInt const&) Unexecuted instantiation: bool clang::interp::IntegralAP<false>::truncateCast<bool, false>(llvm::APInt const&) Unexecuted instantiation: unsigned char clang::interp::IntegralAP<true>::truncateCast<unsigned char, true>(llvm::APInt const&) Unexecuted instantiation: signed char clang::interp::IntegralAP<true>::truncateCast<signed char, true>(llvm::APInt const&) Unexecuted instantiation: unsigned short clang::interp::IntegralAP<true>::truncateCast<unsigned short, true>(llvm::APInt const&) Unexecuted instantiation: short clang::interp::IntegralAP<true>::truncateCast<short, true>(llvm::APInt const&) Unexecuted instantiation: int clang::interp::IntegralAP<true>::truncateCast<int, true>(llvm::APInt const&) Unexecuted instantiation: unsigned long clang::interp::IntegralAP<true>::truncateCast<unsigned long, true>(llvm::APInt const&) Unexecuted instantiation: bool clang::interp::IntegralAP<true>::truncateCast<bool, true>(llvm::APInt const&) |
54 | | |
55 | | public: |
56 | | using AsUnsigned = IntegralAP<false>; |
57 | | |
58 | | template <typename T> |
59 | | IntegralAP(T Value, unsigned BitWidth) |
60 | 0 | : V(APInt(BitWidth, static_cast<uint64_t>(Value), Signed)) {} Unexecuted instantiation: clang::interp::IntegralAP<false>::IntegralAP<int>(int, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true>::IntegralAP<int>(int, unsigned int) |
61 | | |
62 | 0 | IntegralAP(APInt V) : V(V) {} Unexecuted instantiation: clang::interp::IntegralAP<true>::IntegralAP(llvm::APInt) Unexecuted instantiation: clang::interp::IntegralAP<false>::IntegralAP(llvm::APInt) |
63 | | /// Arbitrary value for uninitialized variables. |
64 | 0 | IntegralAP() : IntegralAP(-1, 1024) {} Unexecuted instantiation: clang::interp::IntegralAP<false>::IntegralAP() Unexecuted instantiation: clang::interp::IntegralAP<true>::IntegralAP() |
65 | | |
66 | 0 | IntegralAP operator-() const { return IntegralAP(-V); } Unexecuted instantiation: clang::interp::IntegralAP<false>::operator-() const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator-() const |
67 | 0 | IntegralAP operator-(const IntegralAP &Other) const { |
68 | 0 | return IntegralAP(V - Other.V); |
69 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::operator-(clang::interp::IntegralAP<false> const&) const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator-(clang::interp::IntegralAP<true> const&) const |
70 | 0 | bool operator>(const IntegralAP &RHS) const { |
71 | 0 | if constexpr (Signed) |
72 | 0 | return V.ugt(RHS.V); |
73 | 0 | return V.sgt(RHS.V); |
74 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::operator>(clang::interp::IntegralAP<false> const&) const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator>(clang::interp::IntegralAP<true> const&) const |
75 | 0 | bool operator>=(IntegralAP RHS) const { |
76 | 0 | if constexpr (Signed) |
77 | 0 | return V.uge(RHS.V); |
78 | 0 | return V.sge(RHS.V); |
79 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::operator>=(clang::interp::IntegralAP<false>) const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator>=(clang::interp::IntegralAP<true>) const |
80 | 0 | bool operator<(IntegralAP RHS) const { |
81 | 0 | if constexpr (Signed) |
82 | 0 | return V.slt(RHS.V); |
83 | 0 | return V.slt(RHS.V); |
84 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::operator<(clang::interp::IntegralAP<false>) const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator<(clang::interp::IntegralAP<true>) const |
85 | | bool operator<=(IntegralAP RHS) const { |
86 | | if constexpr (Signed) |
87 | | return V.ult(RHS.V); |
88 | | return V.ult(RHS.V); |
89 | | } |
90 | | |
91 | | template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>> |
92 | 0 | explicit operator Ty() const { |
93 | 0 | return truncateCast<Ty, Signed>(V); |
94 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::operator unsigned int<unsigned int, void>() const Unexecuted instantiation: clang::interp::IntegralAP<false>::operator long<long, void>() const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator unsigned int<unsigned int, void>() const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator long<long, void>() const Unexecuted instantiation: clang::interp::IntegralAP<false>::operator unsigned char<unsigned char, void>() const Unexecuted instantiation: clang::interp::IntegralAP<false>::operator signed char<signed char, void>() const Unexecuted instantiation: clang::interp::IntegralAP<false>::operator unsigned short<unsigned short, void>() const Unexecuted instantiation: clang::interp::IntegralAP<false>::operator short<short, void>() const Unexecuted instantiation: clang::interp::IntegralAP<false>::operator int<int, void>() const Unexecuted instantiation: clang::interp::IntegralAP<false>::operator unsigned long<unsigned long, void>() const Unexecuted instantiation: clang::interp::IntegralAP<false>::operator bool<bool, void>() const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator unsigned char<unsigned char, void>() const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator signed char<signed char, void>() const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator unsigned short<unsigned short, void>() const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator short<short, void>() const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator int<int, void>() const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator unsigned long<unsigned long, void>() const Unexecuted instantiation: clang::interp::IntegralAP<true>::operator bool<bool, void>() const |
95 | | |
96 | 0 | template <typename T> static IntegralAP from(T Value, unsigned NumBits = 0) { |
97 | 0 | assert(NumBits > 0); |
98 | 0 | APInt Copy = APInt(NumBits, static_cast<uint64_t>(Value), Signed); |
99 | |
|
100 | 0 | return IntegralAP<Signed>(Copy); |
101 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<long>(long, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<unsigned int>(unsigned int, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<long>(long, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<unsigned int>(unsigned int, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<clang::interp::Boolean>(clang::interp::Boolean, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<clang::interp::Boolean>(clang::interp::Boolean, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<clang::interp::Integral<8u, true> >(clang::interp::Integral<8u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<clang::interp::Integral<8u, false> >(clang::interp::Integral<8u, false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<clang::interp::Integral<16u, true> >(clang::interp::Integral<16u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<clang::interp::Integral<16u, false> >(clang::interp::Integral<16u, false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<clang::interp::Integral<32u, true> >(clang::interp::Integral<32u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<clang::interp::Integral<32u, false> >(clang::interp::Integral<32u, false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<clang::interp::Integral<64u, true> >(clang::interp::Integral<64u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<clang::interp::Integral<64u, false> >(clang::interp::Integral<64u, false>, unsigned int) |
102 | | |
103 | | template <bool InputSigned> |
104 | 0 | static IntegralAP from(IntegralAP<InputSigned> V, unsigned NumBits = 0) { |
105 | 0 | if (NumBits == 0) |
106 | 0 | NumBits = V.bitWidth(); |
107 | |
|
108 | 0 | if constexpr (InputSigned) |
109 | 0 | return IntegralAP<Signed>(V.V.sextOrTrunc(NumBits)); |
110 | 0 | return IntegralAP<Signed>(V.V.zextOrTrunc(NumBits)); |
111 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<false>(clang::interp::IntegralAP<false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<true>(clang::interp::IntegralAP<true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<true>(clang::interp::IntegralAP<true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<false>(clang::interp::IntegralAP<false>, unsigned int) |
112 | | |
113 | | template <unsigned Bits, bool InputSigned> |
114 | 0 | static IntegralAP from(Integral<Bits, InputSigned> I, unsigned BitWidth) { |
115 | 0 | APInt Copy = APInt(BitWidth, static_cast<uint64_t>(I), InputSigned); |
116 | |
|
117 | 0 | return IntegralAP<Signed>(Copy); |
118 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<8u, true>(clang::interp::Integral<8u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<8u, false>(clang::interp::Integral<8u, false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<16u, true>(clang::interp::Integral<16u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<16u, false>(clang::interp::Integral<16u, false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<32u, true>(clang::interp::Integral<32u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<32u, false>(clang::interp::Integral<32u, false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<64u, true>(clang::interp::Integral<64u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<64u, false>(clang::interp::Integral<64u, false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<8u, true>(clang::interp::Integral<8u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<8u, false>(clang::interp::Integral<8u, false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<16u, true>(clang::interp::Integral<16u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<16u, false>(clang::interp::Integral<16u, false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<32u, true>(clang::interp::Integral<32u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<32u, false>(clang::interp::Integral<32u, false>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<64u, true>(clang::interp::Integral<64u, true>, unsigned int) Unexecuted instantiation: clang::interp::IntegralAP<true> clang::interp::IntegralAP<true>::from<64u, false>(clang::interp::Integral<64u, false>, unsigned int) |
119 | | |
120 | 0 | static IntegralAP zero(int32_t BitWidth) { |
121 | 0 | APInt V = APInt(BitWidth, 0LL, Signed); |
122 | 0 | return IntegralAP(V); |
123 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::zero(int) Unexecuted instantiation: clang::interp::IntegralAP<true>::zero(int) |
124 | | |
125 | 0 | constexpr unsigned bitWidth() const { return V.getBitWidth(); } Unexecuted instantiation: clang::interp::IntegralAP<false>::bitWidth() const Unexecuted instantiation: clang::interp::IntegralAP<true>::bitWidth() const |
126 | | |
127 | 0 | APSInt toAPSInt(unsigned Bits = 0) const { |
128 | 0 | if (Bits == 0) |
129 | 0 | Bits = bitWidth(); |
130 | |
|
131 | 0 | if constexpr (Signed) |
132 | 0 | return APSInt(V.sext(Bits), !Signed); |
133 | 0 | else |
134 | 0 | return APSInt(V.zext(Bits), !Signed); |
135 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::toAPSInt(unsigned int) const Unexecuted instantiation: clang::interp::IntegralAP<true>::toAPSInt(unsigned int) const |
136 | 0 | APValue toAPValue() const { return APValue(toAPSInt()); } Unexecuted instantiation: clang::interp::IntegralAP<false>::toAPValue() const Unexecuted instantiation: clang::interp::IntegralAP<true>::toAPValue() const |
137 | | |
138 | 0 | bool isZero() const { return V.isZero(); } Unexecuted instantiation: clang::interp::IntegralAP<false>::isZero() const Unexecuted instantiation: clang::interp::IntegralAP<true>::isZero() const |
139 | 0 | bool isPositive() const { return V.isNonNegative(); } Unexecuted instantiation: clang::interp::IntegralAP<false>::isPositive() const Unexecuted instantiation: clang::interp::IntegralAP<true>::isPositive() const |
140 | 0 | bool isNegative() const { return !V.isNonNegative(); } Unexecuted instantiation: clang::interp::IntegralAP<false>::isNegative() const Unexecuted instantiation: clang::interp::IntegralAP<true>::isNegative() const |
141 | 0 | bool isMin() const { return V.isMinValue(); } Unexecuted instantiation: clang::interp::IntegralAP<false>::isMin() const Unexecuted instantiation: clang::interp::IntegralAP<true>::isMin() const |
142 | | bool isMax() const { return V.isMaxValue(); } |
143 | 0 | static constexpr bool isSigned() { return Signed; } Unexecuted instantiation: clang::interp::IntegralAP<false>::isSigned() Unexecuted instantiation: clang::interp::IntegralAP<true>::isSigned() |
144 | 0 | bool isMinusOne() const { return Signed && V == -1; } Unexecuted instantiation: clang::interp::IntegralAP<false>::isMinusOne() const Unexecuted instantiation: clang::interp::IntegralAP<true>::isMinusOne() const |
145 | | |
146 | 0 | unsigned countLeadingZeros() const { return V.countl_zero(); } |
147 | | |
148 | 0 | void print(llvm::raw_ostream &OS) const { OS << V; } Unexecuted instantiation: clang::interp::IntegralAP<false>::print(llvm::raw_ostream&) const Unexecuted instantiation: clang::interp::IntegralAP<true>::print(llvm::raw_ostream&) const |
149 | 0 | std::string toDiagnosticString(const ASTContext &Ctx) const { |
150 | 0 | std::string NameStr; |
151 | 0 | llvm::raw_string_ostream OS(NameStr); |
152 | 0 | print(OS); |
153 | 0 | return NameStr; |
154 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::toDiagnosticString(clang::ASTContext const&) const Unexecuted instantiation: clang::interp::IntegralAP<true>::toDiagnosticString(clang::ASTContext const&) const |
155 | | |
156 | 0 | IntegralAP truncate(unsigned BitWidth) const { |
157 | 0 | return IntegralAP(V.trunc(BitWidth)); |
158 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::truncate(unsigned int) const Unexecuted instantiation: clang::interp::IntegralAP<true>::truncate(unsigned int) const |
159 | | |
160 | 0 | IntegralAP<false> toUnsigned() const { |
161 | 0 | APInt Copy = V; |
162 | 0 | return IntegralAP<false>(Copy); |
163 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::toUnsigned() const Unexecuted instantiation: clang::interp::IntegralAP<true>::toUnsigned() const |
164 | | |
165 | 0 | ComparisonCategoryResult compare(const IntegralAP &RHS) const { |
166 | 0 | assert(Signed == RHS.isSigned()); |
167 | 0 | assert(bitWidth() == RHS.bitWidth()); |
168 | 0 | if constexpr (Signed) { |
169 | 0 | if (V.slt(RHS.V)) |
170 | 0 | return ComparisonCategoryResult::Less; |
171 | 0 | if (V.sgt(RHS.V)) |
172 | 0 | return ComparisonCategoryResult::Greater; |
173 | 0 | return ComparisonCategoryResult::Equal; |
174 | 0 | } |
175 | | |
176 | 0 | assert(!Signed); |
177 | 0 | if (V.ult(RHS.V)) |
178 | 0 | return ComparisonCategoryResult::Less; |
179 | 0 | if (V.ugt(RHS.V)) |
180 | 0 | return ComparisonCategoryResult::Greater; |
181 | 0 | return ComparisonCategoryResult::Equal; |
182 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::compare(clang::interp::IntegralAP<false> const&) const Unexecuted instantiation: clang::interp::IntegralAP<true>::compare(clang::interp::IntegralAP<true> const&) const |
183 | | |
184 | 0 | static bool increment(IntegralAP A, IntegralAP *R) { |
185 | 0 | IntegralAP<Signed> One(1, A.bitWidth()); |
186 | 0 | return add(A, One, A.bitWidth() + 1, R); |
187 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::increment(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::increment(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>*) |
188 | | |
189 | 0 | static bool decrement(IntegralAP A, IntegralAP *R) { |
190 | 0 | IntegralAP<Signed> One(1, A.bitWidth()); |
191 | 0 | return sub(A, One, A.bitWidth() + 1, R); |
192 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::decrement(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::decrement(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>*) |
193 | | |
194 | 0 | static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) { |
195 | 0 | return CheckAddSubMulUB<std::plus>(A, B, OpBits, R); |
196 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::add(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::add(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>, unsigned int, clang::interp::IntegralAP<true>*) |
197 | | |
198 | 0 | static bool sub(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) { |
199 | 0 | return CheckAddSubMulUB<std::minus>(A, B, OpBits, R); |
200 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::sub(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::sub(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>, unsigned int, clang::interp::IntegralAP<true>*) |
201 | | |
202 | 0 | static bool mul(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) { |
203 | 0 | return CheckAddSubMulUB<std::multiplies>(A, B, OpBits, R); |
204 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::mul(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::mul(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>, unsigned int, clang::interp::IntegralAP<true>*) |
205 | | |
206 | 0 | static bool rem(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) { |
207 | 0 | if constexpr (Signed) |
208 | 0 | *R = IntegralAP(A.V.srem(B.V)); |
209 | 0 | else |
210 | 0 | *R = IntegralAP(A.V.urem(B.V)); |
211 | 0 | return false; |
212 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::rem(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::rem(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>, unsigned int, clang::interp::IntegralAP<true>*) |
213 | | |
214 | 0 | static bool div(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) { |
215 | 0 | if constexpr (Signed) |
216 | 0 | *R = IntegralAP(A.V.sdiv(B.V)); |
217 | 0 | else |
218 | 0 | *R = IntegralAP(A.V.udiv(B.V)); |
219 | 0 | return false; |
220 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::div(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::div(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>, unsigned int, clang::interp::IntegralAP<true>*) |
221 | | |
222 | | static bool bitAnd(IntegralAP A, IntegralAP B, unsigned OpBits, |
223 | 0 | IntegralAP *R) { |
224 | 0 | *R = IntegralAP(A.V & B.V); |
225 | 0 | return false; |
226 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::bitAnd(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::bitAnd(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>, unsigned int, clang::interp::IntegralAP<true>*) |
227 | | |
228 | | static bool bitOr(IntegralAP A, IntegralAP B, unsigned OpBits, |
229 | 0 | IntegralAP *R) { |
230 | 0 | *R = IntegralAP(A.V | B.V); |
231 | 0 | return false; |
232 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::bitOr(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::bitOr(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>, unsigned int, clang::interp::IntegralAP<true>*) |
233 | | |
234 | | static bool bitXor(IntegralAP A, IntegralAP B, unsigned OpBits, |
235 | 0 | IntegralAP *R) { |
236 | 0 | *R = IntegralAP(A.V ^ B.V); |
237 | 0 | return false; |
238 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::bitXor(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::bitXor(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>, unsigned int, clang::interp::IntegralAP<true>*) |
239 | | |
240 | 0 | static bool neg(const IntegralAP &A, IntegralAP *R) { |
241 | 0 | APInt AI = A.V; |
242 | 0 | AI.negate(); |
243 | 0 | *R = IntegralAP(AI); |
244 | 0 | return false; |
245 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::neg(clang::interp::IntegralAP<false> const&, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::neg(clang::interp::IntegralAP<true> const&, clang::interp::IntegralAP<true>*) |
246 | | |
247 | 0 | static bool comp(IntegralAP A, IntegralAP *R) { |
248 | 0 | *R = IntegralAP(~A.V); |
249 | 0 | return false; |
250 | 0 | } Unexecuted instantiation: clang::interp::IntegralAP<false>::comp(clang::interp::IntegralAP<false>, clang::interp::IntegralAP<false>*) Unexecuted instantiation: clang::interp::IntegralAP<true>::comp(clang::interp::IntegralAP<true>, clang::interp::IntegralAP<true>*) |
251 | | |
252 | | static void shiftLeft(const IntegralAP A, const IntegralAP B, unsigned OpBits, |
253 | 0 | IntegralAP *R) { |
254 | 0 | *R = IntegralAP(A.V.shl(B.V.getZExtValue())); |
255 | 0 | } |
256 | | |
257 | | static void shiftRight(const IntegralAP A, const IntegralAP B, |
258 | 0 | unsigned OpBits, IntegralAP *R) { |
259 | 0 | unsigned ShiftAmount = B.V.getZExtValue(); |
260 | 0 | if constexpr (Signed) |
261 | 0 | *R = IntegralAP(A.V.ashr(ShiftAmount)); |
262 | 0 | else |
263 | 0 | *R = IntegralAP(A.V.lshr(ShiftAmount)); |
264 | 0 | } |
265 | | |
266 | | private: |
267 | | template <template <typename T> class Op> |
268 | | static bool CheckAddSubMulUB(const IntegralAP &A, const IntegralAP &B, |
269 | 0 | unsigned BitWidth, IntegralAP *R) { |
270 | 0 | if constexpr (!Signed) { |
271 | 0 | R->V = Op<APInt>{}(A.V, B.V); |
272 | 0 | return false; |
273 | 0 | } |
274 | | |
275 | 0 | const APSInt &LHS = A.toAPSInt(); |
276 | 0 | const APSInt &RHS = B.toAPSInt(); |
277 | 0 | APSInt Value = Op<APSInt>{}(LHS.extend(BitWidth), RHS.extend(BitWidth)); |
278 | 0 | APSInt Result = Value.trunc(LHS.getBitWidth()); |
279 | 0 | R->V = Result; |
280 | |
|
281 | 0 | return Result.extend(BitWidth) != Value; |
282 | 0 | } Unexecuted instantiation: bool clang::interp::IntegralAP<false>::CheckAddSubMulUB<std::__1::plus>(clang::interp::IntegralAP<false> const&, clang::interp::IntegralAP<false> const&, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: bool clang::interp::IntegralAP<true>::CheckAddSubMulUB<std::__1::plus>(clang::interp::IntegralAP<true> const&, clang::interp::IntegralAP<true> const&, unsigned int, clang::interp::IntegralAP<true>*) Unexecuted instantiation: bool clang::interp::IntegralAP<false>::CheckAddSubMulUB<std::__1::minus>(clang::interp::IntegralAP<false> const&, clang::interp::IntegralAP<false> const&, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: bool clang::interp::IntegralAP<true>::CheckAddSubMulUB<std::__1::minus>(clang::interp::IntegralAP<true> const&, clang::interp::IntegralAP<true> const&, unsigned int, clang::interp::IntegralAP<true>*) Unexecuted instantiation: bool clang::interp::IntegralAP<false>::CheckAddSubMulUB<std::__1::multiplies>(clang::interp::IntegralAP<false> const&, clang::interp::IntegralAP<false> const&, unsigned int, clang::interp::IntegralAP<false>*) Unexecuted instantiation: bool clang::interp::IntegralAP<true>::CheckAddSubMulUB<std::__1::multiplies>(clang::interp::IntegralAP<true> const&, clang::interp::IntegralAP<true> const&, unsigned int, clang::interp::IntegralAP<true>*) |
283 | | }; |
284 | | |
285 | | template <bool Signed> |
286 | | inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, |
287 | 0 | IntegralAP<Signed> I) { |
288 | 0 | I.print(OS); |
289 | 0 | return OS; |
290 | 0 | } Unexecuted instantiation: llvm::raw_ostream& clang::interp::operator<< <false>(llvm::raw_ostream&, clang::interp::IntegralAP<false>) Unexecuted instantiation: llvm::raw_ostream& clang::interp::operator<< <true>(llvm::raw_ostream&, clang::interp::IntegralAP<true>) |
291 | | |
292 | | } // namespace interp |
293 | | } // namespace clang |
294 | | |
295 | | #endif |