diff --git a/clang-tools-extra/clangd/HeuristicResolver.cpp b/clang-tools-extra/clangd/HeuristicResolver.cpp index 37e8f134efdfc53ccacd59c7a700d4f6cc27b97e..97b2005cbccf8c7a591a5cd6da2544a25e56f641 100644 --- a/clang-tools-extra/clangd/HeuristicResolver.cpp +++ b/clang-tools-extra/clangd/HeuristicResolver.cpp @@ -255,6 +255,15 @@ std::vector HeuristicResolver::resolveDependentMember( auto Result = ET->getDecl()->lookup(Name); return {Result.begin(), Result.end()}; } +#if ENABLE_BSC + // fix getPrimaryContext coredump + // Below is the analysis process for C++ + // The shielding may prevent clangd from automatically recognizing generic + // struct members + if (Ctx.getLangOpts().BSC) { + return {}; + } +#endif if (auto *RD = resolveTypeToRecordDecl(T)) { if (!RD->hasDefinition()) return {}; diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp index eb8905a7459cd91b73b2aba8c85ac01f24c97f2a..32ece850bd41fd95ea5eeb443f8886f792735245 100644 --- a/clang/lib/Index/IndexBody.cpp +++ b/clang/lib/Index/IndexBody.cpp @@ -168,6 +168,15 @@ public: dyn_cast_or_null(TN.getAsTemplateDecl()); if (!TD) return true; +#if ENABLE_BSC + // fix getPrimaryContext coredump + // Below is the analysis process for C++ + // The shielding may prevent clangd from automatically recognizing generic + // struct members + if (IndexCtx.getLangOpts().BSC) { + return true; + } +#endif CXXRecordDecl *RD = TD->getTemplatedDecl(); if (!RD->hasDefinition()) return true; diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 63aa081f1555a44078480a79ad933b2c6bd497de..f3246b8c567817f7801a4eb5ef9cdec8fd39ce8c 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -1395,8 +1395,8 @@ StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr } if (Decls.size()) { DeclGroupPtrTy DataPT = Actions.BuildDeclaratorGroup(Decls); - StmtResult SR = Actions.ActOnDeclStmt(DataPT, SourceLocation(), - SourceLocation()); + StmtResult SR = Actions.ActOnDeclStmt(DataPT, DS->getBeginLoc(), + DS->getEndLoc()); R = SR; } } diff --git a/clang/lib/Sema/BSC/SemaBSCCoroutine.cpp b/clang/lib/Sema/BSC/SemaBSCCoroutine.cpp index a67c1c8dfea5da0973605bc68831a3551aff9036..73ab70c833ac50fa1dbebcf9db2dfc8064a92eca 100644 --- a/clang/lib/Sema/BSC/SemaBSCCoroutine.cpp +++ b/clang/lib/Sema/BSC/SemaBSCCoroutine.cpp @@ -3050,7 +3050,11 @@ SmallVector Sema::ActOnAsyncFunctionDeclaration(FunctionDecl *FD) { SmallVector Sema::ActOnAsyncFunctionDefinition(FunctionDecl *FD) { SmallVector Decls; Decls.push_back(FD); - + // Clang does not analyze the function bodies of functions defined in header + // files, such as inline functions + if (!FD->getBody()) { + return Decls; + } AwaitExprFinder AwaitFinder = AwaitExprFinder(); AwaitFinder.Visit(FD->getBody()); diff --git a/clang/lib/Sema/BSC/SemaBSCDestructor.cpp b/clang/lib/Sema/BSC/SemaBSCDestructor.cpp index 681ec6233f0f41baf39dbc04f31cbcdf0dadab6c..932c10e2037af5e05c982ff3c0f3bf575c774006 100644 --- a/clang/lib/Sema/BSC/SemaBSCDestructor.cpp +++ b/clang/lib/Sema/BSC/SemaBSCDestructor.cpp @@ -488,8 +488,8 @@ public: if (Stmts.size() <= 1) return S; return CompoundStmt::Create(SemaRef.getASTContext(), Stmts, - FPOptionsOverride(), SourceLocation(), - SourceLocation()); + FPOptionsOverride(), S->getBeginLoc(), + S->getEndLoc()); } bool TraverseWhileStmt(WhileStmt *WS) { diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6a59b3a76d23264ba30902432e938ce1a8a9299c..b9a5978bba98c1c198b4cd7255f7249cc187842d 100755 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14853,14 +14853,24 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D // For example ~S(This this); if (!isDestructor && parmDeclType->isPointerType()) { parmDeclType = Context.getQualifiedType( - Context.getPointerType(desugarThisType), ThisPointerQual); + Context.getPointerType(desugarThisType), ThisPointerQual); } else { - parmDeclType = Context.getQualifiedType(desugarThisType, ThisPointerQual); // FIXME: check This Qualifiers + parmDeclType = Context.getQualifiedType( + desugarThisType, ThisPointerQual); // FIXME: check This Qualifiers + } + + // Try to get the valid source location TypeLoc + SourceLocation TypeLoc = D.getIdentifierLoc(); + if (TypeLoc.isInvalid()) { + TypeLoc = D.getBeginLoc(); + if (TypeLoc.isInvalid()) { + TypeLoc = DS.getBeginLoc(); + } } - TInfo = Context.CreateTypeSourceInfo(parmDeclType); // if EntendedType is a generic type, // TemplateArgumentLocInfo is needed when instantiation, if (TypePtr->isDependentType()) { + TInfo = Context.getTrivialTypeSourceInfo(parmDeclType, TypeLoc); UnqualTypeLoc CurrTL = TInfo->getTypeLoc().getUnqualifiedLoc(); QualType CurrType = CurrTL.getType(); while (!isa(CurrType)) { @@ -14869,20 +14879,21 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D } TemplateSpecializationTypeLoc SpecTL = CurrTL.getAs(); - const TemplateSpecializationType* SpecType = SpecTL.getTypePtr(); + const TemplateSpecializationType *SpecType = SpecTL.getTypePtr(); for (unsigned i = 0, e = SpecTL.getNumArgs(); i != e; ++i) { TemplateArgument TemplateArg = SpecType->getArg(i); if (TemplateArg.getKind() == clang::TemplateArgument::Expression) { Expr *TemplateArgExpr = TemplateArg.getAsExpr(); SpecTL.setArgLocInfo(i, TemplateArgumentLocInfo(TemplateArgExpr)); - } else if (TemplateArg.getKind() == clang::TemplateArgument::Type){ + } else if (TemplateArg.getKind() == clang::TemplateArgument::Type) { QualType TemplateArgType = TemplateArg.getAsType(); TypeSourceInfo *TemplateArgTypeInfo = - Context.getTrivialTypeSourceInfo(TemplateArgType, - DS.getBeginLoc()); + Context.getTrivialTypeSourceInfo(TemplateArgType, TypeLoc); SpecTL.setArgLocInfo(i, TemplateArgumentLocInfo(TemplateArgTypeInfo)); } } + } else { + TInfo = Context.getTrivialTypeSourceInfo(parmDeclType, TypeLoc); } } #endif diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 41904980fcfebd4469bb6c8ee618b0221c26f6a9..6ce88b1dfb9c1a2b521d1535d4f3b15e649d74fd 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -6246,6 +6246,8 @@ namespace { TL.setConditionalTInfo1(ConditionalTInfo1); TL.setConditionalTInfo2(ConditionalTInfo2); + TL.setUnderlyingTInfo(DS.getConditionalCondResult() ? ConditionalTInfo1 + : ConditionalTInfo2); } #endif void VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index e9eea1913fd27de2d9fb2d90afc959a774bd2677..a6f4aa3ca9b42036348b32939234390c0832e8f6 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -921,6 +921,10 @@ void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) { ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTraitDeclImpl(TraitDecl *TD) { RedeclarableResult Redecl = VisitTagDecl(TD); + TD->setTrait(readDeclAs()); + TD->setOwnedTrait(readDeclAs()); + TD->setBorrowTrait(readDeclAs()); + TD->setVtable(readDeclAs()); return Redecl; } diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 209b0f698124895cb0cc3e2f4eebb2ec4cefcfa4..75364babfbc995a040be1020278715d3d49e8309 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -494,6 +494,10 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) { #if ENABLE_BSC void ASTDeclWriter::VisitTraitDecl(TraitDecl *D) { VisitTagDecl(D); + Record.AddDeclRef(D->getTrait()); + Record.AddDeclRef(D->getOwnedTrait()); + Record.AddDeclRef(D->getBorrowTrait()); + Record.AddDeclRef(D->getVtable()); if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && !D->isImplicit() && !D->isUsed(false) && !D->hasExtInfo() && !D->getTypedefNameForAnonDecl() &&