diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/AST/Expr.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/AST/Expr.cpp | 191 |
1 files changed, 133 insertions, 58 deletions
diff --git a/contrib/llvm/tools/clang/lib/AST/Expr.cpp b/contrib/llvm/tools/clang/lib/AST/Expr.cpp index 091e878..14f31d0 100644 --- a/contrib/llvm/tools/clang/lib/AST/Expr.cpp +++ b/contrib/llvm/tools/clang/lib/AST/Expr.cpp @@ -11,7 +11,6 @@ // //===----------------------------------------------------------------------===// -#include "clang/AST/APValue.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" #include "clang/AST/DeclCXX.h" @@ -36,9 +35,33 @@ #include <cstring> using namespace clang; -const CXXRecordDecl *Expr::getBestDynamicClassType() const { - const Expr *E = ignoreParenBaseCasts(); +const Expr *Expr::getBestDynamicClassTypeExpr() const { + const Expr *E = this; + while (true) { + E = E->ignoreParenBaseCasts(); + + // Follow the RHS of a comma operator. + if (auto *BO = dyn_cast<BinaryOperator>(E)) { + if (BO->getOpcode() == BO_Comma) { + E = BO->getRHS(); + continue; + } + } + + // Step into initializer for materialized temporaries. + if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) { + E = MTE->GetTemporaryExpr(); + continue; + } + + break; + } + + return E; +} +const CXXRecordDecl *Expr::getBestDynamicClassType() const { + const Expr *E = getBestDynamicClassTypeExpr(); QualType DerivedType = E->getType(); if (const PointerType *PTy = DerivedType->getAs<PointerType>()) DerivedType = PTy->getPointeeType(); @@ -403,7 +426,7 @@ DeclRefExpr *DeclRefExpr::Create(const ASTContext &Context, HasTemplateKWAndArgsInfo ? 1 : 0, TemplateArgs ? TemplateArgs->size() : 0); - void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); + void *Mem = Context.Allocate(Size, alignof(DeclRefExpr)); return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D, RefersToEnclosingVariableOrCapture, NameInfo, FoundD, TemplateArgs, T, VK); @@ -420,7 +443,7 @@ DeclRefExpr *DeclRefExpr::CreateEmpty(const ASTContext &Context, ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( HasQualifier ? 1 : 0, HasFoundDecl ? 1 : 0, HasTemplateKWAndArgsInfo, NumTemplateArgs); - void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); + void *Mem = Context.Allocate(Size, alignof(DeclRefExpr)); return new (Mem) DeclRefExpr(EmptyShell()); } @@ -495,20 +518,21 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { } return ""; } - if (auto *BD = dyn_cast<BlockDecl>(CurrentDecl)) { - std::unique_ptr<MangleContext> MC; - MC.reset(Context.createMangleContext()); - SmallString<256> Buffer; - llvm::raw_svector_ostream Out(Buffer); + if (isa<BlockDecl>(CurrentDecl)) { + // For blocks we only emit something if it is enclosed in a function + // For top-level block we'd like to include the name of variable, but we + // don't have it at this point. auto DC = CurrentDecl->getDeclContext(); if (DC->isFileContext()) - MC->mangleGlobalBlock(BD, /*ID*/ nullptr, Out); - else if (const auto *CD = dyn_cast<CXXConstructorDecl>(DC)) - MC->mangleCtorBlock(CD, /*CT*/ Ctor_Complete, BD, Out); - else if (const auto *DD = dyn_cast<CXXDestructorDecl>(DC)) - MC->mangleDtorBlock(DD, /*DT*/ Dtor_Complete, BD, Out); - else - MC->mangleBlock(DC, BD, Out); + return ""; + + SmallString<256> Buffer; + llvm::raw_svector_ostream Out(Buffer); + if (auto *DCBlock = dyn_cast<BlockDecl>(DC)) + // For nested blocks, propagate up to the parent. + Out << ComputeName(IT, DCBlock); + else if (auto *DCDecl = dyn_cast<Decl>(DC)) + Out << ComputeName(IT, DCDecl) << "_block_invoke"; return Out.str(); } if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { @@ -538,12 +562,13 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { FT = dyn_cast<FunctionProtoType>(AFT); if (IT == FuncSig) { - switch (FT->getCallConv()) { + switch (AFT->getCallConv()) { case CC_C: POut << "__cdecl "; break; case CC_X86StdCall: POut << "__stdcall "; break; case CC_X86FastCall: POut << "__fastcall "; break; case CC_X86ThisCall: POut << "__thiscall "; break; case CC_X86VectorCall: POut << "__vectorcall "; break; + case CC_X86RegCall: POut << "__regcall "; break; // Only bother printing the conventions that MSVC knows about. default: break; } @@ -561,12 +586,15 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { if (FT->isVariadic()) { if (FD->getNumParams()) POut << ", "; POut << "..."; + } else if ((IT == FuncSig || !Context.getLangOpts().CPlusPlus) && + !Decl->getNumParams()) { + POut << "void"; } } POut << ")"; if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { - const FunctionType *FT = MD->getType()->castAs<FunctionType>(); + assert(FT && "We must have a written prototype in this case."); if (FT->isConst()) POut << " const"; if (FT->isVolatile()) @@ -756,33 +784,33 @@ FloatingLiteral::Create(const ASTContext &C, EmptyShell Empty) { const llvm::fltSemantics &FloatingLiteral::getSemantics() const { switch(FloatingLiteralBits.Semantics) { case IEEEhalf: - return llvm::APFloat::IEEEhalf; + return llvm::APFloat::IEEEhalf(); case IEEEsingle: - return llvm::APFloat::IEEEsingle; + return llvm::APFloat::IEEEsingle(); case IEEEdouble: - return llvm::APFloat::IEEEdouble; + return llvm::APFloat::IEEEdouble(); case x87DoubleExtended: - return llvm::APFloat::x87DoubleExtended; + return llvm::APFloat::x87DoubleExtended(); case IEEEquad: - return llvm::APFloat::IEEEquad; + return llvm::APFloat::IEEEquad(); case PPCDoubleDouble: - return llvm::APFloat::PPCDoubleDouble; + return llvm::APFloat::PPCDoubleDouble(); } llvm_unreachable("Unrecognised floating semantics"); } void FloatingLiteral::setSemantics(const llvm::fltSemantics &Sem) { - if (&Sem == &llvm::APFloat::IEEEhalf) + if (&Sem == &llvm::APFloat::IEEEhalf()) FloatingLiteralBits.Semantics = IEEEhalf; - else if (&Sem == &llvm::APFloat::IEEEsingle) + else if (&Sem == &llvm::APFloat::IEEEsingle()) FloatingLiteralBits.Semantics = IEEEsingle; - else if (&Sem == &llvm::APFloat::IEEEdouble) + else if (&Sem == &llvm::APFloat::IEEEdouble()) FloatingLiteralBits.Semantics = IEEEdouble; - else if (&Sem == &llvm::APFloat::x87DoubleExtended) + else if (&Sem == &llvm::APFloat::x87DoubleExtended()) FloatingLiteralBits.Semantics = x87DoubleExtended; - else if (&Sem == &llvm::APFloat::IEEEquad) + else if (&Sem == &llvm::APFloat::IEEEquad()) FloatingLiteralBits.Semantics = IEEEquad; - else if (&Sem == &llvm::APFloat::PPCDoubleDouble) + else if (&Sem == &llvm::APFloat::PPCDoubleDouble()) FloatingLiteralBits.Semantics = PPCDoubleDouble; else llvm_unreachable("Unknown floating semantics"); @@ -794,7 +822,7 @@ void FloatingLiteral::setSemantics(const llvm::fltSemantics &Sem) { double FloatingLiteral::getValueAsApproximateDouble() const { llvm::APFloat V = getValue(); bool ignored; - V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, + V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven, &ignored); return V.convertToDouble(); } @@ -832,9 +860,9 @@ StringLiteral *StringLiteral::Create(const ASTContext &C, StringRef Str, // Allocate enough space for the StringLiteral plus an array of locations for // any concatenated string tokens. - void *Mem = C.Allocate(sizeof(StringLiteral)+ - sizeof(SourceLocation)*(NumStrs-1), - llvm::alignOf<StringLiteral>()); + void *Mem = + C.Allocate(sizeof(StringLiteral) + sizeof(SourceLocation) * (NumStrs - 1), + alignof(StringLiteral)); StringLiteral *SL = new (Mem) StringLiteral(Ty); // OPTIMIZE: could allocate this appended to the StringLiteral. @@ -850,9 +878,9 @@ StringLiteral *StringLiteral::Create(const ASTContext &C, StringRef Str, StringLiteral *StringLiteral::CreateEmpty(const ASTContext &C, unsigned NumStrs) { - void *Mem = C.Allocate(sizeof(StringLiteral)+ - sizeof(SourceLocation)*(NumStrs-1), - llvm::alignOf<StringLiteral>()); + void *Mem = + C.Allocate(sizeof(StringLiteral) + sizeof(SourceLocation) * (NumStrs - 1), + alignof(StringLiteral)); StringLiteral *SL = new (Mem) StringLiteral(QualType()); SL->CharByteWidth = 0; SL->Length = 0; @@ -944,10 +972,13 @@ void StringLiteral::outputString(raw_ostream &OS) const { // Handle some common non-printable cases to make dumps prettier. case '\\': OS << "\\\\"; break; case '"': OS << "\\\""; break; - case '\n': OS << "\\n"; break; - case '\t': OS << "\\t"; break; case '\a': OS << "\\a"; break; case '\b': OS << "\\b"; break; + case '\f': OS << "\\f"; break; + case '\n': OS << "\\n"; break; + case '\r': OS << "\\r"; break; + case '\t': OS << "\\t"; break; + case '\v': OS << "\\v"; break; } } OS << '"'; @@ -1182,8 +1213,16 @@ void CallExpr::updateDependenciesFromArg(Expr *Arg) { ExprBits.ContainsUnexpandedParameterPack = true; } +FunctionDecl *CallExpr::getDirectCallee() { + return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); +} + Decl *CallExpr::getCalleeDecl() { - Expr *CEE = getCallee()->IgnoreParenImpCasts(); + return getCallee()->getReferencedDeclOfCallee(); +} + +Decl *Expr::getReferencedDeclOfCallee() { + Expr *CEE = IgnoreParenImpCasts(); while (SubstNonTypeTemplateParmExpr *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) { @@ -1206,10 +1245,6 @@ Decl *CallExpr::getCalleeDecl() { return nullptr; } -FunctionDecl *CallExpr::getDirectCallee() { - return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); -} - /// setNumArgs - This changes the number of arguments present in this call. /// Any orphaned expressions are deleted by this, and any new operands are set /// to null. @@ -1417,7 +1452,7 @@ MemberExpr *MemberExpr::Create( HasTemplateKWAndArgsInfo ? 1 : 0, targs ? targs->size() : 0); - void *Mem = C.Allocate(Size, llvm::alignOf<MemberExpr>()); + void *Mem = C.Allocate(Size, alignof(MemberExpr)); MemberExpr *E = new (Mem) MemberExpr(base, isarrow, OperatorLoc, memberdecl, nameinfo, ty, vk, ok); @@ -1570,6 +1605,8 @@ bool CastExpr::CastConsistency() const { case CK_ARCReclaimReturnedObject: case CK_ARCExtendBlockObject: case CK_ZeroToOCLEvent: + case CK_ZeroToOCLQueue: + case CK_IntToOCLSampler: assert(!getType()->isBooleanType() && "unheralded conversion to bool"); goto CheckNoBasePath; @@ -1830,6 +1867,24 @@ bool InitListExpr::isStringLiteralInit() const { return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init); } +bool InitListExpr::isTransparent() const { + assert(isSemanticForm() && "syntactic form never semantically transparent"); + + // A glvalue InitListExpr is always just sugar. + if (isGLValue()) { + assert(getNumInits() == 1 && "multiple inits in glvalue init list"); + return true; + } + + // Otherwise, we're sugar if and only if we have exactly one initializer that + // is of the same type. + if (getNumInits() != 1 || !getInit(0)) + return false; + + return getType().getCanonicalType() == + getInit(0)->getType().getCanonicalType(); +} + SourceLocation InitListExpr::getLocStart() const { if (InitListExpr *SyntacticForm = getSyntacticForm()) return SyntacticForm->getLocStart(); @@ -2212,12 +2267,15 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, // effects (e.g. a placement new with an uninitialized POD). case CXXDeleteExprClass: return false; + case MaterializeTemporaryExprClass: + return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() + ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); case CXXBindTemporaryExprClass: - return (cast<CXXBindTemporaryExpr>(this) - ->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); + return cast<CXXBindTemporaryExpr>(this)->getSubExpr() + ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); case ExprWithCleanupsClass: - return (cast<ExprWithCleanups>(this) - ->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); + return cast<ExprWithCleanups>(this)->getSubExpr() + ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); } } @@ -2748,7 +2806,8 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef, CE->getCastKind() == CK_ToUnion || CE->getCastKind() == CK_ConstructorConversion || CE->getCastKind() == CK_NonAtomicToAtomic || - CE->getCastKind() == CK_AtomicToNonAtomic) + CE->getCastKind() == CK_AtomicToNonAtomic || + CE->getCastKind() == CK_IntToOCLSampler) return CE->getSubExpr()->isConstantInitializer(Ctx, false, Culprit); break; @@ -2843,6 +2902,7 @@ bool Expr::HasSideEffects(const ASTContext &Ctx, case UnaryExprOrTypeTraitExprClass: case AddrLabelExprClass: case GNUNullExprClass: + case ArrayInitIndexExprClass: case NoInitExprClass: case CXXBoolLiteralExprClass: case CXXNullPtrLiteralExprClass: @@ -2919,6 +2979,7 @@ bool Expr::HasSideEffects(const ASTContext &Ctx, case ExtVectorElementExprClass: case DesignatedInitExprClass: case DesignatedInitUpdateExprClass: + case ArrayInitLoopExprClass: case ParenListExprClass: case CXXPseudoDestructorExprClass: case CXXStdInitializerListExprClass: @@ -3307,11 +3368,16 @@ FieldDecl *Expr::getSourceBitField() { if (Ivar->isBitField()) return Ivar; - if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) + if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) { if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) if (Field->isBitField()) return Field; + if (BindingDecl *BD = dyn_cast<BindingDecl>(DeclRef->getDecl())) + if (Expr *E = BD->getBinding()) + return E->getSourceBitField(); + } + if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) { if (BinOp->isAssignmentOp() && BinOp->getLHS()) return BinOp->getLHS()->getSourceBitField(); @@ -3328,6 +3394,7 @@ FieldDecl *Expr::getSourceBitField() { } bool Expr::refersToVectorElement() const { + // FIXME: Why do we not just look at the ObjectKind here? const Expr *E = this->IgnoreParens(); while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { @@ -3344,6 +3411,11 @@ bool Expr::refersToVectorElement() const { if (isa<ExtVectorElementExpr>(E)) return true; + if (auto *DRE = dyn_cast<DeclRefExpr>(E)) + if (auto *BD = dyn_cast<BindingDecl>(DRE->getDecl())) + if (auto *E = BD->getBinding()) + return E->refersToVectorElement(); + return false; } @@ -3396,8 +3468,11 @@ bool ExtVectorElementExpr::containsDuplicateElements() const { void ExtVectorElementExpr::getEncodedElementAccess( SmallVectorImpl<uint32_t> &Elts) const { StringRef Comp = Accessor->getName(); - if (Comp[0] == 's' || Comp[0] == 'S') + bool isNumericAccessor = false; + if (Comp[0] == 's' || Comp[0] == 'S') { Comp = Comp.substr(1); + isNumericAccessor = true; + } bool isHi = Comp == "hi"; bool isLo = Comp == "lo"; @@ -3416,7 +3491,7 @@ void ExtVectorElementExpr::getEncodedElementAccess( else if (isOdd) Index = 2 * i + 1; else - Index = ExtVectorType::getAccessorIdx(Comp[i]); + Index = ExtVectorType::getAccessorIdx(Comp[i], isNumericAccessor); Elts.push_back(Index); } @@ -3589,7 +3664,7 @@ DesignatedInitExpr::Create(const ASTContext &C, SourceLocation ColonOrEqualLoc, bool UsesColonSyntax, Expr *Init) { void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(IndexExprs.size() + 1), - llvm::alignOf<DesignatedInitExpr>()); + alignof(DesignatedInitExpr)); return new (Mem) DesignatedInitExpr(C, C.VoidTy, Designators, ColonOrEqualLoc, UsesColonSyntax, IndexExprs, Init); @@ -3598,7 +3673,7 @@ DesignatedInitExpr::Create(const ASTContext &C, DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(const ASTContext &C, unsigned NumIndexExprs) { void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(NumIndexExprs + 1), - llvm::alignOf<DesignatedInitExpr>()); + alignof(DesignatedInitExpr)); return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); } @@ -3738,7 +3813,7 @@ PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &Context, unsigned numSemanticExprs) { void *buffer = Context.Allocate(totalSizeToAlloc<Expr *>(1 + numSemanticExprs), - llvm::alignOf<PseudoObjectExpr>()); + alignof(PseudoObjectExpr)); return new(buffer) PseudoObjectExpr(sh, numSemanticExprs); } @@ -3766,7 +3841,7 @@ PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &C, Expr *syntax, } void *buffer = C.Allocate(totalSizeToAlloc<Expr *>(semantics.size() + 1), - llvm::alignOf<PseudoObjectExpr>()); + alignof(PseudoObjectExpr)); return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics, resultIndex); } |