r262506 - Serialize `#pragma detect_mismatch`.
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 2 11:28:54 PST 2016
Author: nico
Date: Wed Mar 2 13:28:54 2016
New Revision: 262506
URL: http://llvm.org/viewvc/llvm-project?rev=262506&view=rev
Log:
Serialize `#pragma detect_mismatch`.
This is like r262493, but for pragma detect_mismatch instead of pragma comment.
The two pragmas have similar behavior, so use the same approach for both.
Added:
cfe/trunk/test/PCH/pragma-detect_mismatch.c
Modified:
cfe/trunk/include/clang/AST/ASTConsumer.h
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/DeclNodes.td
cfe/trunk/include/clang/Frontend/MultiplexConsumer.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CodeGenAction.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/lib/Sema/SemaAttr.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/include/clang/AST/ASTConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTConsumer.h?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTConsumer.h (original)
+++ cfe/trunk/include/clang/AST/ASTConsumer.h Wed Mar 2 13:28:54 2016
@@ -94,12 +94,6 @@ public:
/// The default implementation passes it to HandleTopLevelDecl.
virtual void HandleImplicitImportDecl(ImportDecl *D);
- /// \brief Handle a pragma that emits a mismatch identifier and value to the
- /// object file for the linker to work with. Currently, this only exists to
- /// support Microsoft's #pragma detect_mismatch.
- virtual void HandleDetectMismatch(llvm::StringRef Name,
- llvm::StringRef Value) {}
-
/// CompleteTentativeDefinition - Callback invoked at the end of a translation
/// unit to notify the consumer that the given tentative definition should be
/// completed.
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Mar 2 13:28:54 2016
@@ -138,6 +138,39 @@ public:
static bool classofKind(Kind K) { return K == PragmaComment; }
};
+/// \brief Represents a `#pragma detect_mismatch` line. Always a child of
+/// TranslationUnitDecl.
+class PragmaDetectMismatchDecl final
+ : public Decl,
+ private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> {
+ virtual void anchor();
+
+ size_t ValueStart;
+
+ friend TrailingObjects;
+ friend class ASTDeclReader;
+ friend class ASTDeclWriter;
+
+ PragmaDetectMismatchDecl(TranslationUnitDecl *TU, SourceLocation Loc,
+ size_t ValueStart)
+ : Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {}
+
+public:
+ static PragmaDetectMismatchDecl *Create(const ASTContext &C,
+ TranslationUnitDecl *DC,
+ SourceLocation Loc, StringRef Name,
+ StringRef Value);
+ static PragmaDetectMismatchDecl *
+ CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize);
+
+ StringRef getName() const { return getTrailingObjects<char>(); }
+ StringRef getValue() const { return getTrailingObjects<char>() + ValueStart; }
+
+ // Implement isa/cast/dyncast/etc.
+ static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+ static bool classofKind(Kind K) { return K == PragmaDetectMismatch; }
+};
+
/// \brief Declaration context for names declared as extern "C" in C++. This
/// is neither the semantic nor lexical context for such declarations, but is
/// used to check for conflicts with other extern "C" declarations. Example:
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Wed Mar 2 13:28:54 2016
@@ -1361,6 +1361,8 @@ DEF_TRAVERSE_DECL(
DEF_TRAVERSE_DECL(PragmaCommentDecl, {})
+DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {})
+
DEF_TRAVERSE_DECL(ExternCContextDecl, {})
DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
Modified: cfe/trunk/include/clang/Basic/DeclNodes.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DeclNodes.td?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DeclNodes.td (original)
+++ cfe/trunk/include/clang/Basic/DeclNodes.td Wed Mar 2 13:28:54 2016
@@ -12,6 +12,7 @@ class DeclContext { }
def TranslationUnit : Decl, DeclContext;
def PragmaComment : Decl;
+def PragmaDetectMismatch : Decl;
def ExternCContext : Decl, DeclContext;
def Named : Decl<1>;
def Namespace : DDecl<Named>, DeclContext;
Modified: cfe/trunk/include/clang/Frontend/MultiplexConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/MultiplexConsumer.h?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/MultiplexConsumer.h (original)
+++ cfe/trunk/include/clang/Frontend/MultiplexConsumer.h Wed Mar 2 13:28:54 2016
@@ -44,8 +44,6 @@ public:
void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) override;
void HandleTopLevelDeclInObjCContainer(DeclGroupRef D) override;
void HandleImplicitImportDecl(ImportDecl *D) override;
- void HandleDetectMismatch(llvm::StringRef Name,
- llvm::StringRef Value) override;
void CompleteTentativeDefinition(VarDecl *D) override;
void AssignInheritanceModel(CXXRecordDecl *RD) override;
void HandleVTable(CXXRecordDecl *RD) override;
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Mar 2 13:28:54 2016
@@ -7676,7 +7676,8 @@ public:
void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II);
/// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch
- void ActOnPragmaDetectMismatch(StringRef Name, StringRef Value);
+ void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name,
+ StringRef Value);
/// ActOnPragmaUnused - Called on well-formed '\#pragma unused'.
void ActOnPragmaUnused(const Token &Identifier,
Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Wed Mar 2 13:28:54 2016
@@ -1166,7 +1166,9 @@ namespace clang {
/// \brief An OMPCapturedExprDecl record.
DECL_OMP_CAPTUREDEXPR,
/// \brief A PragmaCommentDecl record.
- DECL_PRAGMA_COMMENT
+ DECL_PRAGMA_COMMENT,
+ /// \brief A PragmaDetectMismatchDecl record.
+ DECL_PRAGMA_DETECT_MISMATCH
};
/// \brief Record codes for each kind of statement or expression.
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Mar 2 13:28:54 2016
@@ -8505,6 +8505,8 @@ bool ASTContext::DeclMustBeEmitted(const
return false;
} else if (isa<PragmaCommentDecl>(D))
return true;
+ else if (isa<PragmaDetectMismatchDecl>(D))
+ return true;
else if (isa<OMPThreadPrivateDecl>(D))
return true;
else
Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Wed Mar 2 13:28:54 2016
@@ -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(c
OS << " \"" << Arg << "\"";
}
+void ASTDumper::VisitPragmaDetectMismatchDecl(
+ const PragmaDetectMismatchDecl *D) {
+ OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
+}
+
+
//===----------------------------------------------------------------------===//
// C++ Declarations
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Wed Mar 2 13:28:54 2016
@@ -3927,6 +3927,30 @@ PragmaCommentDecl *PragmaCommentDecl::Cr
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() { }
Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Wed Mar 2 13:28:54 2016
@@ -642,6 +642,7 @@ unsigned Decl::getIdentifierNamespaceFor
case StaticAssert:
case ObjCPropertyImpl:
case PragmaComment:
+ case PragmaDetectMismatch:
case Block:
case Captured:
case TranslationUnit:
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Wed Mar 2 13:28:54 2016
@@ -72,6 +72,7 @@ void CodeGenFunction::EmitDecl(const Dec
case Decl::ObjCProperty:
case Decl::ObjCCompatibleAlias:
case Decl::PragmaComment:
+ case Decl::PragmaDetectMismatch:
case Decl::AccessSpec:
case Decl::LinkageSpec:
case Decl::ObjCPropertyImpl:
Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Wed Mar 2 13:28:54 2016
@@ -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);
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Mar 2 13:28:54 2016
@@ -3748,6 +3748,12 @@ void CodeGenModule::EmitTopLevelDecl(Dec
break;
}
+ case Decl::PragmaDetectMismatch: {
+ const auto *PDMD = cast<PragmaDetectMismatchDecl>(D);
+ AddDetectMismatch(PDMD->getName(), PDMD->getValue());
+ break;
+ }
+
case Decl::LinkageSpec:
EmitLinkageSpec(cast<LinkageSpecDecl>(D));
break;
Modified: cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ModuleBuilder.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ModuleBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/ModuleBuilder.cpp Wed Mar 2 13:28:54 2016
@@ -233,11 +233,6 @@ namespace {
Builder->EmitVTable(RD);
}
-
- void HandleDetectMismatch(llvm::StringRef Name,
- llvm::StringRef Value) override {
- Builder->AddDetectMismatch(Name, Value);
- }
};
}
Modified: cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/MultiplexConsumer.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/MultiplexConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/MultiplexConsumer.cpp Wed Mar 2 13:28:54 2016
@@ -317,11 +317,6 @@ void MultiplexConsumer::HandleImplicitIm
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);
Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Wed Mar 2 13:28:54 2016
@@ -1722,10 +1722,10 @@ void PragmaMSPragma::HandlePragma(Prepro
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::Handle
// 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.
Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Wed Mar 2 13:28:54 2016
@@ -277,9 +277,12 @@ void Sema::ActOnPragmaMSComment(SourceLo
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(
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Mar 2 13:28:54 2016
@@ -338,6 +338,11 @@ TemplateDeclInstantiator::VisitPragmaCom
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");
Modified: cfe/trunk/lib/Serialization/ASTCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTCommon.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTCommon.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTCommon.cpp Wed Mar 2 13:28:54 2016
@@ -320,6 +320,7 @@ bool serialization::isRedeclarableDeclKi
case Decl::LinkageSpec:
case Decl::ObjCPropertyImpl:
case Decl::PragmaComment:
+ case Decl::PragmaDetectMismatch:
case Decl::FileScopeAsm:
case Decl::AccessSpec:
case Decl::Friend:
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Mar 2 13:28:54 2016
@@ -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::VisitPragmaCommentDe
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
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 I
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;
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Wed Mar 2 13:28:54 2016
@@ -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::VisitPragmaCommentDe
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");
}
Added: cfe/trunk/test/PCH/pragma-detect_mismatch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/pragma-detect_mismatch.c?rev=262506&view=auto
==============================================================================
--- cfe/trunk/test/PCH/pragma-detect_mismatch.c (added)
+++ cfe/trunk/test/PCH/pragma-detect_mismatch.c Wed Mar 2 13:28:54 2016
@@ -0,0 +1,23 @@
+// Test this without pch.
+// RUN: %clang_cc1 %s -Wunknown-pragmas -Werror -triple x86_64-pc-win32 -fms-extensions -emit-llvm -include %s -o - | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 %s -Wunknown-pragmas -Werror -triple x86_64-pc-win32 -fms-extensions -emit-pch -o %t
+// RUN: %clang_cc1 %s -Wunknown-pragmas -Werror -triple x86_64-pc-win32 -fms-extensions -emit-llvm -include-pch %t -o - | FileCheck %s
+
+// The first run line creates a pch, and since at that point HEADER is not
+// defined, the only thing contained in the pch is the pragma. The second line
+// then includes that pch, so HEADER is defined and the actual code is compiled.
+// The check then makes sure that the pragma is in effect in the file that
+// includes the pch.
+
+#ifndef HEADER
+#define HEADER
+#pragma detect_mismatch("FruitKind", "Jaboticaba")
+
+#else
+
+// CHECK: "/DEFAULTLIB:foo.lib"
+// CHECK: "/FAILIFMISMATCH:\22FruitKind=Jaboticaba\22"
+
+#endif
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=262506&r1=262505&r2=262506&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Mar 2 13:28:54 2016
@@ -5587,6 +5587,7 @@ CXCursor clang_getCursorDefinition(CXCur
case Decl::ObjCTypeParam:
case Decl::BuiltinTemplate:
case Decl::PragmaComment:
+ case Decl::PragmaDetectMismatch:
return C;
// Declaration kinds that don't make any sense here, but are
More information about the cfe-commits
mailing list