blob: f1154c1a8aebe29e4d6eb4a8874f7692949e41b9 [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,
Eli Friedman9595c7e2012-10-04 02:36:51 +0000139 SourceLocation PragmaLoc) {
Daniel Dunbarea75a822010-05-27 00:04:40 +0000140 if (PackContext == 0)
141 PackContext = new PragmaPackStack();
142
143 PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext);
144
Daniel Dunbarea75a822010-05-27 00:04:40 +0000145 switch (Kind) {
Daniel Dunbar638e7cf2010-05-27 18:42:09 +0000146 // For all targets we support native and natural are the same.
147 //
148 // FIXME: This is not true on Darwin/PPC.
149 case POAK_Native:
Daniel Dunbar450f7932010-05-28 19:43:33 +0000150 case POAK_Power:
Daniel Dunbard6b305d2010-05-28 20:08:00 +0000151 case POAK_Natural:
Daniel Dunbar450f7932010-05-28 19:43:33 +0000152 Context->push(0);
153 Context->setAlignment(0);
154 break;
155
Daniel Dunbar6f739142010-05-27 18:42:17 +0000156 // Note that '#pragma options align=packed' is not equivalent to attribute
157 // packed, it has a different precedence relative to attribute aligned.
158 case POAK_Packed:
159 Context->push(0);
160 Context->setAlignment(1);
161 break;
162
Daniel Dunbar613fd672010-05-27 00:35:16 +0000163 case POAK_Mac68k:
164 // Check if the target supports this.
165 if (!PP.getTargetInfo().hasAlignMac68kSupport()) {
166 Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
167 return;
Daniel Dunbar613fd672010-05-27 00:35:16 +0000168 }
Daniel Dunbarc6082fe2010-05-27 05:45:51 +0000169 Context->push(0);
170 Context->setAlignment(PackStackEntry::kMac68kAlignmentSentinel);
Daniel Dunbar613fd672010-05-27 00:35:16 +0000171 break;
172
Eli Friedman9595c7e2012-10-04 02:36:51 +0000173 case POAK_Reset:
174 // Reset just pops the top of the stack, or resets the current alignment to
175 // default.
176 if (!Context->pop(0, /*IsReset=*/true)) {
177 Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
178 << "stack empty";
179 }
Daniel Dunbarea75a822010-05-27 00:04:40 +0000180 break;
181 }
182}
183
Mike Stump1eb44332009-09-09 15:08:12 +0000184void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name,
Richard Trieuf81e5a92011-09-09 02:00:50 +0000185 Expr *alignment, SourceLocation PragmaLoc,
Chris Lattner5a0c3512009-02-17 00:57:29 +0000186 SourceLocation LParenLoc, SourceLocation RParenLoc) {
187 Expr *Alignment = static_cast<Expr *>(alignment);
188
189 // If specified then alignment must be a "small" power of two.
190 unsigned AlignmentVal = 0;
191 if (Alignment) {
192 llvm::APSInt Val;
Mike Stump1eb44332009-09-09 15:08:12 +0000193
Daniel Dunbar79cd1162009-03-06 20:45:54 +0000194 // pack(0) is like pack(), which just works out since that is what
195 // we use 0 for in PackAttr.
Douglas Gregorac06a0e2010-05-18 23:01:22 +0000196 if (Alignment->isTypeDependent() ||
197 Alignment->isValueDependent() ||
198 !Alignment->isIntegerConstantExpr(Val, Context) ||
Daniel Dunbar79cd1162009-03-06 20:45:54 +0000199 !(Val == 0 || Val.isPowerOf2()) ||
Chris Lattner5a0c3512009-02-17 00:57:29 +0000200 Val.getZExtValue() > 16) {
201 Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
Chris Lattner5a0c3512009-02-17 00:57:29 +0000202 return; // Ignore
203 }
204
205 AlignmentVal = (unsigned) Val.getZExtValue();
206 }
Mike Stump1eb44332009-09-09 15:08:12 +0000207
Chris Lattner574aa402009-02-17 01:09:29 +0000208 if (PackContext == 0)
209 PackContext = new PragmaPackStack();
Mike Stump1eb44332009-09-09 15:08:12 +0000210
Chris Lattner574aa402009-02-17 01:09:29 +0000211 PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext);
Mike Stump1eb44332009-09-09 15:08:12 +0000212
Chris Lattner5a0c3512009-02-17 00:57:29 +0000213 switch (Kind) {
John McCallf312b1e2010-08-26 23:41:50 +0000214 case Sema::PPK_Default: // pack([n])
Chris Lattner574aa402009-02-17 01:09:29 +0000215 Context->setAlignment(AlignmentVal);
Chris Lattner5a0c3512009-02-17 00:57:29 +0000216 break;
217
John McCallf312b1e2010-08-26 23:41:50 +0000218 case Sema::PPK_Show: // pack(show)
Chris Lattner5a0c3512009-02-17 00:57:29 +0000219 // Show the current alignment, making sure to show the right value
220 // for the default.
Chris Lattner574aa402009-02-17 01:09:29 +0000221 AlignmentVal = Context->getAlignment();
Chris Lattner5a0c3512009-02-17 00:57:29 +0000222 // FIXME: This should come from the target.
223 if (AlignmentVal == 0)
224 AlignmentVal = 8;
Daniel Dunbarc6082fe2010-05-27 05:45:51 +0000225 if (AlignmentVal == PackStackEntry::kMac68kAlignmentSentinel)
226 Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
227 else
228 Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
Chris Lattner5a0c3512009-02-17 00:57:29 +0000229 break;
230
John McCallf312b1e2010-08-26 23:41:50 +0000231 case Sema::PPK_Push: // pack(push [, id] [, [n])
Chris Lattner574aa402009-02-17 01:09:29 +0000232 Context->push(Name);
Chris Lattner5a0c3512009-02-17 00:57:29 +0000233 // Set the new alignment if specified.
234 if (Alignment)
Mike Stump1eb44332009-09-09 15:08:12 +0000235 Context->setAlignment(AlignmentVal);
Chris Lattner5a0c3512009-02-17 00:57:29 +0000236 break;
237
John McCallf312b1e2010-08-26 23:41:50 +0000238 case Sema::PPK_Pop: // pack(pop [, id] [, n])
Chris Lattner5a0c3512009-02-17 00:57:29 +0000239 // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
240 // "#pragma pack(pop, identifier, n) is undefined"
241 if (Alignment && Name)
Mike Stump1eb44332009-09-09 15:08:12 +0000242 Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifer_and_alignment);
243
Chris Lattner5a0c3512009-02-17 00:57:29 +0000244 // Do the pop.
Daniel Dunbarddc6ff62010-07-16 04:54:16 +0000245 if (!Context->pop(Name, /*IsReset=*/false)) {
Chris Lattner5a0c3512009-02-17 00:57:29 +0000246 // If a name was specified then failure indicates the name
247 // wasn't found. Otherwise failure indicates the stack was
248 // empty.
249 Diag(PragmaLoc, diag::warn_pragma_pack_pop_failed)
250 << (Name ? "no record matching name" : "stack empty");
251
252 // FIXME: Warn about popping named records as MSVC does.
253 } else {
254 // Pop succeeded, set the new alignment if specified.
255 if (Alignment)
Chris Lattner574aa402009-02-17 01:09:29 +0000256 Context->setAlignment(AlignmentVal);
Chris Lattner5a0c3512009-02-17 00:57:29 +0000257 }
258 break;
Chris Lattner5a0c3512009-02-17 00:57:29 +0000259 }
260}
261
Fariborz Jahanian62c92582011-04-25 18:49:15 +0000262void Sema::ActOnPragmaMSStruct(PragmaMSStructKind Kind) {
263 MSStructPragmaOn = (Kind == PMSST_ON);
264}
265
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000266void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
267 SourceLocation PragmaLoc) {
Ted Kremenek4726d032009-03-23 22:28:25 +0000268
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000269 IdentifierInfo *Name = IdTok.getIdentifierInfo();
270 LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
271 LookupParsedName(Lookup, curScope, NULL, true);
Ted Kremenek4726d032009-03-23 22:28:25 +0000272
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000273 if (Lookup.empty()) {
274 Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
275 << Name << SourceRange(IdTok.getLocation());
276 return;
Ted Kremenek4726d032009-03-23 22:28:25 +0000277 }
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000278
279 VarDecl *VD = Lookup.getAsSingle<VarDecl>();
Argyrios Kyrtzidis2a5c45b2011-01-27 18:16:48 +0000280 if (!VD) {
281 Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000282 << Name << SourceRange(IdTok.getLocation());
283 return;
284 }
285
286 // Warn if this was used before being marked unused.
287 if (VD->isUsed())
288 Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
289
290 VD->addAttr(::new (Context) UnusedAttr(IdTok.getLocation(), Context));
Ted Kremenek4726d032009-03-23 22:28:25 +0000291}
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000292
John McCall8dfac0b2011-09-30 05:12:12 +0000293void Sema::AddCFAuditedAttribute(Decl *D) {
294 SourceLocation Loc = PP.getPragmaARCCFCodeAuditedLoc();
295 if (!Loc.isValid()) return;
296
297 // Don't add a redundant or conflicting attribute.
298 if (D->hasAttr<CFAuditedTransferAttr>() ||
299 D->hasAttr<CFUnknownTransferAttr>())
300 return;
301
302 D->addAttr(::new (Context) CFAuditedTransferAttr(Loc, Context));
303}
304
John McCall90f14502010-12-10 02:59:44 +0000305typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
306enum { NoVisibility = (unsigned) -1 };
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000307
308void Sema::AddPushedVisibilityAttribute(Decl *D) {
309 if (!VisContext)
310 return;
311
Douglas Gregor4421d2b2011-03-26 12:10:19 +0000312 if (isa<NamedDecl>(D) && cast<NamedDecl>(D)->getExplicitVisibility())
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000313 return;
314
315 VisStack *Stack = static_cast<VisStack*>(VisContext);
John McCall90f14502010-12-10 02:59:44 +0000316 unsigned rawType = Stack->back().first;
317 if (rawType == NoVisibility) return;
318
319 VisibilityAttr::VisibilityType type
320 = (VisibilityAttr::VisibilityType) rawType;
Sean Huntcf807c42010-08-18 23:23:40 +0000321 SourceLocation loc = Stack->back().second;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000322
Sean Huntcf807c42010-08-18 23:23:40 +0000323 D->addAttr(::new (Context) VisibilityAttr(loc, Context, type));
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000324}
325
326/// FreeVisContext - Deallocate and null out VisContext.
327void Sema::FreeVisContext() {
328 delete static_cast<VisStack*>(VisContext);
329 VisContext = 0;
330}
331
John McCall90f14502010-12-10 02:59:44 +0000332static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
John McCallea318642010-08-26 09:15:37 +0000333 // Put visibility on stack.
334 if (!S.VisContext)
335 S.VisContext = new VisStack;
336
337 VisStack *Stack = static_cast<VisStack*>(S.VisContext);
338 Stack->push_back(std::make_pair(type, loc));
339}
340
Rafael Espindola3fc809d2012-01-21 05:43:40 +0000341void Sema::ActOnPragmaVisibility(const IdentifierInfo* VisType,
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000342 SourceLocation PragmaLoc) {
Rafael Espindola3fc809d2012-01-21 05:43:40 +0000343 if (VisType) {
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000344 // Compute visibility to use.
Sean Huntcf807c42010-08-18 23:23:40 +0000345 VisibilityAttr::VisibilityType type;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000346 if (VisType->isStr("default"))
Sean Huntcf807c42010-08-18 23:23:40 +0000347 type = VisibilityAttr::Default;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000348 else if (VisType->isStr("hidden"))
Sean Huntcf807c42010-08-18 23:23:40 +0000349 type = VisibilityAttr::Hidden;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000350 else if (VisType->isStr("internal"))
Sean Huntcf807c42010-08-18 23:23:40 +0000351 type = VisibilityAttr::Hidden; // FIXME
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000352 else if (VisType->isStr("protected"))
Sean Huntcf807c42010-08-18 23:23:40 +0000353 type = VisibilityAttr::Protected;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000354 else {
355 Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) <<
356 VisType->getName();
357 return;
358 }
John McCallea318642010-08-26 09:15:37 +0000359 PushPragmaVisibility(*this, type, PragmaLoc);
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000360 } else {
Rafael Espindola20039ae2012-02-01 23:24:59 +0000361 PopPragmaVisibility(false, PragmaLoc);
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000362 }
363}
364
Peter Collingbourne321b8172011-02-14 01:42:35 +0000365void Sema::ActOnPragmaFPContract(tok::OnOffSwitch OOS) {
366 switch (OOS) {
367 case tok::OOS_ON:
368 FPFeatures.fp_contract = 1;
369 break;
370 case tok::OOS_OFF:
371 FPFeatures.fp_contract = 0;
372 break;
373 case tok::OOS_DEFAULT:
David Blaikie4e4d0842012-03-11 07:00:24 +0000374 FPFeatures.fp_contract = getLangOpts().DefaultFPContract;
Peter Collingbourne321b8172011-02-14 01:42:35 +0000375 break;
376 }
377}
378
Rafael Espindola20039ae2012-02-01 23:24:59 +0000379void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
380 SourceLocation Loc) {
John McCall90f14502010-12-10 02:59:44 +0000381 // Visibility calculations will consider the namespace's visibility.
382 // Here we just want to note that we're in a visibility context
383 // which overrides any enclosing #pragma context, but doesn't itself
384 // contribute visibility.
Rafael Espindola20039ae2012-02-01 23:24:59 +0000385 PushPragmaVisibility(*this, NoVisibility, Loc);
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000386}
387
Rafael Espindola20039ae2012-02-01 23:24:59 +0000388void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
389 if (!VisContext) {
390 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
391 return;
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000392 }
Rafael Espindola20039ae2012-02-01 23:24:59 +0000393
394 // Pop visibility from stack
395 VisStack *Stack = static_cast<VisStack*>(VisContext);
396
397 const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
398 bool StartsWithPragma = Back->first != NoVisibility;
399 if (StartsWithPragma && IsNamespaceEnd) {
400 Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
401 Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
402
403 // For better error recovery, eat all pushes inside the namespace.
404 do {
405 Stack->pop_back();
406 Back = &Stack->back();
407 StartsWithPragma = Back->first != NoVisibility;
408 } while (StartsWithPragma);
409 } else if (!StartsWithPragma && !IsNamespaceEnd) {
410 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
411 Diag(Back->second, diag::note_surrounding_namespace_starts_here);
412 return;
413 }
414
415 Stack->pop_back();
416 // To simplify the implementation, never keep around an empty stack.
417 if (Stack->empty())
418 FreeVisContext();
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000419}