From bd95745d0efb0d3c6e7cc2f946438a8b2c39c858 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Thu, 18 Apr 2013 01:42:35 +0000 Subject: [PATCH] [Parser] Handle #pragma pack/align inside C structs. Fixes PR13580. Patch by Serge Pavlov! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179743 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseDecl.cpp | 10 ++++++++++ test/Parser/pragma-options.c | 12 ++++++++++++ test/Parser/pragma-pack.c | 14 ++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 47826aa3b9..a39cebccb3 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -3230,6 +3230,16 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, continue; } + if (Tok.is(tok::annot_pragma_pack)) { + HandlePragmaPack(); + continue; + } + + if (Tok.is(tok::annot_pragma_align)) { + HandlePragmaAlign(); + continue; + } + if (!Tok.is(tok::at)) { struct CFieldCallback : FieldCallback { Parser &P; diff --git a/test/Parser/pragma-options.c b/test/Parser/pragma-options.c index 7844e71080..d168a2751a 100644 --- a/test/Parser/pragma-options.c +++ b/test/Parser/pragma-options.c @@ -20,3 +20,15 @@ #pragma align=reset #pragma align=mac68k #pragma align=power + +// PR13580 +struct S +{ + char a[3]; +#pragma align=packed + struct T + { + char b; + int c; + } d; +}; diff --git a/test/Parser/pragma-pack.c b/test/Parser/pragma-pack.c index 84778cd501..172a332510 100644 --- a/test/Parser/pragma-pack.c +++ b/test/Parser/pragma-pack.c @@ -30,3 +30,17 @@ _Pragma("pack(push)") /* expected-warning {{expected integer or identifier in '#pragma pack'}}*/ _Pragma("pack(push,)") + +// PR13580 +struct S +{ + char a[3]; +#pragma pack(1) + struct T + { + char b; + int c; + } d; +#pragma pack() + int e; +}; -- 2.40.0