blob: e935fc735b230351d33283dd3b9d150a4f631581 [file] [log] [blame]
Chris Lattner5a0c3512009-02-17 00:57:29 +00001//===--- SemaAttr.cpp - Semantic Analysis for Attributes ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner574aa402009-02-17 01:09:29 +000010// This file implements semantic analysis for non-trivial attributes and
11// pragmas.
Chris Lattner5a0c3512009-02-17 00:57:29 +000012//
13//===----------------------------------------------------------------------===//
14
John McCall2d887082010-08-25 22:03:47 +000015#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000016#include "clang/Sema/Lookup.h"
Sean Huntcf807c42010-08-18 23:23:40 +000017#include "clang/AST/Attr.h"
Chris Lattner5a0c3512009-02-17 00:57:29 +000018#include "clang/AST/Expr.h"
Daniel Dunbar613fd672010-05-27 00:35:16 +000019#include "clang/Basic/TargetInfo.h"
20#include "clang/Lex/Preprocessor.h"
Chris Lattner5a0c3512009-02-17 00:57:29 +000021using namespace clang;
22
Chris Lattner574aa402009-02-17 01:09:29 +000023//===----------------------------------------------------------------------===//
Daniel Dunbarea75a822010-05-27 00:04:40 +000024// Pragma 'pack' and 'options align'
Chris Lattner574aa402009-02-17 01:09:29 +000025//===----------------------------------------------------------------------===//
26
27namespace {
Daniel Dunbarae2232b2010-05-27 02:25:27 +000028 struct PackStackEntry {
Daniel Dunbarc6082fe2010-05-27 05:45:51 +000029 // We just use a sentinel to represent when the stack is set to mac68k
30 // alignment.
31 static const unsigned kMac68kAlignmentSentinel = ~0U;
32
Daniel Dunbarae2232b2010-05-27 02:25:27 +000033 unsigned Alignment;
34 IdentifierInfo *Name;
35 };
36
Chris Lattner574aa402009-02-17 01:09:29 +000037 /// PragmaPackStack - Simple class to wrap the stack used by #pragma
38 /// pack.
39 class PragmaPackStack {
Daniel Dunbarae2232b2010-05-27 02:25:27 +000040 typedef std::vector<PackStackEntry> stack_ty;
Chris Lattner574aa402009-02-17 01:09:29 +000041
42 /// Alignment - The current user specified alignment.
43 unsigned Alignment;
44
45 /// Stack - Entries in the #pragma pack stack, consisting of saved
46 /// alignments and optional names.
47 stack_ty Stack;
Mike Stump1eb44332009-09-09 15:08:12 +000048
49 public:
Chris Lattner574aa402009-02-17 01:09:29 +000050 PragmaPackStack() : Alignment(0) {}
51
52 void setAlignment(unsigned A) { Alignment = A; }
53 unsigned getAlignment() { return Alignment; }
54
55 /// push - Push the current alignment onto the stack, optionally
56 /// using the given \arg Name for the record, if non-zero.
57 void push(IdentifierInfo *Name) {
Daniel Dunbarae2232b2010-05-27 02:25:27 +000058 PackStackEntry PSE = { Alignment, Name };
59 Stack.push_back(PSE);
Chris Lattner574aa402009-02-17 01:09:29 +000060 }
61
62 /// pop - Pop a record from the stack and restore the current
63 /// alignment to the previous value. If \arg Name is non-zero then
64 /// the first such named record is popped, otherwise the top record
65 /// is popped. Returns true if the pop succeeded.
Daniel Dunbarddc6ff62010-07-16 04:54:16 +000066 bool pop(IdentifierInfo *Name, bool IsReset);
Chris Lattner574aa402009-02-17 01:09:29 +000067 };
68} // end anonymous namespace.
69
Daniel Dunbarddc6ff62010-07-16 04:54:16 +000070bool PragmaPackStack::pop(IdentifierInfo *Name, bool IsReset) {
Chris Lattner574aa402009-02-17 01:09:29 +000071 // If name is empty just pop top.
72 if (!Name) {
Daniel Dunbarddc6ff62010-07-16 04:54:16 +000073 // An empty stack is a special case...
74 if (Stack.empty()) {
75 // If this isn't a reset, it is always an error.
76 if (!IsReset)
77 return false;
78
79 // Otherwise, it is an error only if some alignment has been set.
80 if (!Alignment)
81 return false;
82
83 // Otherwise, reset to the default alignment.
84 Alignment = 0;
85 } else {
86 Alignment = Stack.back().Alignment;
87 Stack.pop_back();
88 }
89
Chris Lattner574aa402009-02-17 01:09:29 +000090 return true;
Mike Stump1eb44332009-09-09 15:08:12 +000091 }
92
Chris Lattner574aa402009-02-17 01:09:29 +000093 // Otherwise, find the named record.
94 for (unsigned i = Stack.size(); i != 0; ) {
95 --i;
Daniel Dunbarae2232b2010-05-27 02:25:27 +000096 if (Stack[i].Name == Name) {
Chris Lattner574aa402009-02-17 01:09:29 +000097 // Found it, pop up to and including this record.
Daniel Dunbarae2232b2010-05-27 02:25:27 +000098 Alignment = Stack[i].Alignment;
Chris Lattner574aa402009-02-17 01:09:29 +000099 Stack.erase(Stack.begin() + i, Stack.end());
100 return true;
101 }
102 }
Mike Stump1eb44332009-09-09 15:08:12 +0000103
Chris Lattner574aa402009-02-17 01:09:29 +0000104 return false;
105}
106
107
108/// FreePackedContext - Deallocate and null out PackContext.
109void Sema::FreePackedContext() {
110 delete static_cast<PragmaPackStack*>(PackContext);
111 PackContext = 0;
112}
113
Daniel Dunbar9f21f892010-05-27 01:53:40 +0000114void Sema::AddAlignmentAttributesForRecord(RecordDecl *RD) {
115 // If there is no pack context, we don't need any attributes.
116 if (!PackContext)
117 return;
118
119 PragmaPackStack *Stack = static_cast<PragmaPackStack*>(PackContext);
120
121 // Otherwise, check to see if we need a max field alignment attribute.
Daniel Dunbarc6082fe2010-05-27 05:45:51 +0000122 if (unsigned Alignment = Stack->getAlignment()) {
123 if (Alignment == PackStackEntry::kMac68kAlignmentSentinel)
Sean Huntcf807c42010-08-18 23:23:40 +0000124 RD->addAttr(::new (Context) AlignMac68kAttr(SourceLocation(), Context));
Daniel Dunbarc6082fe2010-05-27 05:45:51 +0000125 else
Sean Huntcf807c42010-08-18 23:23:40 +0000126 RD->addAttr(::new (Context) MaxFieldAlignmentAttr(SourceLocation(),
127 Context,
128 Alignment * 8));
Daniel Dunbarc6082fe2010-05-27 05:45:51 +0000129 }
Chris Lattner574aa402009-02-17 01:09:29 +0000130}
131
Fariborz Jahanianc1a0a732011-04-26 17:54:40 +0000132void Sema::AddMsStructLayoutForRecord(RecordDecl *RD) {
133 if (!MSStructPragmaOn)
134 return;
135 RD->addAttr(::new (Context) MsStructAttr(SourceLocation(), Context));
136}
137
Daniel Dunbarea75a822010-05-27 00:04:40 +0000138void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
139 SourceLocation PragmaLoc,
140 SourceLocation KindLoc) {
141 if (PackContext == 0)
142 PackContext = new PragmaPackStack();
143
144 PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext);
145
Daniel Dunbarddc6ff62010-07-16 04:54:16 +0000146 // Reset just pops the top of the stack, or resets the current alignment to
147 // default.
John McCallf312b1e2010-08-26 23:41:50 +0000148 if (Kind == Sema::POAK_Reset) {
Daniel Dunbarddc6ff62010-07-16 04:54:16 +0000149 if (!Context->pop(0, /*IsReset=*/true)) {
Daniel Dunbarea75a822010-05-27 00:04:40 +0000150 Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
151 << "stack empty";
152 }
153 return;
154 }
155
Daniel Dunbarea75a822010-05-27 00:04:40 +0000156 switch (Kind) {
Daniel Dunbar638e7cf2010-05-27 18:42:09 +0000157 // For all targets we support native and natural are the same.
158 //
159 // FIXME: This is not true on Darwin/PPC.
160 case POAK_Native:
Daniel Dunbar450f7932010-05-28 19:43:33 +0000161 case POAK_Power:
Daniel Dunbard6b305d2010-05-28 20:08:00 +0000162 case POAK_Natural:
Daniel Dunbar450f7932010-05-28 19:43:33 +0000163 Context->push(0);
164 Context->setAlignment(0);
165 break;
166
Daniel Dunbar6f739142010-05-27 18:42:17 +0000167 // Note that '#pragma options align=packed' is not equivalent to attribute
168 // packed, it has a different precedence relative to attribute aligned.
169 case POAK_Packed:
170 Context->push(0);
171 Context->setAlignment(1);
172 break;
173
Daniel Dunbar613fd672010-05-27 00:35:16 +0000174 case POAK_Mac68k:
175 // Check if the target supports this.
176 if (!PP.getTargetInfo().hasAlignMac68kSupport()) {
177 Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
178 return;
Daniel Dunbar613fd672010-05-27 00:35:16 +0000179 }
Daniel Dunbarc6082fe2010-05-27 05:45:51 +0000180 Context->push(0);
181 Context->setAlignment(PackStackEntry::kMac68kAlignmentSentinel);
Daniel Dunbar613fd672010-05-27 00:35:16 +0000182 break;
183
Daniel Dunbarea75a822010-05-27 00:04:40 +0000184 default:
185 Diag(PragmaLoc, diag::warn_pragma_options_align_unsupported_option)
186 << KindLoc;
187 break;
188 }
189}
190
Mike Stump1eb44332009-09-09 15:08:12 +0000191void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name,
Richard Trieuf81e5a92011-09-09 02:00:50 +0000192 Expr *alignment, SourceLocation PragmaLoc,
Chris Lattner5a0c3512009-02-17 00:57:29 +0000193 SourceLocation LParenLoc, SourceLocation RParenLoc) {
194 Expr *Alignment = static_cast<Expr *>(alignment);
195
196 // If specified then alignment must be a "small" power of two.
197 unsigned AlignmentVal = 0;
198 if (Alignment) {
199 llvm::APSInt Val;
Mike Stump1eb44332009-09-09 15:08:12 +0000200
Daniel Dunbar79cd1162009-03-06 20:45:54 +0000201 // pack(0) is like pack(), which just works out since that is what
202 // we use 0 for in PackAttr.
Douglas Gregorac06a0e2010-05-18 23:01:22 +0000203 if (Alignment->isTypeDependent() ||
204 Alignment->isValueDependent() ||
205 !Alignment->isIntegerConstantExpr(Val, Context) ||
Daniel Dunbar79cd1162009-03-06 20:45:54 +0000206 !(Val == 0 || Val.isPowerOf2()) ||
Chris Lattner5a0c3512009-02-17 00:57:29 +0000207 Val.getZExtValue() > 16) {
208 Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
Chris Lattner5a0c3512009-02-17 00:57:29 +0000209 return; // Ignore
210 }
211
212 AlignmentVal = (unsigned) Val.getZExtValue();
213 }
Mike Stump1eb44332009-09-09 15:08:12 +0000214
Chris Lattner574aa402009-02-17 01:09:29 +0000215 if (PackContext == 0)
216 PackContext = new PragmaPackStack();
Mike Stump1eb44332009-09-09 15:08:12 +0000217
Chris Lattner574aa402009-02-17 01:09:29 +0000218 PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext);
Mike Stump1eb44332009-09-09 15:08:12 +0000219
Chris Lattner5a0c3512009-02-17 00:57:29 +0000220 switch (Kind) {
John McCallf312b1e2010-08-26 23:41:50 +0000221 case Sema::PPK_Default: // pack([n])
Chris Lattner574aa402009-02-17 01:09:29 +0000222 Context->setAlignment(AlignmentVal);
Chris Lattner5a0c3512009-02-17 00:57:29 +0000223 break;
224
John McCallf312b1e2010-08-26 23:41:50 +0000225 case Sema::PPK_Show: // pack(show)
Chris Lattner5a0c3512009-02-17 00:57:29 +0000226 // Show the current alignment, making sure to show the right value
227 // for the default.
Chris Lattner574aa402009-02-17 01:09:29 +0000228 AlignmentVal = Context->getAlignment();
Chris Lattner5a0c3512009-02-17 00:57:29 +0000229 // FIXME: This should come from the target.
230 if (AlignmentVal == 0)
231 AlignmentVal = 8;
Daniel Dunbarc6082fe2010-05-27 05:45:51 +0000232 if (AlignmentVal == PackStackEntry::kMac68kAlignmentSentinel)
233 Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
234 else
235 Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
Chris Lattner5a0c3512009-02-17 00:57:29 +0000236 break;
237
John McCallf312b1e2010-08-26 23:41:50 +0000238 case Sema::PPK_Push: // pack(push [, id] [, [n])
Chris Lattner574aa402009-02-17 01:09:29 +0000239 Context->push(Name);
Chris Lattner5a0c3512009-02-17 00:57:29 +0000240 // Set the new alignment if specified.
241 if (Alignment)
Mike Stump1eb44332009-09-09 15:08:12 +0000242 Context->setAlignment(AlignmentVal);
Chris Lattner5a0c3512009-02-17 00:57:29 +0000243 break;
244
John McCallf312b1e2010-08-26 23:41:50 +0000245 case Sema::PPK_Pop: // pack(pop [, id] [, n])
Chris Lattner5a0c3512009-02-17 00:57:29 +0000246 // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
247 // "#pragma pack(pop, identifier, n) is undefined"
248 if (Alignment && Name)
Mike Stump1eb44332009-09-09 15:08:12 +0000249 Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifer_and_alignment);
250
Chris Lattner5a0c3512009-02-17 00:57:29 +0000251 // Do the pop.
Daniel Dunbarddc6ff62010-07-16 04:54:16 +0000252 if (!Context->pop(Name, /*IsReset=*/false)) {
Chris Lattner5a0c3512009-02-17 00:57:29 +0000253 // If a name was specified then failure indicates the name
254 // wasn't found. Otherwise failure indicates the stack was
255 // empty.
256 Diag(PragmaLoc, diag::warn_pragma_pack_pop_failed)
257 << (Name ? "no record matching name" : "stack empty");
258
259 // FIXME: Warn about popping named records as MSVC does.
260 } else {
261 // Pop succeeded, set the new alignment if specified.
262 if (Alignment)
Chris Lattner574aa402009-02-17 01:09:29 +0000263 Context->setAlignment(AlignmentVal);
Chris Lattner5a0c3512009-02-17 00:57:29 +0000264 }
265 break;
Chris Lattner5a0c3512009-02-17 00:57:29 +0000266 }
267}
268
Fariborz Jahanian62c92582011-04-25 18:49:15 +0000269void Sema::ActOnPragmaMSStruct(PragmaMSStructKind Kind) {
270 MSStructPragmaOn = (Kind == PMSST_ON);
271}
272
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000273void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
274 SourceLocation PragmaLoc) {
Ted Kremenek4726d032009-03-23 22:28:25 +0000275
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000276 IdentifierInfo *Name = IdTok.getIdentifierInfo();
277 LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
278 LookupParsedName(Lookup, curScope, NULL, true);
Ted Kremenek4726d032009-03-23 22:28:25 +0000279
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000280 if (Lookup.empty()) {
281 Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
282 << Name << SourceRange(IdTok.getLocation());
283 return;
Ted Kremenek4726d032009-03-23 22:28:25 +0000284 }
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000285
286 VarDecl *VD = Lookup.getAsSingle<VarDecl>();
Argyrios Kyrtzidis2a5c45b2011-01-27 18:16:48 +0000287 if (!VD) {
288 Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000289 << Name << SourceRange(IdTok.getLocation());
290 return;
291 }
292
293 // Warn if this was used before being marked unused.
294 if (VD->isUsed())
295 Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
296
297 VD->addAttr(::new (Context) UnusedAttr(IdTok.getLocation(), Context));
Ted Kremenek4726d032009-03-23 22:28:25 +0000298}
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000299
John McCall8dfac0b2011-09-30 05:12:12 +0000300void Sema::AddCFAuditedAttribute(Decl *D) {
301 SourceLocation Loc = PP.getPragmaARCCFCodeAuditedLoc();
302 if (!Loc.isValid()) return;
303
304 // Don't add a redundant or conflicting attribute.
305 if (D->hasAttr<CFAuditedTransferAttr>() ||
306 D->hasAttr<CFUnknownTransferAttr>())
307 return;
308
309 D->addAttr(::new (Context) CFAuditedTransferAttr(Loc, Context));
310}
311
John McCall90f14502010-12-10 02:59:44 +0000312typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
313enum { NoVisibility = (unsigned) -1 };
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000314
315void Sema::AddPushedVisibilityAttribute(Decl *D) {
316 if (!VisContext)
317 return;
318
Douglas Gregor4421d2b2011-03-26 12:10:19 +0000319 if (isa<NamedDecl>(D) && cast<NamedDecl>(D)->getExplicitVisibility())
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000320 return;
321
322 VisStack *Stack = static_cast<VisStack*>(VisContext);
John McCall90f14502010-12-10 02:59:44 +0000323 unsigned rawType = Stack->back().first;
324 if (rawType == NoVisibility) return;
325
326 VisibilityAttr::VisibilityType type
327 = (VisibilityAttr::VisibilityType) rawType;
Sean Huntcf807c42010-08-18 23:23:40 +0000328 SourceLocation loc = Stack->back().second;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000329
Sean Huntcf807c42010-08-18 23:23:40 +0000330 D->addAttr(::new (Context) VisibilityAttr(loc, Context, type));
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000331}
332
333/// FreeVisContext - Deallocate and null out VisContext.
334void Sema::FreeVisContext() {
335 delete static_cast<VisStack*>(VisContext);
336 VisContext = 0;
337}
338
John McCall90f14502010-12-10 02:59:44 +0000339static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
John McCallea318642010-08-26 09:15:37 +0000340 // Put visibility on stack.
341 if (!S.VisContext)
342 S.VisContext = new VisStack;
343
344 VisStack *Stack = static_cast<VisStack*>(S.VisContext);
345 Stack->push_back(std::make_pair(type, loc));
346}
347
Rafael Espindola3fc809d2012-01-21 05:43:40 +0000348void Sema::ActOnPragmaVisibility(const IdentifierInfo* VisType,
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000349 SourceLocation PragmaLoc) {
Rafael Espindola3fc809d2012-01-21 05:43:40 +0000350 if (VisType) {
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000351 // Compute visibility to use.
Sean Huntcf807c42010-08-18 23:23:40 +0000352 VisibilityAttr::VisibilityType type;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000353 if (VisType->isStr("default"))
Sean Huntcf807c42010-08-18 23:23:40 +0000354 type = VisibilityAttr::Default;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000355 else if (VisType->isStr("hidden"))
Sean Huntcf807c42010-08-18 23:23:40 +0000356 type = VisibilityAttr::Hidden;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000357 else if (VisType->isStr("internal"))
Sean Huntcf807c42010-08-18 23:23:40 +0000358 type = VisibilityAttr::Hidden; // FIXME
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000359 else if (VisType->isStr("protected"))
Sean Huntcf807c42010-08-18 23:23:40 +0000360 type = VisibilityAttr::Protected;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000361 else {
362 Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) <<
363 VisType->getName();
364 return;
365 }
John McCallea318642010-08-26 09:15:37 +0000366 PushPragmaVisibility(*this, type, PragmaLoc);
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000367 } else {
Rafael Espindola20039ae2012-02-01 23:24:59 +0000368 PopPragmaVisibility(false, PragmaLoc);
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000369 }
370}
371
Peter Collingbourne321b8172011-02-14 01:42:35 +0000372void Sema::ActOnPragmaFPContract(tok::OnOffSwitch OOS) {
373 switch (OOS) {
374 case tok::OOS_ON:
375 FPFeatures.fp_contract = 1;
376 break;
377 case tok::OOS_OFF:
378 FPFeatures.fp_contract = 0;
379 break;
380 case tok::OOS_DEFAULT:
David Blaikie4e4d0842012-03-11 07:00:24 +0000381 FPFeatures.fp_contract = getLangOpts().DefaultFPContract;
Peter Collingbourne321b8172011-02-14 01:42:35 +0000382 break;
383 }
384}
385
Rafael Espindola20039ae2012-02-01 23:24:59 +0000386void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
387 SourceLocation Loc) {
John McCall90f14502010-12-10 02:59:44 +0000388 // Visibility calculations will consider the namespace's visibility.
389 // Here we just want to note that we're in a visibility context
390 // which overrides any enclosing #pragma context, but doesn't itself
391 // contribute visibility.
Rafael Espindola20039ae2012-02-01 23:24:59 +0000392 PushPragmaVisibility(*this, NoVisibility, Loc);
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000393}
394
Rafael Espindola20039ae2012-02-01 23:24:59 +0000395void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
396 if (!VisContext) {
397 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
398 return;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000399 }
Rafael Espindola20039ae2012-02-01 23:24:59 +0000400
401 // Pop visibility from stack
402 VisStack *Stack = static_cast<VisStack*>(VisContext);
403
404 const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
405 bool StartsWithPragma = Back->first != NoVisibility;
406 if (StartsWithPragma && IsNamespaceEnd) {
407 Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
408 Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
409
410 // For better error recovery, eat all pushes inside the namespace.
411 do {
412 Stack->pop_back();
413 Back = &Stack->back();
414 StartsWithPragma = Back->first != NoVisibility;
415 } while (StartsWithPragma);
416 } else if (!StartsWithPragma && !IsNamespaceEnd) {
417 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
418 Diag(Back->second, diag::note_surrounding_namespace_starts_here);
419 return;
420 }
421
422 Stack->pop_back();
423 // To simplify the implementation, never keep around an empty stack.
424 if (Stack->empty())
425 FreeVisContext();
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000426}