[PATCH] D35484: Add a warning for missing '#pragma pack (pop)' and suspicious '#pragma pack' uses when including files

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 17 07:38:18 PDT 2017


arphaman created this revision.

This patch adds a new `-Wpragma-pack` warning. It warns in the following cases:

- When a translation unit is missing terminating `#pragma pack (pop)` directives.
- When entering an included file if the current alignment value as determined by '#pragma pack' directives is different from the default alignment value.
- When leaving an included file that changed the state of the current alignment value.

The change in the parser is required to avoid a missing diagnostic in the following scenario:

  #pragma pack (push, 1)
  #include “foo.h” // Without the change, the diagnostic for the 2nd case won’t be emitted since include will get processed by the Sema before the pragma


Repository:
  rL LLVM

https://reviews.llvm.org/D35484

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTReader.h
  lib/Parse/ParsePragma.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaAttr.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/PCH/pragma-pack.c
  test/PCH/suspicious-pragma-pack.c
  test/Parser/pragma-options.c
  test/Parser/pragma-options.cpp
  test/Parser/pragma-pack.c
  test/Sema/Inputs/pragma-pack1.h
  test/Sema/Inputs/pragma-pack2.h
  test/Sema/pragma-pack.c
  test/Sema/suspicious-pragma-pack.c
  test/SemaObjC/Inputs/empty.h
  test/SemaObjC/suspicious-pragma-pack.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35484.106870.patch
Type: text/x-patch
Size: 22654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170717/26680820/attachment-0001.bin>


More information about the cfe-commits mailing list