diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index 1c8236669c..2938dc76de 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -432,7 +432,8 @@ private: void WritePreprocessorDetail(PreprocessingRecord &PPRec); void WriteSubmodules(Module *WritingModule); - void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag); + void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, + bool isModule); void WriteCXXBaseSpecifiersOffsets(); void WriteType(QualType T); uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 95e32a37fe..033d48c147 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -2444,8 +2444,14 @@ ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { return getSubmoduleID(OwningMod); } -void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) { - // FIXME: Make it work properly with modules. +void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, + bool isModule) { + // Make sure set diagnostic pragmas don't affect the translation unit that + // imports the module. + // FIXME: Make diagnostic pragma sections work properly with modules. + if (isModule) + return; + llvm::SmallDenseMap DiagStateIDMap; unsigned CurrID = 0; @@ -4048,7 +4054,7 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, WriteOpenCLExtensions(SemaRef); WriteTypeDeclOffsets(); - WritePragmaDiagnosticMappings(Context.getDiagnostics()); + WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule); WriteCXXBaseSpecifiersOffsets(); diff --git a/test/Modules/Inputs/diag_pragma.h b/test/Modules/Inputs/diag_pragma.h new file mode 100644 index 0000000000..a8f958994c --- /dev/null +++ b/test/Modules/Inputs/diag_pragma.h @@ -0,0 +1,3 @@ +#define DIAG_PRAGMA_MACRO 1 + +#pragma clang diagnostic ignored "-Wparentheses" diff --git a/test/Modules/Inputs/module.map b/test/Modules/Inputs/module.map index 479bfcfa7f..93ba4935ff 100644 --- a/test/Modules/Inputs/module.map +++ b/test/Modules/Inputs/module.map @@ -188,3 +188,7 @@ module config { header "config.h" config_macros [exhaustive] WANT_FOO, WANT_BAR } + +module diag_pragma { + header "diag_pragma.h" +} diff --git a/test/Modules/diag-pragma.c b/test/Modules/diag-pragma.c new file mode 100644 index 0000000000..7ec3400bba --- /dev/null +++ b/test/Modules/diag-pragma.c @@ -0,0 +1,13 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=diag_pragma %S/Inputs/module.map +// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t %s +// FIXME: When we have a syntax for modules in C, use that. + +@import diag_pragma; + +int foo(int x) { + if (x = DIAG_PRAGMA_MACRO) // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note {{place parentheses}} expected-note {{use '=='}} + return 0; + return 1; +}