// handles them.
ANNOTATION(pragma_vis)
+// Annotation for #pragma pack...
+// The lexer produces these so that they only take effect when the parser
+// handles them.
+ANNOTATION(pragma_pack)
+
#undef ANNOTATION
#undef TESTING_KEYWORD
#undef OBJC2_AT_KEYWORD
/// #pragma GCC visibility...
void HandlePragmaVisibility();
+ /// \brief Handle the annotation token produced for
+ /// #pragma pack...
+ void HandlePragmaPack();
+
/// GetLookAheadToken - This peeks ahead N tokens and returns that token
/// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1)
/// returns the token after Tok, etc.
continue;
}
+ if (Tok.is(tok::annot_pragma_vis)) {
+ HandlePragmaVisibility();
+ continue;
+ }
+
+ if (Tok.is(tok::annot_pragma_pack)) {
+ HandlePragmaPack();
+ continue;
+ }
+
AccessSpecifier AS = getAccessSpecifierIfPresent();
if (AS != AS_none) {
// Current token is a C++ access specifier.
Actions.ActOnPragmaVisibility(VisType, VisLoc);
}
+struct PragmaPackInfo {
+ Sema::PragmaPackKind Kind;
+ IdentifierInfo *Name;
+ Expr *Alignment;
+ SourceLocation LParenLoc;
+ SourceLocation RParenLoc;
+};
+
+void Parser::HandlePragmaPack() {
+ assert(Tok.is(tok::annot_pragma_pack));
+ PragmaPackInfo *Info =
+ static_cast<PragmaPackInfo *>(Tok.getAnnotationValue());
+ SourceLocation PragmaLoc = ConsumeToken();
+ Actions.ActOnPragmaPack(Info->Kind, Info->Name, Info->Alignment, PragmaLoc,
+ Info->LParenLoc, Info->RParenLoc);
+ delete Info;
+}
+
// #pragma GCC visibility comes in two variants:
// 'push' '(' [visibility] ')'
// 'pop'
return;
}
- Actions.ActOnPragmaPack(Kind, Name, Alignment.release(), PackLoc,
- LParenLoc, RParenLoc);
+ PragmaPackInfo *Info = new PragmaPackInfo;
+ Info->Kind = Kind;
+ Info->Name = Name;
+ Info->Alignment = Alignment.release();
+ Info->LParenLoc = LParenLoc;
+ Info->RParenLoc = RParenLoc;
+
+ Token *Toks = new Token[1];
+ Toks[0].startToken();
+ Toks[0].setKind(tok::annot_pragma_pack);
+ Toks[0].setLocation(PackLoc);
+ Toks[0].setAnnotationValue(static_cast<void*>(Info));
+ PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
+ /*OwnsTokens=*/true);
}
// #pragma ms_struct on
case tok::kw___try:
return ParseSEHTryBlock(attrs);
+
+ case tok::annot_pragma_vis:
+ HandlePragmaVisibility();
+ return StmtEmpty();
+
+ case tok::annot_pragma_pack:
+ HandlePragmaPack();
+ return StmtEmpty();
}
// If we reached this code, the statement must end in a semicolon.
case tok::annot_pragma_vis:
HandlePragmaVisibility();
return DeclGroupPtrTy();
+ case tok::annot_pragma_pack:
+ HandlePragmaPack();
+ return DeclGroupPtrTy();
case tok::semi:
Diag(Tok, getLang().CPlusPlus0x ?
diag::warn_cxx98_compat_top_level_semi : diag::ext_top_level_semi)
// Test scope of definition
#pragma pack(push, 2)
-struct s2_0 {
-#pragma pack(pop)
+struct s2_0 { // expected-error {{expected ';'}}
+#pragma pack(pop) // expected-error {{type name}} expected-error {{member name}} expected-warning {{type specifier}}
char f0;
int f1;
};
extern int a2_0[offsetof(struct s2_0, f1) == 2 ? 1 : -1];
struct s2_1 {
- char f0;
-#pragma pack(push, 2)
- int f1;
-#pragma pack(pop)
+ char f0; // expected-error {{expected ';'}}
+#pragma pack(push, 2) // expected-error {{type name}} expected-error {{member name}} expected-warning {{type specifier}}
+ int f1; // expected-error {{expected ';'}}
+#pragma pack(pop) // expected-error {{type name}} expected-error {{member name}} expected-warning {{type specifier}}
};
extern int a2_1[offsetof(struct s2_1, f1) == 4 ? 1 : -1];
struct s2_2 {
char f0;
- int f1;
-#pragma pack(push, 2)
+ int f1; // expected-error {{expected ';'}}
+#pragma pack(push, 2) // expected-error {{type name}} expected-error {{member name}} expected-warning {{type specifier}}
};
#pragma pack(pop)
extern int a2_2[offsetof(struct s2_2, f1) == 4 ? 1 : -1];
struct s2_3 {
- char f0;
-#pragma pack(push, 2)
+ char f0; // expected-error {{expected ';'}}
+#pragma pack(push, 2) // expected-error {{type name}} expected-error {{member name}} expected-warning {{type specifier}}
struct s2_3_0 {
#pragma pack(pop)
int f0;
struct s2_4 {
char f0;
struct s2_4_0 {
- int f0;
-#pragma pack(push, 2)
- } f1;
-#pragma pack(pop)
+ int f0; // expected-error {{expected ';'}}
+#pragma pack(push, 2) // expected-error {{type name}} expected-error {{member name}} expected-warning {{type specifier}}
+ } f1; // expected-error {{expected ';'}}
+#pragma pack(pop) // expected-error {{type name}} expected-error {{member name}} expected-warning {{type specifier}}
};
extern int a2_4[offsetof(struct s2_4, f1) == 4 ? 1 : -1];
};
extern int a4_0[offsetof(struct s4_0, f1) == 1 ? 1 : -1];
extern int a4_1[offsetof(struct s4_1, f1) == 4 ? 1 : -1];
+
+void f() {
+ #pragma pack(push, 2)
+ struct s5_0 {
+ char f0;
+ struct s2_4_0 {
+ int f0;
+ } f1;
+ };
+ #pragma pack(pop)
+ extern int s5_0[offsetof(struct s5_0, f1) == 2 ? 1 : -1];
+}
} // expected-note{{surrounding namespace with visibility attribute ends here}}
#pragma GCC visibility pop // expected-error{{#pragma visibility pop with no matching #pragma visibility push}}
+
+// <rdar://problem/10871094>
+struct A {
+ #pragma GCC visibility push(protected)
+ #pragma GCC visibility pop
+};
+
+void f() {
+ #pragma GCC visibility push(protected)
+ #pragma GCC visibility pop
+}
--- /dev/null
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -verify %s
+
+// Make sure pragma pack works inside ObjC methods. <rdar://problem/10893316>
+@interface X
+@end
+@implementation X
+- (void)Y {
+#pragma pack(push, 1)
+ struct x {
+ char a;
+ int b;
+ };
+#pragma pack(pop)
+ typedef char check_[sizeof (struct x) == 5 ? 1 : -1];
+}
+@end