<div dir="ltr">Are the pshpack1.h/poppack.h headers included from other headers in the SDK or are they intended for end-users? If they're only used in the SDK then the SDK headers should probably be system headers, so the warning should be silenced.<div><br></div><div>Apart from that there's no real good solution for this issue unfortunately apart from turning off the warning with a command-line flag or a pragma. I don't think this particular pattern warrants some sort of special treatment in Clang.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 26 September 2017 at 17:02, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Another bit of feedback: The Microsoft SDK has pragma adjustment headers that are used like so:<div><br></div><div><div>#include <pshpack1.h></div><div>// Define structs with alignment 1 here<br></div><div>#include <poppack.h><br></div></div><div><br></div><div>This warning fires on that. I haven't seen these headers in active use recently, but I remember seeing them quite a bit maybe 10 years ago. (It took me until today to remember their names.) Any ideas on how to deal with that?</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 28, 2017 at 2:41 PM, Alex Lorenz via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: arphaman<br>
Date: Fri Jul 28 07:41:21 2017<br>
New Revision: 309386<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=309386&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=309386&view=rev</a><br>
Log:<br>
Recommit r308327 3rd time: Add a warning for missing<br>
'#pragma pack (pop)' and suspicious uses of '#pragma pack' in included files<br>
<br>
The second recommit (r309106) was reverted because the "non-default #pragma<br>
pack value chages the alignment of struct or union members in the included file"<br>
warning proved to be too aggressive for external projects like Chromium<br>
(<a href="https://bugs.chromium.org/p/chromium/issues/detail?id=749197" rel="noreferrer" target="_blank">https://bugs.chromium.org/p/c<wbr>hromium/issues/detail?id=74919<wbr>7</a>). This recommit<br>
makes the problematic warning a non-default one, and gives it the<br>
-Wpragma-pack-suspicious-inclu<wbr>de warning option.<br>
<br>
The first recommit (r308441) caused a "non-default #pragma pack value might<br>
change the alignment of struct or union members in the included file" warning<br>
in LLVM itself. This recommit tweaks the added warning to avoid warnings for<br>
#includes that don't have any records that are affected by the non-default<br>
alignment. This tweak avoids the previously emitted warning in LLVM.<br>
<br>
Original message:<br>
<br>
This commit adds a new -Wpragma-pack warning. It warns in the following cases:<br>
<br>
- When a translation unit is missing terminating #pragma pack (pop) directives.<br>
- When entering an included file if the current alignment value as determined<br>
  by '#pragma pack' directives is different from the default alignment value.<br>
- When leaving an included file that changed the state of the current alignment<br>
  value.<br>
<br>
rdar://10184173<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D35484" rel="noreferrer" target="_blank">https://reviews.llvm.org/D3548<wbr>4</a><br>
<br>
Added:<br>
    cfe/trunk/test/PCH/suspicious-<wbr>pragma-pack.c<br>
    cfe/trunk/test/Sema/Inputs/pra<wbr>gma-pack1.h<br>
    cfe/trunk/test/Sema/Inputs/pra<wbr>gma-pack2.h<br>
    cfe/trunk/test/Sema/suspicious<wbr>-pragma-pack.c<br>
    cfe/trunk/test/SemaObjC/Inputs<wbr>/empty.h<br>
    cfe/trunk/test/SemaObjC/suspic<wbr>ious-pragma-pack.m<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/<wbr>DiagnosticGroups.td<br>
    cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td<br>
    cfe/trunk/include/clang/Lex/PP<wbr>Callbacks.h<br>
    cfe/trunk/include/clang/Sema/S<wbr>ema.h<br>
    cfe/trunk/include/clang/Serial<wbr>ization/ASTReader.h<br>
    cfe/trunk/lib/Parse/ParsePragm<wbr>a.cpp<br>
    cfe/trunk/lib/Sema/Sema.cpp<br>
    cfe/trunk/lib/Sema/SemaAttr.cp<wbr>p<br>
    cfe/trunk/lib/Serialization/AS<wbr>TReader.cpp<br>
    cfe/trunk/lib/Serialization/AS<wbr>TWriter.cpp<br>
    cfe/trunk/test/OpenMP/declare_<wbr>simd_messages.cpp<br>
    cfe/trunk/test/PCH/pragma-pack<wbr>.c<br>
    cfe/trunk/test/Parser/pragma-o<wbr>ptions.c<br>
    cfe/trunk/test/Parser/pragma-o<wbr>ptions.cpp<br>
    cfe/trunk/test/Parser/pragma-p<wbr>ack.c<br>
    cfe/trunk/test/Sema/pragma-pac<wbr>k.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>DiagnosticGroups.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>Basic/DiagnosticGroups.td?rev=<wbr>309386&r1=309385&r2=309386&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>DiagnosticGroups.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>DiagnosticGroups.td Fri Jul 28 07:41:21 2017<br>
@@ -471,8 +471,10 @@ def IgnoredPragmaIntrinsic : DiagGroup<"<br>
 def UnknownPragmas : DiagGroup<"unknown-pragmas">;<br>
 def IgnoredPragmas : DiagGroup<"ignored-pragmas", [IgnoredPragmaIntrinsic]>;<br>
 def PragmaClangAttribute : DiagGroup<"pragma-clang-attrib<wbr>ute">;<br>
+def PragmaPackSuspiciousInclude : DiagGroup<"pragma-pack-suspici<wbr>ous-include">;<br>
+def PragmaPack : DiagGroup<"pragma-pack", [PragmaPackSuspiciousInclude]><wbr>;<br>
 def Pragmas : DiagGroup<"pragmas", [UnknownPragmas, IgnoredPragmas,<br>
-                                    PragmaClangAttribute]>;<br>
+                                    PragmaClangAttribute, PragmaPack]>;<br>
 def UnknownWarningOption : DiagGroup<"unknown-warning-opt<wbr>ion">;<br>
 def NSobjectAttribute : DiagGroup<"NSObject-attribute"<wbr>>;<br>
 def IndependentClassAttribute : DiagGroup<"IndependentClass-at<wbr>tribute">;<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>Basic/DiagnosticSemaKinds.td?<wbr>rev=309386&r1=309385&r2=<wbr>309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td Fri Jul 28 07:41:21 2017<br>
@@ -712,6 +712,17 @@ def err_pragma_options_align_mac68<wbr>k_targ<br>
 def warn_pragma_pack_invalid_align<wbr>ment : Warning<<br>
   "expected #pragma pack parameter to be '1', '2', '4', '8', or '16'">,<br>
   InGroup<IgnoredPragmas>;<br>
+def warn_pragma_pack_non_default_a<wbr>t_include : Warning<<br>
+  "non-default #pragma pack value changes the alignment of struct or union "<br>
+  "members in the included file">, InGroup<PragmaPackSuspiciousIn<wbr>clude>,<br>
+  DefaultIgnore;<br>
+def warn_pragma_pack_modified_afte<wbr>r_include : Warning<<br>
+  "the current #pragma pack aligment value is modified in the included "<br>
+  "file">, InGroup<PragmaPack>;<br>
+def warn_pragma_pack_no_pop_eof : Warning<"unterminated "<br>
+  "'#pragma pack (push, ...)' at end of file">, InGroup<PragmaPack>;<br>
+def note_pragma_pack_here : Note<<br>
+  "previous '#pragma pack' directive that modifies alignment is here">;<br>
 // Follow the Microsoft implementation.<br>
 def warn_pragma_pack_show : Warning<"value of #pragma pack(show) == %0">;<br>
 def warn_pragma_pack_pop_identifer<wbr>_and_alignment : Warning<<br>
<br>
Modified: cfe/trunk/include/clang/Lex/PP<wbr>Callbacks.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>Lex/PPCallbacks.h?rev=309386&<wbr>r1=309385&r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Lex/PP<wbr>Callbacks.h (original)<br>
+++ cfe/trunk/include/clang/Lex/PP<wbr>Callbacks.h Fri Jul 28 07:41:21 2017<br>
@@ -381,6 +381,12 @@ public:<br>
     Second->Ident(Loc, str);<br>
   }<br>
<br>
+  void PragmaDirective(SourceLocation Loc,<br>
+                       PragmaIntroducerKind Introducer) override {<br>
+    First->PragmaDirective(Loc, Introducer);<br>
+    Second->PragmaDirective(Loc, Introducer);<br>
+  }<br>
+<br>
   void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,<br>
                      StringRef Str) override {<br>
     First->PragmaComment(Loc, Kind, Str);<br>
<br>
Modified: cfe/trunk/include/clang/Sema/S<wbr>ema.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>Sema/Sema.h?rev=309386&r1=<wbr>309385&r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Sema/S<wbr>ema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/S<wbr>ema.h Fri Jul 28 07:41:21 2017<br>
@@ -208,6 +208,7 @@ namespace sema {<br>
   class FunctionScopeInfo;<br>
   class LambdaScopeInfo;<br>
   class PossiblyUnreachableDiag;<br>
+  class SemaPPCallbacks;<br>
   class TemplateDeductionInfo;<br>
 }<br>
<br>
@@ -381,11 +382,12 @@ public:<br>
       llvm::StringRef StackSlotLabel;<br>
       ValueType Value;<br>
       SourceLocation PragmaLocation;<br>
-      Slot(llvm::StringRef StackSlotLabel,<br>
-           ValueType Value,<br>
-           SourceLocation PragmaLocation)<br>
-        : StackSlotLabel(StackSlotLabel)<wbr>, Value(Value),<br>
-          PragmaLocation(PragmaLocation) {}<br>
+      SourceLocation PragmaPushLocation;<br>
+      Slot(llvm::StringRef StackSlotLabel, ValueType Value,<br>
+           SourceLocation PragmaLocation, SourceLocation PragmaPushLocation)<br>
+          : StackSlotLabel(StackSlotLabel)<wbr>, Value(Value),<br>
+            PragmaLocation(PragmaLocation)<wbr>,<br>
+            PragmaPushLocation(PragmaPushL<wbr>ocation) {}<br>
     };<br>
     void Act(SourceLocation PragmaLocation,<br>
              PragmaMsStackAction Action,<br>
@@ -416,6 +418,8 @@ public:<br>
     explicit PragmaStack(const ValueType &Default)<br>
         : DefaultValue(Default), CurrentValue(Default) {}<br>
<br>
+    bool hasValue() const { return CurrentValue != DefaultValue; }<br>
+<br>
     SmallVector<Slot, 2> Stack;<br>
     ValueType DefaultValue; // Value used for PSK_Reset action.<br>
     ValueType CurrentValue;<br>
@@ -437,6 +441,13 @@ public:<br>
   // Sentinel to represent when the stack is set to mac68k alignment.<br>
   static const unsigned kMac68kAlignmentSentinel = ~0U;<br>
   PragmaStack<unsigned> PackStack;<br>
+  // The current #pragma pack values and locations at each #include.<br>
+  struct PackIncludeState {<br>
+    unsigned CurrentValue;<br>
+    SourceLocation CurrentPragmaLocation;<br>
+    bool HasNonDefaultValue, ShouldWarnOnInclude;<br>
+  };<br>
+  SmallVector<PackIncludeState, 8> PackIncludeStack;<br>
   // Segment #pragmas.<br>
   PragmaStack<StringLiteral *> DataSegStack;<br>
   PragmaStack<StringLiteral *> BSSSegStack;<br>
@@ -8182,6 +8193,15 @@ public:<br>
   void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action,<br>
                        StringRef SlotLabel, Expr *Alignment);<br>
<br>
+  enum class PragmaPackDiagnoseKind {<br>
+    NonDefaultStateAtInclude,<br>
+    ChangedStateAtExit<br>
+  };<br>
+<br>
+  void DiagnoseNonDefaultPragmaPack(P<wbr>ragmaPackDiagnoseKind Kind,<br>
+                                    SourceLocation IncludeLoc);<br>
+  void DiagnoseUnterminatedPragmaPack<wbr>();<br>
+<br>
   /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off].<br>
   void ActOnPragmaMSStruct(PragmaMSSt<wbr>ructKind Kind);<br>
<br>
@@ -10390,6 +10410,12 @@ private:<br>
<br>
   IdentifierInfo *Ident_NSError = nullptr;<br>
<br>
+  /// \brief The handler for the FileChanged preprocessor events.<br>
+  ///<br>
+  /// Used for diagnostics that implement custom semantic analysis for #include<br>
+  /// directives, like -Wpragma-pack.<br>
+  sema::SemaPPCallbacks *SemaPPCallbackHandler;<br>
+<br>
 protected:<br>
   friend class Parser;<br>
   friend class InitializationSequence;<br>
<br>
Modified: cfe/trunk/include/clang/Serial<wbr>ization/ASTReader.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>Serialization/ASTReader.h?rev=<wbr>309386&r1=309385&r2=309386&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Serial<wbr>ization/ASTReader.h (original)<br>
+++ cfe/trunk/include/clang/Serial<wbr>ization/ASTReader.h Fri Jul 28 07:41:21 2017<br>
@@ -825,6 +825,7 @@ private:<br>
   struct PragmaPackStackEntry {<br>
     unsigned Value;<br>
     SourceLocation Location;<br>
+    SourceLocation PushLocation;<br>
     StringRef SlotLabel;<br>
   };<br>
   llvm::SmallVector<PragmaPackS<wbr>tackEntry, 2> PragmaPackStack;<br>
<br>
Modified: cfe/trunk/lib/Parse/ParsePragm<wbr>a.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Parse/Pars<wbr>ePragma.cpp?rev=309386&r1=3093<wbr>85&r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Parse/ParsePragm<wbr>a.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParsePragm<wbr>a.cpp Fri Jul 28 07:41:21 2017<br>
@@ -422,15 +422,20 @@ void Parser::HandlePragmaPack() {<br>
   assert(Tok.is(tok::annot_prag<wbr>ma_pack));<br>
   PragmaPackInfo *Info =<br>
     static_cast<PragmaPackInfo *>(Tok.getAnnotationValue());<br>
-  SourceLocation PragmaLoc = ConsumeAnnotationToken();<br>
+  SourceLocation PragmaLoc = Tok.getLocation();<br>
   ExprResult Alignment;<br>
   if (Info->Alignment.is(tok::numer<wbr>ic_constant)) {<br>
     Alignment = Actions.ActOnNumericConstant(I<wbr>nfo->Alignment);<br>
-    if (Alignment.isInvalid())<br>
+    if (Alignment.isInvalid()) {<br>
+      ConsumeAnnotationToken();<br>
       return;<br>
+    }<br>
   }<br>
   Actions.ActOnPragmaPack(Pragm<wbr>aLoc, Info->Action, Info->SlotLabel,<br>
                           Alignment.get());<br>
+  // Consume the token after processing the pragma to enable pragma-specific<br>
+  // #include warnings.<br>
+  ConsumeAnnotationToken();<br>
 }<br>
<br>
 void Parser::HandlePragmaMSStruct() {<br>
<br>
Modified: cfe/trunk/lib/Sema/Sema.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Sema/Sema.<wbr>cpp?rev=309386&r1=309385&r2=<wbr>309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/Sema.cpp (original)<br>
+++ cfe/trunk/lib/Sema/Sema.cpp Fri Jul 28 07:41:21 2017<br>
@@ -70,6 +70,49 @@ void Sema::ActOnTranslationUnitScop<wbr>e(Sco<br>
   PushDeclContext(S, Context.getTranslationUnitDecl<wbr>());<br>
 }<br>
<br>
+namespace clang {<br>
+namespace sema {<br>
+<br>
+class SemaPPCallbacks : public PPCallbacks {<br>
+  Sema *S = nullptr;<br>
+  llvm::SmallVector<SourceLocati<wbr>on, 8> IncludeStack;<br>
+<br>
+public:<br>
+  void set(Sema &S) { this->S = &S; }<br>
+<br>
+  void reset() { S = nullptr; }<br>
+<br>
+  virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,<br>
+                           SrcMgr::CharacteristicKind FileType,<br>
+                           FileID PrevFID) override {<br>
+    if (!S)<br>
+      return;<br>
+    switch (Reason) {<br>
+    case EnterFile: {<br>
+      SourceManager &SM = S->getSourceManager();<br>
+      SourceLocation IncludeLoc = SM.getIncludeLoc(SM.getFileID(<wbr>Loc));<br>
+      if (IncludeLoc.isValid()) {<br>
+        IncludeStack.push_back(Include<wbr>Loc);<br>
+        S->DiagnoseNonDefaultPragmaPac<wbr>k(<br>
+            Sema::PragmaPackDiagnoseKind::<wbr>NonDefaultStateAtInclude, IncludeLoc);<br>
+      }<br>
+      break;<br>
+    }<br>
+    case ExitFile:<br>
+      if (!IncludeStack.empty())<br>
+        S->DiagnoseNonDefaultPragmaPac<wbr>k(<br>
+            Sema::PragmaPackDiagnoseKind::<wbr>ChangedStateAtExit,<br>
+            IncludeStack.pop_back_val());<br>
+      break;<br>
+    default:<br>
+      break;<br>
+    }<br>
+  }<br>
+};<br>
+<br>
+} // end namespace sema<br>
+} // end namespace clang<br>
+<br>
 Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,<br>
            TranslationUnitKind TUKind, CodeCompleteConsumer *CodeCompleter)<br>
     : ExternalSource(nullptr), isMultiplexExternalSource(fals<wbr>e),<br>
@@ -122,6 +165,12 @@ Sema::Sema(Preprocessor &pp, ASTContext<br>
<br>
   // Initilization of data sharing attributes stack for OpenMP<br>
   <wbr>InitDataSharingAttributesStack<wbr>();<br>
+<br>
+  std::unique_ptr<sema::SemaPPCa<wbr>llbacks> Callbacks =<br>
+      llvm::make_unique<sema::SemaPP<wbr>Callbacks>();<br>
+  SemaPPCallbackHandler = Callbacks.get();<br>
+  PP.addPPCallbacks(std::move(Ca<wbr>llbacks));<br>
+  SemaPPCallbackHandler->set(*th<wbr>is);<br>
 }<br>
<br>
 void Sema::addImplicitTypedef(Strin<wbr>gRef Name, QualType T) {<br>
@@ -306,6 +355,10 @@ Sema::~Sema() {<br>
   // Destroys data sharing attributes stack for OpenMP<br>
   <wbr>DestroyDataSharingAttributesSt<wbr>ack();<br>
<br>
+  // Detach from the PP callback handler which outlives Sema since it's owned<br>
+  // by the preprocessor.<br>
+  SemaPPCallbackHandler->reset()<wbr>;<br>
+<br>
   assert(DelayedTypos.empty() && "Uncorrected typos!");<br>
 }<br>
<br>
@@ -766,6 +819,7 @@ void Sema::ActOnEndOfTranslationUni<wbr>t() {<br>
     <wbr>CheckDelayedMemberExceptionSpe<wbr>cs();<br>
   }<br>
<br>
+  DiagnoseUnterminatedPragmaPack<wbr>();<br>
   <wbr>DiagnoseUnterminatedPragmaAttr<wbr>ibute();<br>
<br>
   // All delayed member exception specs should be checked or we end up accepting<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaAttr.cp<wbr>p<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Sema/SemaA<wbr>ttr.cpp?rev=309386&r1=309385&<wbr>r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaAttr.cp<wbr>p (original)<br>
+++ cfe/trunk/lib/Sema/SemaAttr.cp<wbr>p Fri Jul 28 07:41:21 2017<br>
@@ -61,6 +61,17 @@ void Sema::AddAlignmentAttributesFo<wbr>rReco<br>
       RD->addAttr(MaxFieldAlignment<wbr>Attr::CreateImplicit(Context,<br>
                                                         Alignment * 8));<br>
   }<br>
+  if (PackIncludeStack.empty())<br>
+    return;<br>
+  // The #pragma pack affected a record in an included file,  so Clang should<br>
+  // warn when that pragma was written in a file that included the included<br>
+  // file.<br>
+  for (auto &PackedInclude : llvm::reverse(PackIncludeStack<wbr>)) {<br>
+    if (PackedInclude.CurrentPragmaLo<wbr>cation != PackStack.CurrentPragmaLocatio<wbr>n)<br>
+      break;<br>
+    if (PackedInclude.HasNonDefaultVa<wbr>lue)<br>
+      PackedInclude.ShouldWarnOnIncl<wbr>ude = true;<br>
+  }<br>
 }<br>
<br>
 void Sema::AddMsStructLayoutForReco<wbr>rd(RecordDecl *RD) {<br>
@@ -202,6 +213,47 @@ void Sema::ActOnPragmaPack(SourceLo<wbr>catio<br>
   PackStack.Act(PragmaLoc, Action, SlotLabel, AlignmentVal);<br>
 }<br>
<br>
+void Sema::DiagnoseNonDefaultPragma<wbr>Pack(PragmaPackDiagnoseKind Kind,<br>
+                                        SourceLocation IncludeLoc) {<br>
+  if (Kind == PragmaPackDiagnoseKind::NonDef<wbr>aultStateAtInclude) {<br>
+    SourceLocation PrevLocation = PackStack.CurrentPragmaLocatio<wbr>n;<br>
+    // Warn about non-default alignment at #includes (without redundant<br>
+    // warnings for the same directive in nested includes).<br>
+    // The warning is delayed until the end of the file to avoid warnings<br>
+    // for files that don't have any records that are affected by the modified<br>
+    // alignment.<br>
+    bool HasNonDefaultValue =<br>
+        PackStack.hasValue() &&<br>
+        (PackIncludeStack.empty() ||<br>
+         PackIncludeStack.back().Curre<wbr>ntPragmaLocation != PrevLocation);<br>
+    PackIncludeStack.push_back(<br>
+        {PackStack.CurrentValue,<br>
+         PackStack.hasValue() ? PrevLocation : SourceLocation(),<br>
+         HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});<br>
+    return;<br>
+  }<br>
+<br>
+  assert(Kind == PragmaPackDiagnoseKind::Change<wbr>dStateAtExit && "invalid kind");<br>
+  PackIncludeState PrevPackState = PackIncludeStack.pop_back_val(<wbr>);<br>
+  if (PrevPackState.ShouldWarnOnInc<wbr>lude) {<br>
+    // Emit the delayed non-default alignment at #include warning.<br>
+    Diag(IncludeLoc, diag::warn_pragma_pack_non_def<wbr>ault_at_include);<br>
+    Diag(PrevPackState.CurrentPrag<wbr>maLocation, diag::note_pragma_pack_here);<br>
+  }<br>
+  // Warn about modified alignment after #includes.<br>
+  if (PrevPackState.CurrentValue != PackStack.CurrentValue) {<br>
+    Diag(IncludeLoc, diag::warn_pragma_pack_modifie<wbr>d_after_include);<br>
+    Diag(PackStack.CurrentPragmaLo<wbr>cation, diag::note_pragma_pack_here);<br>
+  }<br>
+}<br>
+<br>
+void Sema::DiagnoseUnterminatedPrag<wbr>maPack() {<br>
+  if (PackStack.Stack.empty())<br>
+    return;<br>
+  for (const auto &StackSlot : llvm::reverse(PackStack.Stack)<wbr>)<br>
+    Diag(StackSlot.PragmaPushLocat<wbr>ion, diag::warn_pragma_pack_no_pop_<wbr>eof);<br>
+}<br>
+<br>
 void Sema::ActOnPragmaMSStruct(Prag<wbr>maMSStructKind Kind) {<br>
   MSStructPragmaOn = (Kind == PMSST_ON);<br>
 }<br>
@@ -249,7 +301,8 @@ void Sema::PragmaStack<ValueType>::<wbr>Act(S<br>
     return;<br>
   }<br>
   if (Action & PSK_Push)<br>
-    Stack.push_back(Slot(StackSlot<wbr>Label, CurrentValue, CurrentPragmaLocation));<br>
+    Stack.emplace_back(StackSlotLa<wbr>bel, CurrentValue, CurrentPragmaLocation,<br>
+                       PragmaLocation);<br>
   else if (Action & PSK_Pop) {<br>
     if (!StackSlotLabel.empty()) {<br>
       // If we've got a label, try to find it and jump there.<br>
<br>
Modified: cfe/trunk/lib/Serialization/AS<wbr>TReader.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Serializat<wbr>ion/ASTReader.cpp?rev=309386&<wbr>r1=309385&r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Serialization/AS<wbr>TReader.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/AS<wbr>TReader.cpp Fri Jul 28 07:41:21 2017<br>
@@ -3382,6 +3382,7 @@ ASTReader::ReadASTBlock(Module<wbr>File &F, u<br>
         PragmaPackStackEntry Entry;<br>
         Entry.Value = Record[Idx++];<br>
         Entry.Location = ReadSourceLocation(F, Record[Idx++]);<br>
+        Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]);<br>
         PragmaPackStrings.push_back(R<wbr>eadString(Record, Idx));<br>
         Entry.SlotLabel = PragmaPackStrings.back();<br>
         PragmaPackStack.push_back(Ent<wbr>ry);<br>
@@ -7570,13 +7571,14 @@ void ASTReader::UpdateSema() {<br>
              "Expected a default alignment value");<br>
       SemaObj->PackStack.Stack.empl<wbr>ace_back(<br>
           PragmaPackStack.front().SlotL<wbr>abel, SemaObj->PackStack.CurrentValu<wbr>e,<br>
-          SemaObj->PackStack.CurrentPrag<wbr>maLocation);<br>
+          SemaObj->PackStack.CurrentPrag<wbr>maLocation,<br>
+          PragmaPackStack.front().PushLo<wbr>cation);<br>
       DropFirst = true;<br>
     }<br>
     for (const auto &Entry :<br>
          llvm::makeArrayRef(PragmaPackS<wbr>tack).drop_front(DropFirst ? 1 : 0))<br>
       SemaObj->PackStack.Stack.empl<wbr>ace_back(Entry.SlotLabel, Entry.Value,<br>
-                                            Entry.Location);<br>
+                                            Entry.Location, Entry.PushLocation);<br>
     if (PragmaPackCurrentLocation.isI<wbr>nvalid()) {<br>
       assert(*<wbr>PragmaPackCurrentValue == SemaObj->PackStack.DefaultValu<wbr>e &&<br>
              "Expected a default alignment value");<br>
<br>
Modified: cfe/trunk/lib/Serialization/AS<wbr>TWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Serializat<wbr>ion/ASTWriter.cpp?rev=309386&<wbr>r1=309385&r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Serialization/AS<wbr>TWriter.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/AS<wbr>TWriter.cpp Fri Jul 28 07:41:21 2017<br>
@@ -4295,6 +4295,7 @@ void ASTWriter::WritePackPragmaOpti<wbr>ons(S<br>
   for (const auto &StackEntry : SemaRef.PackStack.Stack) {<br>
     Record.push_back(StackEntry.V<wbr>alue);<br>
     AddSourceLocation(StackEntry.<wbr>PragmaLocation, Record);<br>
+    AddSourceLocation(StackEntry.P<wbr>ragmaPushLocation, Record);<br>
     AddString(StackEntry.StackSlo<wbr>tLabel, Record);<br>
   }<br>
   Stream.EmitRecord(PACK_<wbr>PRAGMA_OPTIONS, Record);<br>
<br>
Modified: cfe/trunk/test/OpenMP/declare_<wbr>simd_messages.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_simd_messages.cpp?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/OpenMP/de<wbr>clare_simd_messages.cpp?rev=30<wbr>9386&r1=309385&r2=309386&view=<wbr>diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/OpenMP/declare_<wbr>simd_messages.cpp (original)<br>
+++ cfe/trunk/test/OpenMP/declare_<wbr>simd_messages.cpp Fri Jul 28 07:41:21 2017<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -triple=x86_64-pc-win32 -verify -fopenmp -x c++ -std=c++11 -fms-extensions %s<br>
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -verify -fopenmp -x c++ -std=c++11 -fms-extensions -Wno-pragma-pack %s<br>
<br>
 // expected-error@+1 {{expected an OpenMP directive}}<br>
 #pragma omp declare<br>
<br>
Modified: cfe/trunk/test/PCH/pragma-pack<wbr>.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/pragma-pack.c?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/PCH/pragm<wbr>a-pack.c?rev=309386&r1=309385&<wbr>r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/PCH/pragma-pack<wbr>.c (original)<br>
+++ cfe/trunk/test/PCH/pragma-pack<wbr>.c Fri Jul 28 07:41:21 2017<br>
@@ -1,21 +1,21 @@<br>
 // Test this without pch.<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -DSET<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -DRESET<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -DPUSH<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -DPUSH_POP<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -DPUSH_POP_LABEL<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -Wno-pragma-pack -DSET<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -Wno-pragma-pack -DRESET<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -Wno-pragma-pack -DPUSH<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -Wno-pragma-pack -DPUSH_POP<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -Wno-pragma-pack -DPUSH_POP_LABEL<br>
<br>
 // Test with pch.<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -DSET -emit-pch -o %t<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -DSET -verify -include-pch %t<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -DRESET -emit-pch -o %t<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -DRESET -verify -include-pch %t<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -DPUSH -emit-pch -o %t<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -DPUSH -verify -include-pch %t<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -DPUSH_POP -emit-pch -o %t<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -DPUSH_POP -verify -include-pch %t<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -DPUSH_POP_LABEL -emit-pch -o %t<br>
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -DPUSH_POP_LABEL -verify -include-pch %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DSET -emit-pch -o %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DSET -verify -include-pch %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DRESET -emit-pch -o %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DRESET -verify -include-pch %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH -emit-pch -o %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH -verify -include-pch %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH_POP -emit-pch -o %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH_POP -verify -include-pch %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH_POP_LABEL -emit-pch -o %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH_POP_LABEL -verify -include-pch %t<br>
<br>
 #ifndef HEADER<br>
 #define HEADER<br>
<br>
Added: cfe/trunk/test/PCH/suspicious-<wbr>pragma-pack.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/suspicious-pragma-pack.c?rev=309386&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/PCH/suspi<wbr>cious-pragma-pack.c?rev=309386<wbr>&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/PCH/suspicious-<wbr>pragma-pack.c (added)<br>
+++ cfe/trunk/test/PCH/suspicious-<wbr>pragma-pack.c Fri Jul 28 07:41:21 2017<br>
@@ -0,0 +1,8 @@<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -verify -emit-pch -o %t<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -verify -include-pch %t<br>
+<br>
+#ifndef HEADER<br>
+#define HEADER<br>
+#pragma pack (push, 1)<br>
+#endif<br>
+// expected-warning@-2 {{unterminated '#pragma pack (push, ...)' at end of file}}<br>
<br>
Modified: cfe/trunk/test/Parser/pragma-o<wbr>ptions.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/pragma-options.c?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Parser/pr<wbr>agma-options.c?rev=309386&r1=<wbr>309385&r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Parser/pragma-o<wbr>ptions.c (original)<br>
+++ cfe/trunk/test/Parser/pragma-o<wbr>ptions.c Fri Jul 28 07:41:21 2017<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s<br>
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -Wno-pragma-pack -fsyntax-only -verify %s<br>
<br>
 /* expected-warning {{expected 'align' following '#pragma options'}} */ #pragma options<br>
 /* expected-warning {{expected '=' following '#pragma options align'}} */ #pragma options align<br>
<br>
Modified: cfe/trunk/test/Parser/pragma-o<wbr>ptions.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/pragma-options.cpp?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Parser/pr<wbr>agma-options.cpp?rev=309386&r1<wbr>=309385&r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Parser/pragma-o<wbr>ptions.cpp (original)<br>
+++ cfe/trunk/test/Parser/pragma-o<wbr>ptions.cpp Fri Jul 28 07:41:21 2017<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s<br>
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -Wno-pragma-pack -fsyntax-only -verify %s<br>
 // expected-no-diagnostics<br>
<br>
 class C {<br>
<br>
Modified: cfe/trunk/test/Parser/pragma-p<wbr>ack.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/pragma-pack.c?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Parser/pr<wbr>agma-pack.c?rev=309386&r1=3093<wbr>85&r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Parser/pragma-p<wbr>ack.c (original)<br>
+++ cfe/trunk/test/Parser/pragma-p<wbr>ack.c Fri Jul 28 07:41:21 2017<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -fsyntax-only -verify %s<br>
+// RUN: %clang_cc1 -fsyntax-only -Wno-pragma-pack -verify %s<br>
<br>
 // Note that this puts the expected lines before the directives to work around<br>
 // limitations in the -verify mode.<br>
<br>
Added: cfe/trunk/test/Sema/Inputs/pra<wbr>gma-pack1.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/Inputs/pragma-pack1.h?rev=309386&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Sema/Inpu<wbr>ts/pragma-pack1.h?rev=309386&<wbr>view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Sema/Inputs/pra<wbr>gma-pack1.h (added)<br>
+++ cfe/trunk/test/Sema/Inputs/pra<wbr>gma-pack1.h Fri Jul 28 07:41:21 2017<br>
@@ -0,0 +1,27 @@<br>
+<br>
+#ifndef NO_RECORD_1<br>
+struct ReceivesPragma { };<br>
+#endif<br>
+<br>
+#ifdef SET_FIRST_HEADER<br>
+#pragma pack (16)<br>
+#ifndef SET_SECOND_HEADER<br>
+// expected-note@-2 2 {{previous '#pragma pack' directive that modifies alignment is here}}<br>
+#else<br>
+// expected-note@-4 1 {{previous '#pragma pack' directive that modifies alignment is here}}<br>
+#endif<br>
+// expected-warning@+3 {{non-default #pragma pack value changes the alignment of struct or union members in the included file}}<br>
+#endif<br>
+<br>
+#include "pragma-pack2.h"<br>
+<br>
+#ifdef SET_SECOND_HEADER<br>
+// expected-warning@-3 {{the current #pragma pack aligment value is modified in the included file}}<br>
+#endif<br>
+<br>
+#ifdef PUSH_POP_FIRST_HEADER<br>
+// This is fine, we don't change the current value.<br>
+#pragma pack (push, 4)<br>
+<br>
+#pragma pack (pop)<br>
+#endif<br>
<br>
Added: cfe/trunk/test/Sema/Inputs/pra<wbr>gma-pack2.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/Inputs/pragma-pack2.h?rev=309386&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Sema/Inpu<wbr>ts/pragma-pack2.h?rev=309386&<wbr>view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Sema/Inputs/pra<wbr>gma-pack2.h (added)<br>
+++ cfe/trunk/test/Sema/Inputs/pra<wbr>gma-pack2.h Fri Jul 28 07:41:21 2017<br>
@@ -0,0 +1,8 @@<br>
+<br>
+#ifndef NO_RECORD_2<br>
+struct S { int x; };<br>
+#endif<br>
+<br>
+#ifdef SET_SECOND_HEADER<br>
+#pragma pack (8) // expected-note 2 {{previous '#pragma pack' directive that modifies alignment is here}}<br>
+#endif<br>
<br>
Modified: cfe/trunk/test/Sema/pragma-pac<wbr>k.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pragma-pack.c?rev=309386&r1=309385&r2=309386&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Sema/prag<wbr>ma-pack.c?rev=309386&r1=309385<wbr>&r2=309386&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Sema/pragma-pac<wbr>k.c (original)<br>
+++ cfe/trunk/test/Sema/pragma-pac<wbr>k.c Fri Jul 28 07:41:21 2017<br>
@@ -25,3 +25,8 @@<br>
 #pragma pack(pop, 16)<br>
 /* expected-warning {{value of #pragma pack(show) == 16}} */ #pragma pack(show)<br>
<br>
+<br>
+// Warn about unbalanced pushes.<br>
+#pragma pack (push,4) // expected-warning {{unterminated '#pragma pack (push, ...)' at end of file}}<br>
+#pragma pack (push)   // expected-warning {{unterminated '#pragma pack (push, ...)' at end of file}}<br>
+#pragma pack ()<br>
<br>
Added: cfe/trunk/test/Sema/suspicious<wbr>-pragma-pack.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/suspicious-pragma-pack.c?rev=309386&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Sema/susp<wbr>icious-pragma-pack.c?rev=30938<wbr>6&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Sema/suspicious<wbr>-pragma-pack.c (added)<br>
+++ cfe/trunk/test/Sema/suspicious<wbr>-pragma-pack.c Fri Jul 28 07:41:21 2017<br>
@@ -0,0 +1,50 @@<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DSAFE -verify %s<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DPUSH_HERE -DSAFE -verify %s<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DPUSH_HERE -DPUSH_SET_HERE -verify %s<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DPUSH_HERE -DRESET_HERE -DSAFE -verify %s<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DPUSH_HERE -DSET_FIRST_HEADER -DWARN_MODIFIED_HEADER -verify %s<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DPUSH_HERE -DRESET_HERE -DSET_FIRST_HEADER -DWARN_MODIFIED_HEADER -verify %s<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DPUSH_HERE -DPUSH_SET_HERE -DSET_FIRST_HEADER -DWARN_MODIFIED_HEADER -verify %s<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DPUSH_HERE -DPUSH_SET_HERE -DSET_SECOND_HEADER -DWARN_MODIFIED_HEADER -verify %s<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DPUSH_HERE -DPUSH_SET_HERE -DSET_FIRST_HEADER -DSET_SECOND_HEADER -DWARN_MODIFIED_HEADER -verify %s<br>
+<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DPUSH_POP_FIRST_HEADER -DSAFE -verify %s<br>
+<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I %S/Inputs -DPUSH_SET_HERE -DNO_RECORD_1 -DNO_RECORD_2 -DSAFE -verify %s<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack-suspicious-inclu<wbr>de -I %S/Inputs -DPUSH_SET_HERE -DNO_RECORD_1 -verify %s<br>
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -Wno-pragma-pack-suspicious-in<wbr>clude -I %S/Inputs -DPUSH_SET_HERE -DNO_RECORD_1 -DSAFE -verify %s<br>
+<br>
+#ifdef SAFE<br>
+// expected-no-diagnostics<br>
+#endif<br>
+<br>
+#ifdef PUSH_HERE<br>
+#pragma pack (push)<br>
+#endif<br>
+<br>
+#ifdef PUSH_SET_HERE<br>
+#pragma pack (push, 4)<br>
+#ifndef SAFE<br>
+// expected-note@-2 {{previous '#pragma pack' directive that modifies alignment is here}}<br>
+// expected-warning@+9 {{non-default #pragma pack value changes the alignment of struct or union members in the included file}}<br>
+#endif<br>
+#endif<br>
+<br>
+#ifdef RESET_HERE<br>
+#pragma pack (4)<br>
+#pragma pack () // no warning after reset as the value is default.<br>
+#endif<br>
+<br>
+#include "pragma-pack1.h"<br>
+<br>
+#ifdef WARN_MODIFIED_HEADER<br>
+// expected-warning@-3 {{the current #pragma pack aligment value is modified in the included file}}<br>
+#endif<br>
+<br>
+#ifdef PUSH_SET_HERE<br>
+#pragma pack (pop)<br>
+#endif<br>
+<br>
+#ifdef PUSH_HERE<br>
+#pragma pack (pop)<br>
+#endif<br>
<br>
Added: cfe/trunk/test/SemaObjC/Inputs<wbr>/empty.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/Inputs/empty.h?rev=309386&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/SemaObjC/<wbr>Inputs/empty.h?rev=309386&<wbr>view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/SemaObjC/Inputs<wbr>/empty.h (added)<br>
+++ cfe/trunk/test/SemaObjC/Inputs<wbr>/empty.h Fri Jul 28 07:41:21 2017<br>
@@ -0,0 +1 @@<br>
+struct S { int x; };<br>
<br>
Added: cfe/trunk/test/SemaObjC/suspic<wbr>ious-pragma-pack.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/suspicious-pragma-pack.m?rev=309386&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/SemaObjC/<wbr>suspicious-pragma-pack.m?rev=<wbr>309386&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/SemaObjC/suspic<wbr>ious-pragma-pack.m (added)<br>
+++ cfe/trunk/test/SemaObjC/suspic<wbr>ious-pragma-pack.m Fri Jul 28 07:41:21 2017<br>
@@ -0,0 +1,6 @@<br>
+// RUN: %clang_cc1 -Wpragma-pack-suspicious-inclu<wbr>de -triple i686-apple-darwin9 -fsyntax-only -I%S/Inputs -verify %s<br>
+<br>
+#pragma pack (push, 1) // expected-note {{previous '#pragma pack' directive that modifies alignment is here}}<br>
+#import "empty.h" // expected-warning {{non-default #pragma pack value changes the alignment of struct or union members in the included file}}<br>
+<br>
+#pragma pack (pop)<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>