diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-04-16 13:21:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-16 13:21:25 +0200 |
commit | 2d63faead4e6339e679ab62113f47112d67a5b06 (patch) | |
tree | aecc1c192d59922469337f1ef7b64b1b0fc8d210 /clang/lib/AST/ByteCode | |
parent | 1e61b374ba3ba2891dc1abda732b0b9263216785 (diff) | |
download | llvm-2d63faead4e6339e679ab62113f47112d67a5b06.zip llvm-2d63faead4e6339e679ab62113f47112d67a5b06.tar.gz llvm-2d63faead4e6339e679ab62113f47112d67a5b06.tar.bz2 |
[clang][bytecode][NFC] Remove PT_FnPtr (#135947)
We don't need this anymore since we don't return it from classify()
anymore.
Diffstat (limited to 'clang/lib/AST/ByteCode')
-rw-r--r-- | clang/lib/AST/ByteCode/Compiler.cpp | 15 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/Disasm.cpp | 2 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/EvalEmitter.cpp | 12 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/FunctionPointer.cpp | 13 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/FunctionPointer.h | 25 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/Interp.h | 21 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/InterpBuiltin.cpp | 6 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/InterpStack.h | 2 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/Opcodes.td | 7 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/Pointer.cpp | 6 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/PrimType.h | 9 |
11 files changed, 20 insertions, 98 deletions
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index afd8d09..157e306 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -4057,7 +4057,7 @@ template <class Emitter> bool Compiler<Emitter>::visitBool(const Expr *E) { return true; // Convert pointers to bool. - if (T == PT_Ptr || T == PT_FnPtr) { + if (T == PT_Ptr) { if (!this->emitNull(*T, 0, nullptr, E)) return false; return this->emitNE(*T, E); @@ -4103,8 +4103,6 @@ bool Compiler<Emitter>::visitZeroInitializer(PrimType T, QualType QT, case PT_Ptr: return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT), nullptr, E); - case PT_FnPtr: - return this->emitNullFnPtr(0, nullptr, E); case PT_MemberPtr: return this->emitNullMemberPtr(0, nullptr, E); case PT_Float: @@ -4255,7 +4253,6 @@ bool Compiler<Emitter>::emitConst(T Value, PrimType Ty, const Expr *E) { case PT_Bool: return this->emitConstBool(Value, E); case PT_Ptr: - case PT_FnPtr: case PT_MemberPtr: case PT_Float: case PT_IntAP: @@ -4956,7 +4953,7 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) { // If we know the callee already, check the known parametrs for nullability. if (FuncDecl && NonNullArgs[ArgIndex]) { PrimType ArgT = classify(Arg).value_or(PT_Ptr); - if (ArgT == PT_Ptr || ArgT == PT_FnPtr) { + if (ArgT == PT_Ptr) { if (!this->emitCheckNonNullArg(ArgT, Arg)) return false; } @@ -5997,7 +5994,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) { if (!this->visit(SubExpr)) return false; - if (T == PT_Ptr || T == PT_FnPtr) { + if (T == PT_Ptr) { if (!this->emitIncPtr(E)) return false; @@ -6021,7 +6018,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) { if (!this->visit(SubExpr)) return false; - if (T == PT_Ptr || T == PT_FnPtr) { + if (T == PT_Ptr) { if (!this->emitDecPtr(E)) return false; @@ -6045,7 +6042,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) { if (!this->visit(SubExpr)) return false; - if (T == PT_Ptr || T == PT_FnPtr) { + if (T == PT_Ptr) { if (!this->emitLoadPtr(E)) return false; if (!this->emitConstUint8(1, E)) @@ -6088,7 +6085,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) { if (!this->visit(SubExpr)) return false; - if (T == PT_Ptr || T == PT_FnPtr) { + if (T == PT_Ptr) { if (!this->emitLoadPtr(E)) return false; if (!this->emitConstUint8(1, E)) diff --git a/clang/lib/AST/ByteCode/Disasm.cpp b/clang/lib/AST/ByteCode/Disasm.cpp index 4bdf0f0..83b9af9 100644 --- a/clang/lib/AST/ByteCode/Disasm.cpp +++ b/clang/lib/AST/ByteCode/Disasm.cpp @@ -256,8 +256,6 @@ static const char *primTypeToString(PrimType T) { return "Float"; case PT_Ptr: return "Ptr"; - case PT_FnPtr: - return "FnPtr"; case PT_MemberPtr: return "MemberPtr"; case PT_FixedPoint: diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index a37be38..71d6884 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -142,10 +142,6 @@ bool EvalEmitter::speculate(const CallExpr *E, const LabelTy &EndLabel) { if (T == PT_Ptr) { const auto &Ptr = S.Stk.pop<Pointer>(); return this->emitBool(CheckBCPResult(S, Ptr), E); - } else if (T == PT_FnPtr) { - S.Stk.discard<FunctionPointer>(); - // Never accepted - return this->emitBool(false, E); } // Otherwise, this is fine! @@ -210,14 +206,6 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) { return true; } -template <> bool EvalEmitter::emitRet<PT_FnPtr>(const SourceInfo &Info) { - if (!isActive()) - return true; - - // Function pointers cannot be converted to rvalues. - EvalResult.setFunctionPointer(S.Stk.pop<FunctionPointer>()); - return true; -} bool EvalEmitter::emitRetVoid(const SourceInfo &Info) { EvalResult.setValid(); diff --git a/clang/lib/AST/ByteCode/FunctionPointer.cpp b/clang/lib/AST/ByteCode/FunctionPointer.cpp index 6b0b559..4ab7af1 100644 --- a/clang/lib/AST/ByteCode/FunctionPointer.cpp +++ b/clang/lib/AST/ByteCode/FunctionPointer.cpp @@ -16,27 +16,22 @@ APValue FunctionPointer::toAPValue(const ASTContext &) const { return APValue(static_cast<Expr *>(nullptr), CharUnits::Zero(), {}, /*OnePastTheEnd=*/false, /*IsNull=*/true); - if (!Valid) - return APValue(static_cast<Expr *>(nullptr), - CharUnits::fromQuantity(getIntegerRepresentation()), {}, - /*OnePastTheEnd=*/false, /*IsNull=*/false); - if (Func->getDecl()) - return APValue(Func->getDecl(), CharUnits::fromQuantity(Offset), {}, + return APValue(Func->getDecl(), CharUnits::fromQuantity(0), {}, /*OnePastTheEnd=*/false, /*IsNull=*/false); - return APValue(Func->getExpr(), CharUnits::fromQuantity(Offset), {}, + return APValue(Func->getExpr(), CharUnits::fromQuantity(0), {}, /*OnePastTheEnd=*/false, /*IsNull=*/false); } void FunctionPointer::print(llvm::raw_ostream &OS) const { OS << "FnPtr("; - if (Func && Valid) + if (Func) OS << Func->getName(); else if (Func) OS << reinterpret_cast<uintptr_t>(Func); else OS << "nullptr"; - OS << ") + " << Offset; + OS << ")"; } } // namespace interp diff --git a/clang/lib/AST/ByteCode/FunctionPointer.h b/clang/lib/AST/ByteCode/FunctionPointer.h index e2b45b2..9e8ea2f 100644 --- a/clang/lib/AST/ByteCode/FunctionPointer.h +++ b/clang/lib/AST/ByteCode/FunctionPointer.h @@ -20,24 +20,15 @@ namespace interp { class FunctionPointer final { private: const Function *Func; - uint64_t Offset; - bool Valid; public: FunctionPointer() = default; - FunctionPointer(const Function *Func, uint64_t Offset = 0) - : Func(Func), Offset(Offset), Valid(true) {} - - FunctionPointer(uintptr_t IntVal, const Descriptor *Desc = nullptr) - : Func(reinterpret_cast<const Function *>(IntVal)), Offset(0), - Valid(false) {} + FunctionPointer(const Function *Func) : Func(Func) {} const Function *getFunction() const { return Func; } - uint64_t getOffset() const { return Offset; } bool isZero() const { return !Func; } - bool isValid() const { return Valid; } bool isWeak() const { - if (!Func || !Valid || !Func->getDecl()) + if (!Func || !Func->getDecl()) return false; return Func->getDecl()->isWeak(); @@ -56,20 +47,8 @@ public: uint64_t getIntegerRepresentation() const { return static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Func)); } - - ComparisonCategoryResult compare(const FunctionPointer &RHS) const { - if (Func == RHS.Func && Offset == RHS.Offset) - return ComparisonCategoryResult::Equal; - return ComparisonCategoryResult::Unordered; - } }; -inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, - FunctionPointer FP) { - FP.print(OS); - return OS; -} - } // namespace interp } // namespace clang diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 88a011e..bd58c2a 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -20,7 +20,6 @@ #include "FixedPoint.h" #include "Floating.h" #include "Function.h" -#include "FunctionPointer.h" #include "InterpBuiltinBitCast.h" #include "InterpFrame.h" #include "InterpStack.h" @@ -985,26 +984,6 @@ bool CmpHelperEQ(InterpState &S, CodePtr OpPC, CompareFn Fn) { } template <> -inline bool CmpHelperEQ<FunctionPointer>(InterpState &S, CodePtr OpPC, - CompareFn Fn) { - const auto &RHS = S.Stk.pop<FunctionPointer>(); - const auto &LHS = S.Stk.pop<FunctionPointer>(); - - // We cannot compare against weak declarations at compile time. - for (const auto &FP : {LHS, RHS}) { - if (FP.isWeak()) { - const SourceInfo &Loc = S.Current->getSource(OpPC); - S.FFDiag(Loc, diag::note_constexpr_pointer_weak_comparison) - << FP.toDiagnosticString(S.getASTContext()); - return false; - } - } - - S.Stk.push<Boolean>(Boolean::from(Fn(LHS.compare(RHS)))); - return true; -} - -template <> inline bool CmpHelper<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) { using BoolT = PrimConv<PT_Bool>::T; const Pointer &RHS = S.Stk.pop<Pointer>(); diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index bde416d..d06941b 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -130,7 +130,6 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC, return Ret<X>(S, OpPC); switch (*T) { RET_CASE(PT_Ptr); - RET_CASE(PT_FnPtr); RET_CASE(PT_Float); RET_CASE(PT_Bool); RET_CASE(PT_Sint8); @@ -766,10 +765,7 @@ static bool interp__builtin_addressof(InterpState &S, CodePtr OpPC, assert(Call->getArg(0)->isLValue()); PrimType PtrT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr); - if (PtrT == PT_FnPtr) { - const FunctionPointer &Arg = S.Stk.peek<FunctionPointer>(); - S.Stk.push<FunctionPointer>(Arg); - } else if (PtrT == PT_Ptr) { + if (PtrT == PT_Ptr) { const Pointer &Arg = S.Stk.peek<Pointer>(); S.Stk.push<Pointer>(Arg); } else { diff --git a/clang/lib/AST/ByteCode/InterpStack.h b/clang/lib/AST/ByteCode/InterpStack.h index f7b8c38..0b76f1d 100644 --- a/clang/lib/AST/ByteCode/InterpStack.h +++ b/clang/lib/AST/ByteCode/InterpStack.h @@ -183,8 +183,6 @@ private: return PT_Uint64; else if constexpr (std::is_same_v<T, Floating>) return PT_Float; - else if constexpr (std::is_same_v<T, FunctionPointer>) - return PT_FnPtr; else if constexpr (std::is_same_v<T, IntegralAP<true>>) return PT_IntAP; else if constexpr (std::is_same_v<T, IntegralAP<false>>) diff --git a/clang/lib/AST/ByteCode/Opcodes.td b/clang/lib/AST/ByteCode/Opcodes.td index 798771b..5a9079f 100644 --- a/clang/lib/AST/ByteCode/Opcodes.td +++ b/clang/lib/AST/ByteCode/Opcodes.td @@ -29,7 +29,6 @@ def IntAP : Type; def IntAPS : Type; def Float : Type; def Ptr : Type; -def FnPtr : Type; def MemberPtr : Type; def FixedPoint : Type; @@ -106,9 +105,7 @@ def AluTypeClass : TypeClass { let Types = !listconcat(IntegerTypeClass.Types, [Bool], [FixedPoint]); } -def PtrTypeClass : TypeClass { - let Types = [Ptr, FnPtr, MemberPtr]; -} +def PtrTypeClass : TypeClass { let Types = [Ptr, MemberPtr]; } def NonPtrTypeClass : TypeClass { let Types = !listconcat(IntegerTypeClass.Types, [Bool], [Float], [FixedPoint]); @@ -119,7 +116,7 @@ def AllTypeClass : TypeClass { } def ComparableTypeClass : TypeClass { - let Types = !listconcat(AluTypeClass.Types, [Ptr], [Float], [FnPtr]); + let Types = !listconcat(AluTypeClass.Types, [Ptr], [Float]); } class SingletonTypeClass<Type Ty> : TypeClass { diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index c09d322..c43c0a0 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -155,10 +155,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const { if (isFunctionPointer()) { const FunctionPointer &FP = asFunctionPointer(); if (const FunctionDecl *FD = FP.getFunction()->getDecl()) - return APValue(FD, CharUnits::fromQuantity(FP.getOffset() + Offset), {}, + return APValue(FD, CharUnits::fromQuantity(Offset), {}, /*OnePastTheEnd=*/false, /*IsNull=*/false); - return APValue(FP.getFunction()->getExpr(), - CharUnits::fromQuantity(FP.getOffset() + Offset), {}, + return APValue(FP.getFunction()->getExpr(), CharUnits::fromQuantity(Offset), + {}, /*OnePastTheEnd=*/false, /*IsNull=*/false); } diff --git a/clang/lib/AST/ByteCode/PrimType.h b/clang/lib/AST/ByteCode/PrimType.h index 59c04c4..a3c0b0f 100644 --- a/clang/lib/AST/ByteCode/PrimType.h +++ b/clang/lib/AST/ByteCode/PrimType.h @@ -46,12 +46,11 @@ enum PrimType : unsigned { PT_FixedPoint = 11, PT_Float = 12, PT_Ptr = 13, - PT_FnPtr = 14, - PT_MemberPtr = 15, + PT_MemberPtr = 14, }; inline constexpr bool isPtrType(PrimType T) { - return T == PT_Ptr || T == PT_FnPtr || T == PT_MemberPtr; + return T == PT_Ptr || T == PT_MemberPtr; } enum class CastKind : uint8_t { @@ -114,9 +113,6 @@ template <> struct PrimConv<PT_Bool> { template <> struct PrimConv<PT_Ptr> { using T = Pointer; }; -template <> struct PrimConv<PT_FnPtr> { - using T = FunctionPointer; -}; template <> struct PrimConv<PT_MemberPtr> { using T = MemberPointer; }; @@ -166,7 +162,6 @@ static inline bool aligned(const void *P) { TYPE_SWITCH_CASE(PT_Float, B) \ TYPE_SWITCH_CASE(PT_Bool, B) \ TYPE_SWITCH_CASE(PT_Ptr, B) \ - TYPE_SWITCH_CASE(PT_FnPtr, B) \ TYPE_SWITCH_CASE(PT_MemberPtr, B) \ TYPE_SWITCH_CASE(PT_FixedPoint, B) \ } \ |