diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 2 | ||||
-rw-r--r-- | clang/lib/AST/ASTDumper.cpp | 7 | ||||
-rw-r--r-- | clang/lib/AST/Decl.cpp | 24 | ||||
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 1 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 1 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 5 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 6 | ||||
-rw-r--r-- | clang/lib/CodeGen/ModuleBuilder.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Frontend/MultiplexConsumer.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Parse/ParsePragma.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaAttr.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTCommon.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 20 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriterDecl.cpp | 13 |
15 files changed, 90 insertions, 22 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 0579bca3fe7..4c9ccd7cc98 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -8505,6 +8505,8 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { return false; } else if (isa<PragmaCommentDecl>(D)) return true; + else if (isa<PragmaDetectMismatchDecl>(D)) + return true; else if (isa<OMPThreadPrivateDecl>(D)) return true; else diff --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp index e0ef80d475f..872420606b6 100644 --- a/clang/lib/AST/ASTDumper.cpp +++ b/clang/lib/AST/ASTDumper.cpp @@ -427,6 +427,7 @@ namespace { void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D); void VisitImportDecl(const ImportDecl *D); void VisitPragmaCommentDecl(const PragmaCommentDecl *D); + void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D); // C++ Decls void VisitNamespaceDecl(const NamespaceDecl *D); @@ -1216,6 +1217,12 @@ void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) { OS << " \"" << Arg << "\""; } +void ASTDumper::VisitPragmaDetectMismatchDecl( + const PragmaDetectMismatchDecl *D) { + OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\""; +} + + //===----------------------------------------------------------------------===// // C++ Declarations //===----------------------------------------------------------------------===// diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index e22f1bcf0f2..6451a5c4b17 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -3927,6 +3927,30 @@ PragmaCommentDecl *PragmaCommentDecl::CreateDeserialized(ASTContext &C, PragmaCommentDecl(nullptr, SourceLocation(), PCK_Unknown); } +void PragmaDetectMismatchDecl::anchor() { } + +PragmaDetectMismatchDecl * +PragmaDetectMismatchDecl::Create(const ASTContext &C, TranslationUnitDecl *DC, + SourceLocation Loc, StringRef Name, + StringRef Value) { + size_t ValueStart = Name.size() + 1; + PragmaDetectMismatchDecl *PDMD = + new (C, DC, additionalSizeToAlloc<char>(ValueStart + Value.size() + 1)) + PragmaDetectMismatchDecl(DC, Loc, ValueStart); + memcpy(PDMD->getTrailingObjects<char>(), Name.data(), Name.size()); + PDMD->getTrailingObjects<char>()[Name.size()] = '\0'; + memcpy(PDMD->getTrailingObjects<char>() + ValueStart, Value.data(), + Value.size()); + PDMD->getTrailingObjects<char>()[ValueStart + Value.size()] = '\0'; + return PDMD; +} + +PragmaDetectMismatchDecl * +PragmaDetectMismatchDecl::CreateDeserialized(ASTContext &C, unsigned ID, + unsigned NameValueSize) { + return new (C, ID, additionalSizeToAlloc<char>(NameValueSize + 1)) + PragmaDetectMismatchDecl(nullptr, SourceLocation(), 0); +} void ExternCContextDecl::anchor() { } diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 91bc809cf48..a572687afe6 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -642,6 +642,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) { case StaticAssert: case ObjCPropertyImpl: case PragmaComment: + case PragmaDetectMismatch: case Block: case Captured: case TranslationUnit: diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index f9a6b06a4a9..c218ca41a1d 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -72,6 +72,7 @@ void CodeGenFunction::EmitDecl(const Decl &D) { case Decl::ObjCProperty: case Decl::ObjCCompatibleAlias: case Decl::PragmaComment: + case Decl::PragmaDetectMismatch: case Decl::AccessSpec: case Decl::LinkageSpec: case Decl::ObjCPropertyImpl: diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 8d081144902..c9e188a8725 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -205,11 +205,6 @@ namespace clang { Gen->HandleVTable(RD); } - void HandleDetectMismatch(llvm::StringRef Name, - llvm::StringRef Value) override { - Gen->HandleDetectMismatch(Name, Value); - } - static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM,void *Context, unsigned LocCookie) { SourceLocation Loc = SourceLocation::getFromRawEncoding(LocCookie); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 286ccb1595f..cf9e29d46b7 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3748,6 +3748,12 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { break; } + case Decl::PragmaDetectMismatch: { + const auto *PDMD = cast<PragmaDetectMismatchDecl>(D); + AddDetectMismatch(PDMD->getName(), PDMD->getValue()); + break; + } + case Decl::LinkageSpec: EmitLinkageSpec(cast<LinkageSpecDecl>(D)); break; diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp index 968cc46f7e7..041a15c5623 100644 --- a/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/clang/lib/CodeGen/ModuleBuilder.cpp @@ -233,11 +233,6 @@ namespace { Builder->EmitVTable(RD); } - - void HandleDetectMismatch(llvm::StringRef Name, - llvm::StringRef Value) override { - Builder->AddDetectMismatch(Name, Value); - } }; } diff --git a/clang/lib/Frontend/MultiplexConsumer.cpp b/clang/lib/Frontend/MultiplexConsumer.cpp index 95e9bec6a4e..31c9b5f23fc 100644 --- a/clang/lib/Frontend/MultiplexConsumer.cpp +++ b/clang/lib/Frontend/MultiplexConsumer.cpp @@ -317,11 +317,6 @@ void MultiplexConsumer::HandleImplicitImportDecl(ImportDecl *D) { Consumer->HandleImplicitImportDecl(D); } -void MultiplexConsumer::HandleDetectMismatch(llvm::StringRef Name, llvm::StringRef Value) { - for (auto &Consumer : Consumers) - Consumer->HandleDetectMismatch(Name, Value); -} - void MultiplexConsumer::CompleteTentativeDefinition(VarDecl *D) { for (auto &Consumer : Consumers) Consumer->CompleteTentativeDefinition(D); diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp index 06c1a17bdd4..a7ea206d09b 100644 --- a/clang/lib/Parse/ParsePragma.cpp +++ b/clang/lib/Parse/ParsePragma.cpp @@ -1722,10 +1722,10 @@ void PragmaMSPragma::HandlePragma(Preprocessor &PP, void PragmaDetectMismatchHandler::HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &Tok) { - SourceLocation CommentLoc = Tok.getLocation(); + SourceLocation DetectMismatchLoc = Tok.getLocation(); PP.Lex(Tok); if (Tok.isNot(tok::l_paren)) { - PP.Diag(CommentLoc, diag::err_expected) << tok::l_paren; + PP.Diag(DetectMismatchLoc, diag::err_expected) << tok::l_paren; return; } @@ -1760,10 +1760,10 @@ void PragmaDetectMismatchHandler::HandlePragma(Preprocessor &PP, // If the pragma is lexically sound, notify any interested PPCallbacks. if (PP.getPPCallbacks()) - PP.getPPCallbacks()->PragmaDetectMismatch(CommentLoc, NameString, + PP.getPPCallbacks()->PragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString); - Actions.ActOnPragmaDetectMismatch(NameString, ValueString); + Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString); } /// \brief Handle the microsoft \#pragma comment extension. diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp index 1900d80b217..4b7aa2b07e5 100644 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -277,9 +277,12 @@ void Sema::ActOnPragmaMSComment(SourceLocation CommentLoc, Consumer.HandleTopLevelDecl(DeclGroupRef(PCD)); } -void Sema::ActOnPragmaDetectMismatch(StringRef Name, StringRef Value) { - // FIXME: Serialize this. - Consumer.HandleDetectMismatch(Name, Value); +void Sema::ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, + StringRef Value) { + auto *PDMD = PragmaDetectMismatchDecl::Create( + Context, Context.getTranslationUnitDecl(), Loc, Name, Value); + Context.getTranslationUnitDecl()->addDecl(PDMD); + Consumer.HandleTopLevelDecl(DeclGroupRef(PDMD)); } void Sema::ActOnPragmaMSPointersToMembers( diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 844bdd1fa07..ffb7eeda4f1 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -338,6 +338,11 @@ TemplateDeclInstantiator::VisitPragmaCommentDecl(PragmaCommentDecl *D) { llvm_unreachable("pragma comment cannot be instantiated"); } +Decl *TemplateDeclInstantiator::VisitPragmaDetectMismatchDecl( + PragmaDetectMismatchDecl *D) { + llvm_unreachable("pragma comment cannot be instantiated"); +} + Decl * TemplateDeclInstantiator::VisitExternCContextDecl(ExternCContextDecl *D) { llvm_unreachable("extern \"C\" context cannot be instantiated"); diff --git a/clang/lib/Serialization/ASTCommon.cpp b/clang/lib/Serialization/ASTCommon.cpp index 067653dfbf2..aba39231327 100644 --- a/clang/lib/Serialization/ASTCommon.cpp +++ b/clang/lib/Serialization/ASTCommon.cpp @@ -320,6 +320,7 @@ bool serialization::isRedeclarableDeclKind(unsigned Kind) { case Decl::LinkageSpec: case Decl::ObjCPropertyImpl: case Decl::PragmaComment: + case Decl::PragmaDetectMismatch: case Decl::FileScopeAsm: case Decl::AccessSpec: case Decl::Friend: diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index a7eded1a2fd..213f2aa0ecf 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -243,6 +243,7 @@ namespace clang { void VisitDecl(Decl *D); void VisitPragmaCommentDecl(PragmaCommentDecl *D); + void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); void VisitTranslationUnitDecl(TranslationUnitDecl *TU); void VisitNamedDecl(NamedDecl *ND); void VisitLabelDecl(LabelDecl *LD); @@ -552,6 +553,20 @@ void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) { D->getTrailingObjects<char>()[Arg.size()] = '\0'; } +void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) { + VisitDecl(D); + D->setLocation(ReadSourceLocation(Record, Idx)); + std::string Name = ReadString(Record, Idx); + memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size()); + D->getTrailingObjects<char>()[Name.size()] = '\0'; + + D->ValueStart = Name.size() + 1; + std::string Value = ReadString(Record, Idx); + memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(), + Value.size()); + D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0'; +} + void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { llvm_unreachable("Translation units are not serialized"); } @@ -2433,6 +2448,7 @@ static bool isConsumerInterestedIn(Decl *D, bool HasBody) { isa<ObjCImplDecl>(D) || isa<ImportDecl>(D) || isa<PragmaCommentDecl>(D) || + isa<PragmaDetectMismatchDecl>(D) || isa<OMPThreadPrivateDecl>(D)) return true; if (VarDecl *Var = dyn_cast<VarDecl>(D)) @@ -3353,6 +3369,10 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { case DECL_PRAGMA_COMMENT: D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record[Idx++]); break; + case DECL_PRAGMA_DETECT_MISMATCH: + D = PragmaDetectMismatchDecl::CreateDeserialized(Context, ID, + Record[Idx++]); + break; case DECL_EMPTY: D = EmptyDecl::CreateDeserialized(Context, ID); break; diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index bf36af6bd5a..ee693bf2fc7 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -50,6 +50,7 @@ namespace clang { void VisitDecl(Decl *D); void VisitPragmaCommentDecl(PragmaCommentDecl *D); + void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); void VisitTranslationUnitDecl(TranslationUnitDecl *D); void VisitNamedDecl(NamedDecl *D); void VisitLabelDecl(LabelDecl *LD); @@ -326,6 +327,18 @@ void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) { Code = serialization::DECL_PRAGMA_COMMENT; } +void ASTDeclWriter::VisitPragmaDetectMismatchDecl( + PragmaDetectMismatchDecl *D) { + StringRef Name = D->getName(); + StringRef Value = D->getValue(); + Record.push_back(Name.size() + 1 + Value.size()); + VisitDecl(D); + Writer.AddSourceLocation(D->getLocStart(), Record); + Writer.AddString(Name, Record); + Writer.AddString(Value, Record); + Code = serialization::DECL_PRAGMA_DETECT_MISMATCH; +} + void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { llvm_unreachable("Translation units aren't directly serialized"); } |