llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> At least the ones we visit directly via the visitor. This was always the case, except for BinaryOperator and CastExpr. --- Patch is 40.56 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/185379.diff 1 Files Affected: - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+213-216) ``````````diff diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 42d137f097760..5af5e07f87a61 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -210,19 +210,19 @@ template <class Emitter> class LocOverrideScope final { } // namespace clang template <class Emitter> -bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { - const Expr *SubExpr = CE->getSubExpr(); +bool Compiler<Emitter>::VisitCastExpr(const CastExpr *E) { + const Expr *SubExpr = E->getSubExpr(); if (DiscardResult) return this->delegate(SubExpr); - switch (CE->getCastKind()) { + switch (E->getCastKind()) { case CK_LValueToRValue: { - if (ToLValue && CE->getType()->isPointerType()) + if (ToLValue && E->getType()->isPointerType()) return this->delegate(SubExpr); if (SubExpr->getType().isVolatileQualified()) - return this->emitInvalidCast(CastKind::Volatile, /*Fatal=*/true, CE); + return this->emitInvalidCast(CastKind::Volatile, /*Fatal=*/true, E); OptPrimType SubExprT = classify(SubExpr->getType()); // Try to load the value directly. This is purely a performance @@ -235,12 +235,12 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { if (!IsReference) { if (Context::shouldBeGloballyIndexed(D)) { if (auto GlobalIndex = P.getGlobal(D)) - return this->emitGetGlobal(*SubExprT, *GlobalIndex, CE); + return this->emitGetGlobal(*SubExprT, *GlobalIndex, E); } else if (auto It = Locals.find(D); It != Locals.end()) { - return this->emitGetLocal(*SubExprT, It->second.Offset, CE); + return this->emitGetLocal(*SubExprT, It->second.Offset, E); } else if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) { if (auto It = this->Params.find(PVD); It != this->Params.end()) { - return this->emitGetParam(*SubExprT, It->second.Offset, CE); + return this->emitGetParam(*SubExprT, It->second.Offset, E); } } } @@ -252,7 +252,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { UnsignedOrNone LocalIndex = allocateLocal(SubExpr); if (!LocalIndex) return false; - if (!this->emitGetPtrLocal(*LocalIndex, CE)) + if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; } @@ -260,18 +260,18 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { return false; if (SubExprT) - return this->emitLoadPop(*SubExprT, CE); + return this->emitLoadPop(*SubExprT, E); // If the subexpr type is not primitive, we need to perform a copy here. // This happens for example in C when dereferencing a pointer of struct // type. - return this->emitMemcpy(CE); + return this->emitMemcpy(E); } case CK_DerivedToBaseMemberPointer: { - if (CE->containsErrors()) + if (E->containsErrors()) return false; - assert(classifyPrim(CE) == PT_MemberPtr); + assert(classifyPrim(E) == PT_MemberPtr); assert(classifyPrim(SubExpr) == PT_MemberPtr); if (!this->delegate(SubExpr)) @@ -280,11 +280,11 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { const CXXRecordDecl *CurDecl = SubExpr->getType() ->castAs<MemberPointerType>() ->getMostRecentCXXRecordDecl(); - for (const CXXBaseSpecifier *B : CE->path()) { + for (const CXXBaseSpecifier *B : E->path()) { const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl(); unsigned DerivedOffset = Ctx.collectBaseOffset(ToDecl, CurDecl); - if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, CE)) + if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E)) return false; CurDecl = ToDecl; } @@ -293,9 +293,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { } case CK_BaseToDerivedMemberPointer: { - if (CE->containsErrors()) + if (E->containsErrors()) return false; - assert(classifyPrim(CE) == PT_MemberPtr); + assert(classifyPrim(E) == PT_MemberPtr); assert(classifyPrim(SubExpr) == PT_MemberPtr); if (!this->delegate(SubExpr)) @@ -308,23 +308,22 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { // order, so iterate backwards. The CXXBaseSpecifier also provides us with // the wrong end of the derived->base arc, so stagger the path by one class. typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter; - for (ReverseIter PathI(CE->path_end() - 1), PathE(CE->path_begin()); + for (ReverseIter PathI(E->path_end() - 1), PathE(E->path_begin()); PathI != PathE; ++PathI) { const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl(); unsigned DerivedOffset = Ctx.collectBaseOffset(CurDecl, ToDecl); - if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, CE)) + if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E)) return false; CurDecl = ToDecl; } - const CXXRecordDecl *ToDecl = CE->getType() - ->castAs<MemberPointerType>() - ->getMostRecentCXXRecordDecl(); + const CXXRecordDecl *ToDecl = + E->getType()->castAs<MemberPointerType>()->getMostRecentCXXRecordDecl(); assert(ToDecl != CurDecl); unsigned DerivedOffset = Ctx.collectBaseOffset(CurDecl, ToDecl); - if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, CE)) + if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E)) return false; return true; @@ -344,15 +343,15 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { // FIXME: We can express a series of non-virtual casts as a single // GetPtrBasePop op. QualType CurType = SubExpr->getType(); - for (const CXXBaseSpecifier *B : CE->path()) { + for (const CXXBaseSpecifier *B : E->path()) { if (B->isVirtual()) { - if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), CE)) + if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E)) return false; CurType = B->getType(); } else { unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType); if (!this->emitGetPtrBasePop( - DerivedOffset, /*NullOK=*/CE->getType()->isPointerType(), CE)) + DerivedOffset, /*NullOK=*/E->getType()->isPointerType(), E)) return false; CurType = B->getType(); } @@ -365,62 +364,62 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { if (!this->delegate(SubExpr)) return false; unsigned DerivedOffset = - collectBaseOffset(SubExpr->getType(), CE->getType()); + collectBaseOffset(SubExpr->getType(), E->getType()); - const Type *TargetType = CE->getType().getTypePtr(); + const Type *TargetType = E->getType().getTypePtr(); if (TargetType->isPointerOrReferenceType()) TargetType = TargetType->getPointeeType().getTypePtr(); return this->emitGetPtrDerivedPop(DerivedOffset, - /*NullOK=*/CE->getType()->isPointerType(), - TargetType, CE); + /*NullOK=*/E->getType()->isPointerType(), + TargetType, E); } case CK_FloatingCast: { // HLSL uses CK_FloatingCast to cast between vectors. if (!SubExpr->getType()->isFloatingType() || - !CE->getType()->isFloatingType()) + !E->getType()->isFloatingType()) return false; if (!this->visit(SubExpr)) return false; - const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType()); - return this->emitCastFP(TargetSemantics, getRoundingMode(CE), CE); + const auto *TargetSemantics = &Ctx.getFloatSemantics(E->getType()); + return this->emitCastFP(TargetSemantics, getRoundingMode(E), E); } case CK_IntegralToFloating: { - if (!CE->getType()->isRealFloatingType()) + if (!E->getType()->isRealFloatingType()) return false; if (!this->visit(SubExpr)) return false; - const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType()); - return this->emitCastIntegralFloating( - classifyPrim(SubExpr), TargetSemantics, getFPOptions(CE), CE); + const auto *TargetSemantics = &Ctx.getFloatSemantics(E->getType()); + return this->emitCastIntegralFloating(classifyPrim(SubExpr), + TargetSemantics, getFPOptions(E), E); } case CK_FloatingToBoolean: { if (!SubExpr->getType()->isRealFloatingType() || - !CE->getType()->isBooleanType()) + !E->getType()->isBooleanType()) return false; if (const auto *FL = dyn_cast<FloatingLiteral>(SubExpr)) - return this->emitConstBool(FL->getValue().isNonZero(), CE); + return this->emitConstBool(FL->getValue().isNonZero(), E); if (!this->visit(SubExpr)) return false; - return this->emitCastFloatingIntegralBool(getFPOptions(CE), CE); + return this->emitCastFloatingIntegralBool(getFPOptions(E), E); } case CK_FloatingToIntegral: { - if (!CE->getType()->isIntegralOrEnumerationType()) + if (!E->getType()->isIntegralOrEnumerationType()) return false; if (!this->visit(SubExpr)) return false; - PrimType ToT = classifyPrim(CE); + PrimType ToT = classifyPrim(E); if (ToT == PT_IntAP) - return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(CE->getType()), - getFPOptions(CE), CE); + return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(E->getType()), + getFPOptions(E), E); if (ToT == PT_IntAPS) - return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(CE->getType()), - getFPOptions(CE), CE); + return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(E->getType()), + getFPOptions(E), E); - return this->emitCastFloatingIntegral(ToT, getFPOptions(CE), CE); + return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E); } case CK_NullToPointer: @@ -428,7 +427,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { if (!this->discard(SubExpr)) return false; const Descriptor *Desc = nullptr; - const QualType PointeeType = CE->getType()->getPointeeType(); + const QualType PointeeType = E->getType()->getPointeeType(); if (!PointeeType.isNull()) { if (OptPrimType T = classify(PointeeType)) Desc = P.createDescriptor(SubExpr, *T); @@ -437,8 +436,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { std::nullopt, /*IsConst=*/true); } - uint64_t Val = Ctx.getASTContext().getTargetNullPointerValue(CE->getType()); - return this->emitNull(classifyPrim(CE->getType()), Val, Desc, CE); + uint64_t Val = Ctx.getASTContext().getTargetNullPointerValue(E->getType()); + return this->emitNull(classifyPrim(E->getType()), Val, Desc, E); } case CK_PointerToIntegral: { @@ -448,24 +447,22 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { // If SubExpr doesn't result in a pointer, make it one. if (PrimType FromT = classifyPrim(SubExpr->getType()); FromT != PT_Ptr) { assert(isPtrType(FromT)); - if (!this->emitDecayPtr(FromT, PT_Ptr, CE)) + if (!this->emitDecayPtr(FromT, PT_Ptr, E)) return false; } - PrimType T = classifyPrim(CE->getType()); + PrimType T = classifyPrim(E->getType()); if (T == PT_IntAP) - return this->emitCastPointerIntegralAP(Ctx.getBitWidth(CE->getType()), - CE); + return this->emitCastPointerIntegralAP(Ctx.getBitWidth(E->getType()), E); if (T == PT_IntAPS) - return this->emitCastPointerIntegralAPS(Ctx.getBitWidth(CE->getType()), - CE); - return this->emitCastPointerIntegral(T, CE); + return this->emitCastPointerIntegralAPS(Ctx.getBitWidth(E->getType()), E); + return this->emitCastPointerIntegral(T, E); } case CK_ArrayToPointerDecay: { if (!this->visit(SubExpr)) return false; - return this->emitArrayDecay(CE); + return this->emitArrayDecay(E); } case CK_IntegralToPointer: { @@ -476,17 +473,17 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { // FIXME: I think the discard is wrong since the int->ptr cast might cause a // diagnostic. PrimType T = classifyPrim(IntType); - QualType PtrType = CE->getType(); + QualType PtrType = E->getType(); const Descriptor *Desc; if (OptPrimType T = classify(PtrType->getPointeeType())) Desc = P.createDescriptor(SubExpr, *T); else if (PtrType->getPointeeType()->isVoidType()) Desc = nullptr; else - Desc = P.createDescriptor(CE, PtrType->getPointeeType().getTypePtr(), + Desc = P.createDescriptor(E, PtrType->getPointeeType().getTypePtr(), Descriptor::InlineDescMD, /*IsConst=*/true); - if (!this->emitGetIntPtr(T, Desc, CE)) + if (!this->emitGetIntPtr(T, Desc, E)) return false; PrimType DestPtrT = classifyPrim(PtrType); @@ -494,7 +491,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { return true; // In case we're converting the integer to a non-Pointer. - return this->emitDecayPtr(PT_Ptr, DestPtrT, CE); + return this->emitDecayPtr(PT_Ptr, DestPtrT, E); } case CK_AtomicToNonAtomic: @@ -508,22 +505,22 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { return this->delegate(SubExpr); case CK_BitCast: { - if (CE->containsErrors()) + if (E->containsErrors()) return false; - QualType CETy = CE->getType(); + QualType ETy = E->getType(); // Reject bitcasts to atomic types. - if (CETy->isAtomicType()) { + if (ETy->isAtomicType()) { if (!this->discard(SubExpr)) return false; - return this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/true, CE); + return this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/true, E); } QualType SubExprTy = SubExpr->getType(); OptPrimType FromT = classify(SubExprTy); // Casts from integer/vector to vector. - if (CE->getType()->isVectorType()) - return this->emitBuiltinBitCast(CE); + if (E->getType()->isVectorType()) + return this->emitBuiltinBitCast(E); - OptPrimType ToT = classify(CE->getType()); + OptPrimType ToT = classify(E->getType()); if (!FromT || !ToT) return false; @@ -531,29 +528,29 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { assert(isPtrType(*ToT)); bool SrcIsVoidPtr = SubExprTy->isVoidPointerType(); if (FromT == ToT) { - if (CE->getType()->isVoidPointerType() && + if (E->getType()->isVoidPointerType() && !SubExprTy->isFunctionPointerType()) { return this->delegate(SubExpr); } if (!this->visit(SubExpr)) return false; - if (!this->emitCheckBitCast(CETy->getPointeeType().getTypePtr(), - SrcIsVoidPtr, CE)) + if (!this->emitCheckBitCast(ETy->getPointeeType().getTypePtr(), + SrcIsVoidPtr, E)) return false; - if (CE->getType()->isFunctionPointerType() || + if (E->getType()->isFunctionPointerType() || SubExprTy->isFunctionPointerType()) { - return this->emitFnPtrCast(CE); + return this->emitFnPtrCast(E); } if (FromT == PT_Ptr) - return this->emitPtrPtrCast(SubExprTy->isVoidPointerType(), CE); + return this->emitPtrPtrCast(SubExprTy->isVoidPointerType(), E); return true; } if (!this->visit(SubExpr)) return false; - return this->emitDecayPtr(*FromT, *ToT, CE); + return this->emitDecayPtr(*FromT, *ToT, E); } case CK_IntegralToBoolean: case CK_FixedPointToBoolean: { @@ -563,25 +560,25 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { return false; if (const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) - return this->emitConst(IL->getValue(), CE); + return this->emitConst(IL->getValue(), E); if (!this->visit(SubExpr)) return false; - return this->emitCast(*FromT, classifyPrim(CE), CE); + return this->emitCast(*FromT, classifyPrim(E), E); } case CK_BooleanToSignedIntegral: case CK_IntegralCast: { OptPrimType FromT = classify(SubExpr->getType()); - OptPrimType ToT = classify(CE->getType()); + OptPrimType ToT = classify(E->getType()); if (!FromT || !ToT) return false; // Try to emit a casted known constant value directly. if (const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) { if (ToT != PT_IntAP && ToT != PT_IntAPS && FromT != PT_IntAP && - FromT != PT_IntAPS && !CE->getType()->isEnumeralType()) + FromT != PT_IntAPS && !E->getType()->isEnumeralType()) return this->emitConst(APSInt(IL->getValue(), !isSignedType(*FromT)), - CE); + E); if (!this->emitConst(IL->getValue(), SubExpr)) return false; } else { @@ -591,28 +588,28 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { // Possibly diagnose casts to enum types if the target type does not // have a fixed size. - if (Ctx.getLangOpts().CPlusPlus && CE->getType()->isEnumeralType()) { - const auto *ED = CE->getType()->castAsEnumDecl(); + if (Ctx.getLangOpts().CPlusPlus && E->getType()->isEnumeralType()) { + const auto *ED = E->getType()->castAsEnumDecl(); if (!ED->isFixed()) { - if (!this->emitCheckEnumValue(*FromT, ED, CE)) + if (!this->emitCheckEnumValue(*FromT, ED, E)) return false; } } if (ToT == PT_IntAP) { - if (!this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE)) + if (!this->emitCastAP(*FromT, Ctx.getBitWidth(E->getType()), E)) return false; } else if (ToT == PT_IntAPS) { - if (!this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE)) + if (!this->emitCastAPS(*FromT, Ctx.getBitWidth(E->getType()), E)) return false; } else { if (FromT == ToT) return true; - if (!this->emitCast(*FromT, *ToT, CE)) + if (!this->emitCast(*FromT, *ToT, E)) return false; } - if (CE->getCastKind() == CK_BooleanToSignedIntegral) - return this->emitNeg(*ToT, CE); + if (E->getCastKind() == CK_BooleanToSignedIntegral) + return this->emitNeg(*ToT, E); return true; } @@ -622,7 +619,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { if (!this->visit(SubExpr)) return false; - return this->emitIsNonNull(PtrT, CE); + return this->emitIsNonNull(PtrT, E); } case CK_IntegralComplexToBoolean: @@ -641,10 +638,10 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { // We're creating a complex value here, so we need to // allocate storage for it. if (!Initializing) { - UnsignedOrNone LocalIndex = allocateTemporary(CE); + UnsignedOrNone LocalIndex = allocateTemporary(E); if (!LocalIndex) return false; - if (!this->emitGetPtrLocal(*LocalIndex, CE)) + if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; } @@ -662,13 +659,13 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { case CK_FloatingComplexCast: case CK_IntegralComplexToFloatingComplex: case CK_FloatingComplexToIntegralComplex: { - assert(CE->getType()->isAnyComplexType()); + assert(E->getType()->isAnyComplexType()); assert(SubExpr->getType()->isAnyComplexType()); if (!Initializing) { - UnsignedOrNone LocalIndex = allocateLocal(CE); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; - if (!this->emitGetPtrLocal(*LocalIndex, CE)) + if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; ... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/185379 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
