r178151 - [modules] Make sure enabled diagnostic pragmas inside the module don't affect the translation unit that

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Mar 27 10:17:23 PDT 2013


Author: akirtzidis
Date: Wed Mar 27 12:17:23 2013
New Revision: 178151

URL: http://llvm.org/viewvc/llvm-project?rev=178151&view=rev
Log:
[modules] Make sure enabled diagnostic pragmas inside the module don't affect the translation unit that
imports the module.

Getting diagnostic sections from modules properly working is a fixme.

rdar://13516663

Added:
    cfe/trunk/test/Modules/Inputs/diag_pragma.h
    cfe/trunk/test/Modules/diag-pragma.c
Modified:
    cfe/trunk/include/clang/Serialization/ASTWriter.h
    cfe/trunk/lib/Serialization/ASTWriter.cpp
    cfe/trunk/test/Modules/Inputs/module.map

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=178151&r1=178150&r2=178151&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Wed Mar 27 12:17:23 2013
@@ -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);

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=178151&r1=178150&r2=178151&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed Mar 27 12:17:23 2013
@@ -2444,8 +2444,14 @@ ASTWriter::inferSubmoduleIDFromLocation(
   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<const DiagnosticsEngine::DiagState *, unsigned, 64>
       DiagStateIDMap;
   unsigned CurrID = 0;
@@ -4048,7 +4054,7 @@ void ASTWriter::WriteASTCore(Sema &SemaR
   WriteOpenCLExtensions(SemaRef);
 
   WriteTypeDeclOffsets();
-  WritePragmaDiagnosticMappings(Context.getDiagnostics());
+  WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule);
 
   WriteCXXBaseSpecifiersOffsets();
   

Added: cfe/trunk/test/Modules/Inputs/diag_pragma.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/diag_pragma.h?rev=178151&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/diag_pragma.h (added)
+++ cfe/trunk/test/Modules/Inputs/diag_pragma.h Wed Mar 27 12:17:23 2013
@@ -0,0 +1,3 @@
+#define DIAG_PRAGMA_MACRO 1
+
+#pragma clang diagnostic ignored "-Wparentheses"

Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=178151&r1=178150&r2=178151&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Wed Mar 27 12:17:23 2013
@@ -188,3 +188,7 @@ module config {
   header "config.h"
   config_macros [exhaustive] WANT_FOO, WANT_BAR
 }
+
+module diag_pragma {
+  header "diag_pragma.h"
+}

Added: cfe/trunk/test/Modules/diag-pragma.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/diag-pragma.c?rev=178151&view=auto
==============================================================================
--- cfe/trunk/test/Modules/diag-pragma.c (added)
+++ cfe/trunk/test/Modules/diag-pragma.c Wed Mar 27 12:17:23 2013
@@ -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.
+
+ at 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;
+}





More information about the cfe-commits mailing list