Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Sema/SemaAttr.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- SemaAttr.cpp - Semantic Analysis for Attributes ------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements semantic analysis for non-trivial attributes and
10
// pragmas.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/AST/ASTConsumer.h"
15
#include "clang/AST/Attr.h"
16
#include "clang/AST/Expr.h"
17
#include "clang/Basic/TargetInfo.h"
18
#include "clang/Lex/Preprocessor.h"
19
#include "clang/Sema/Lookup.h"
20
#include "clang/Sema/SemaInternal.h"
21
using namespace clang;
22
23
//===----------------------------------------------------------------------===//
24
// Pragma 'pack' and 'options align'
25
//===----------------------------------------------------------------------===//
26
27
Sema::PragmaStackSentinelRAII::PragmaStackSentinelRAII(Sema &S,
28
                                                       StringRef SlotLabel,
29
                                                       bool ShouldAct)
30
3.21M
    : S(S), SlotLabel(SlotLabel), ShouldAct(ShouldAct) {
31
3.21M
  if (ShouldAct) {
32
1.13M
    S.VtorDispStack.SentinelAction(PSK_Push, SlotLabel);
33
1.13M
    S.DataSegStack.SentinelAction(PSK_Push, SlotLabel);
34
1.13M
    S.BSSSegStack.SentinelAction(PSK_Push, SlotLabel);
35
1.13M
    S.ConstSegStack.SentinelAction(PSK_Push, SlotLabel);
36
1.13M
    S.CodeSegStack.SentinelAction(PSK_Push, SlotLabel);
37
1.13M
  }
38
3.21M
}
39
40
3.21M
Sema::PragmaStackSentinelRAII::~PragmaStackSentinelRAII() {
41
3.21M
  if (ShouldAct) {
42
1.13M
    S.VtorDispStack.SentinelAction(PSK_Pop, SlotLabel);
43
1.13M
    S.DataSegStack.SentinelAction(PSK_Pop, SlotLabel);
44
1.13M
    S.BSSSegStack.SentinelAction(PSK_Pop, SlotLabel);
45
1.13M
    S.ConstSegStack.SentinelAction(PSK_Pop, SlotLabel);
46
1.13M
    S.CodeSegStack.SentinelAction(PSK_Pop, SlotLabel);
47
1.13M
  }
48
3.21M
}
49
50
1.01M
void Sema::AddAlignmentAttributesForRecord(RecordDecl *RD) {
51
1.01M
  // If there is no pack value, we don't need any attributes.
52
1.01M
  if (!PackStack.CurrentValue)
53
973k
    return;
54
44.6k
55
44.6k
  // Otherwise, check to see if we need a max field alignment attribute.
56
44.6k
  if (unsigned Alignment = PackStack.CurrentValue) {
57
44.6k
    if (Alignment == Sema::kMac68kAlignmentSentinel)
58
13
      RD->addAttr(AlignMac68kAttr::CreateImplicit(Context));
59
44.6k
    else
60
44.6k
      RD->addAttr(MaxFieldAlignmentAttr::CreateImplicit(Context,
61
44.6k
                                                        Alignment * 8));
62
44.6k
  }
63
44.6k
  if (PackIncludeStack.empty())
64
333
    return;
65
44.2k
  // The #pragma pack affected a record in an included file,  so Clang should
66
44.2k
  // warn when that pragma was written in a file that included the included
67
44.2k
  // file.
68
44.2k
  
for (auto &PackedInclude : llvm::reverse(PackIncludeStack))44.2k
{
69
44.2k
    if (PackedInclude.CurrentPragmaLocation != PackStack.CurrentPragmaLocation)
70
44.2k
      break;
71
17
    if (PackedInclude.HasNonDefaultValue)
72
13
      PackedInclude.ShouldWarnOnInclude = true;
73
17
  }
74
44.2k
}
75
76
1.01M
void Sema::AddMsStructLayoutForRecord(RecordDecl *RD) {
77
1.01M
  if (MSStructPragmaOn)
78
21
    RD->addAttr(MSStructAttr::CreateImplicit(Context));
79
1.01M
80
1.01M
  // FIXME: We should merge AddAlignmentAttributesForRecord with
81
1.01M
  // AddMsStructLayoutForRecord into AddPragmaAttributesForRecord, which takes
82
1.01M
  // all active pragmas and applies them as attributes to class definitions.
83
1.01M
  if (VtorDispStack.CurrentValue != getLangOpts().VtorDispMode)
84
29
    RD->addAttr(
85
29
        MSVtorDispAttr::CreateImplicit(Context, VtorDispStack.CurrentValue));
86
1.01M
}
87
88
void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
89
30
                                   SourceLocation PragmaLoc) {
90
30
  PragmaMsStackAction Action = Sema::PSK_Reset;
91
30
  unsigned Alignment = 0;
92
30
  switch (Kind) {
93
30
    // For all targets we support native and natural are the same.
94
30
    //
95
30
    // FIXME: This is not true on Darwin/PPC.
96
30
  case POAK_Native:
97
8
  case POAK_Power:
98
8
  case POAK_Natural:
99
8
    Action = Sema::PSK_Push_Set;
100
8
    Alignment = 0;
101
8
    break;
102
8
103
8
    // Note that '#pragma options align=packed' is not equivalent to attribute
104
8
    // packed, it has a different precedence relative to attribute aligned.
105
8
  case POAK_Packed:
106
5
    Action = Sema::PSK_Push_Set;
107
5
    Alignment = 1;
108
5
    break;
109
8
110
8
  case POAK_Mac68k:
111
7
    // Check if the target supports this.
112
7
    if (!this->Context.getTargetInfo().hasAlignMac68kSupport()) {
113
2
      Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
114
2
      return;
115
2
    }
116
5
    Action = Sema::PSK_Push_Set;
117
5
    Alignment = Sema::kMac68kAlignmentSentinel;
118
5
    break;
119
5
120
10
  case POAK_Reset:
121
10
    // Reset just pops the top of the stack, or resets the current alignment to
122
10
    // default.
123
10
    Action = Sema::PSK_Pop;
124
10
    if (PackStack.Stack.empty()) {
125
2
      if (PackStack.CurrentValue) {
126
1
        Action = Sema::PSK_Reset;
127
1
      } else {
128
1
        Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
129
1
            << "stack empty";
130
1
        return;
131
1
      }
132
9
    }
133
9
    break;
134
27
  }
135
27
136
27
  PackStack.Act(PragmaLoc, Action, StringRef(), Alignment);
137
27
}
138
139
void Sema::ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action,
140
52
                                   PragmaClangSectionKind SecKind, StringRef SecName) {
141
52
  PragmaClangSection *CSec;
142
52
  switch (SecKind) {
143
52
    case PragmaClangSectionKind::PCSK_BSS:
144
14
      CSec = &PragmaClangBSSSection;
145
14
      break;
146
52
    case PragmaClangSectionKind::PCSK_Data:
147
11
      CSec = &PragmaClangDataSection;
148
11
      break;
149
52
    case PragmaClangSectionKind::PCSK_Rodata:
150
13
      CSec = &PragmaClangRodataSection;
151
13
      break;
152
52
    case PragmaClangSectionKind::PCSK_Text:
153
14
      CSec = &PragmaClangTextSection;
154
14
      break;
155
52
    default:
156
0
      llvm_unreachable("invalid clang section kind");
157
52
  }
158
52
159
52
  if (Action == PragmaClangSectionAction::PCSA_Clear) {
160
26
    CSec->Valid = false;
161
26
    return;
162
26
  }
163
26
164
26
  CSec->Valid = true;
165
26
  CSec->SectionName = SecName;
166
26
  CSec->PragmaLocation = PragmaLoc;
167
26
}
168
169
void Sema::ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action,
170
74.5k
                           StringRef SlotLabel, Expr *alignment) {
171
74.5k
  Expr *Alignment = static_cast<Expr *>(alignment);
172
74.5k
173
74.5k
  // If specified then alignment must be a "small" power of two.
174
74.5k
  unsigned AlignmentVal = 0;
175
74.5k
  if (Alignment) {
176
37.3k
    llvm::APSInt Val;
177
37.3k
178
37.3k
    // pack(0) is like pack(), which just works out since that is what
179
37.3k
    // we use 0 for in PackAttr.
180
37.3k
    if (Alignment->isTypeDependent() ||
181
37.3k
        Alignment->isValueDependent() ||
182
37.3k
        !Alignment->isIntegerConstantExpr(Val, Context) ||
183
37.3k
        !(Val == 0 || 
Val.isPowerOf2()37.3k
) ||
184
37.3k
        
Val.getZExtValue() > 1637.3k
) {
185
1
      Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
186
1
      return; // Ignore
187
1
    }
188
37.3k
189
37.3k
    AlignmentVal = (unsigned) Val.getZExtValue();
190
37.3k
  }
191
74.5k
  
if (74.5k
Action == Sema::PSK_Show74.5k
) {
192
40
    // Show the current alignment, making sure to show the right value
193
40
    // for the default.
194
40
    // FIXME: This should come from the target.
195
40
    AlignmentVal = PackStack.CurrentValue;
196
40
    if (AlignmentVal == 0)
197
20
      AlignmentVal = 8;
198
40
    if (AlignmentVal == Sema::kMac68kAlignmentSentinel)
199
0
      Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
200
40
    else
201
40
      Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
202
40
  }
203
74.5k
  // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
204
74.5k
  // "#pragma pack(pop, identifier, n) is undefined"
205
74.5k
  if (Action & Sema::PSK_Pop) {
206
190
    if (Alignment && 
!SlotLabel.empty()1
)
207
0
      Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
208
190
    if (PackStack.Stack.empty())
209
12
      Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "pack" << "stack empty";
210
190
  }
211
74.5k
212
74.5k
  PackStack.Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
213
74.5k
}
214
215
void Sema::DiagnoseNonDefaultPragmaPack(PragmaPackDiagnoseKind Kind,
216
954k
                                        SourceLocation IncludeLoc) {
217
954k
  if (Kind == PragmaPackDiagnoseKind::NonDefaultStateAtInclude) {
218
477k
    SourceLocation PrevLocation = PackStack.CurrentPragmaLocation;
219
477k
    // Warn about non-default alignment at #includes (without redundant
220
477k
    // warnings for the same directive in nested includes).
221
477k
    // The warning is delayed until the end of the file to avoid warnings
222
477k
    // for files that don't have any records that are affected by the modified
223
477k
    // alignment.
224
477k
    bool HasNonDefaultValue =
225
477k
        PackStack.hasValue() &&
226
477k
        
(19
PackIncludeStack.empty()19
||
227
19
         
PackIncludeStack.back().CurrentPragmaLocation != PrevLocation9
);
228
477k
    PackIncludeStack.push_back(
229
477k
        {PackStack.CurrentValue,
230
477k
         PackStack.hasValue() ? 
PrevLocation19
:
SourceLocation()477k
,
231
477k
         HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});
232
477k
    return;
233
477k
  }
234
477k
235
477k
  assert(Kind == PragmaPackDiagnoseKind::ChangedStateAtExit && "invalid kind");
236
477k
  PackIncludeState PrevPackState = PackIncludeStack.pop_back_val();
237
477k
  if (PrevPackState.ShouldWarnOnInclude) {
238
11
    // Emit the delayed non-default alignment at #include warning.
239
11
    Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
240
11
    Diag(PrevPackState.CurrentPragmaLocation, diag::note_pragma_pack_here);
241
11
  }
242
477k
  // Warn about modified alignment after #includes.
243
477k
  if (PrevPackState.CurrentValue != PackStack.CurrentValue) {
244
13
    Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
245
13
    Diag(PackStack.CurrentPragmaLocation, diag::note_pragma_pack_here);
246
13
  }
247
477k
}
248
249
40.3k
void Sema::DiagnoseUnterminatedPragmaPack() {
250
40.3k
  if (PackStack.Stack.empty())
251
40.3k
    return;
252
20
  bool IsInnermost = true;
253
28
  for (const auto &StackSlot : llvm::reverse(PackStack.Stack)) {
254
28
    Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
255
28
    // The user might have already reset the alignment, so suggest replacing
256
28
    // the reset with a pop.
257
28
    if (IsInnermost && 
PackStack.CurrentValue == PackStack.DefaultValue20
) {
258
5
      DiagnosticBuilder DB = Diag(PackStack.CurrentPragmaLocation,
259
5
                                  diag::note_pragma_pack_pop_instead_reset);
260
5
      SourceLocation FixItLoc = Lexer::findLocationAfterToken(
261
5
          PackStack.CurrentPragmaLocation, tok::l_paren, SourceMgr, LangOpts,
262
5
          /*SkipTrailing=*/false);
263
5
      if (FixItLoc.isValid())
264
4
        DB << FixItHint::CreateInsertion(FixItLoc, "pop");
265
5
    }
266
28
    IsInnermost = false;
267
28
  }
268
20
}
269
270
2.61k
void Sema::ActOnPragmaMSStruct(PragmaMSStructKind Kind) {
271
2.61k
  MSStructPragmaOn = (Kind == PMSST_ON);
272
2.61k
}
273
274
void Sema::ActOnPragmaMSComment(SourceLocation CommentLoc,
275
52
                                PragmaMSCommentKind Kind, StringRef Arg) {
276
52
  auto *PCD = PragmaCommentDecl::Create(
277
52
      Context, Context.getTranslationUnitDecl(), CommentLoc, Kind, Arg);
278
52
  Context.getTranslationUnitDecl()->addDecl(PCD);
279
52
  Consumer.HandleTopLevelDecl(DeclGroupRef(PCD));
280
52
}
281
282
void Sema::ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name,
283
10
                                     StringRef Value) {
284
10
  auto *PDMD = PragmaDetectMismatchDecl::Create(
285
10
      Context, Context.getTranslationUnitDecl(), Loc, Name, Value);
286
10
  Context.getTranslationUnitDecl()->addDecl(PDMD);
287
10
  Consumer.HandleTopLevelDecl(DeclGroupRef(PDMD));
288
10
}
289
290
void Sema::ActOnPragmaMSPointersToMembers(
291
    LangOptions::PragmaMSPointersToMembersKind RepresentationMethod,
292
26
    SourceLocation PragmaLoc) {
293
26
  MSPointerToMemberRepresentationMethod = RepresentationMethod;
294
26
  ImplicitMSInheritanceAttrLoc = PragmaLoc;
295
26
}
296
297
void Sema::ActOnPragmaMSVtorDisp(PragmaMsStackAction Action,
298
                                 SourceLocation PragmaLoc,
299
45
                                 MSVtorDispAttr::Mode Mode) {
300
45
  if (Action & PSK_Pop && 
VtorDispStack.Stack.empty()20
)
301
4
    Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "vtordisp"
302
4
                                                  << "stack empty";
303
45
  VtorDispStack.Act(PragmaLoc, Action, StringRef(), Mode);
304
45
}
305
306
template<typename ValueType>
307
void Sema::PragmaStack<ValueType>::Act(SourceLocation PragmaLocation,
308
                                       PragmaMsStackAction Action,
309
                                       llvm::StringRef StackSlotLabel,
310
11.3M
                                       ValueType Value) {
311
11.3M
  if (Action == PSK_Reset) {
312
36.9k
    CurrentValue = DefaultValue;
313
36.9k
    CurrentPragmaLocation = PragmaLocation;
314
36.9k
    return;
315
36.9k
  }
316
11.3M
  if (Action & PSK_Push)
317
5.65M
    Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
318
5.65M
                       PragmaLocation);
319
5.69M
  else if (Action & PSK_Pop) {
320
5.65M
    if (!StackSlotLabel.empty()) {
321
5.65M
      // If we've got a label, try to find it and jump there.
322
5.65M
      auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
323
5.65M
        return x.StackSlotLabel == StackSlotLabel;
324
5.65M
      });
clang::Sema::PragmaStack<unsigned int>::Act(clang::SourceLocation, clang::Sema::PragmaMsStackAction, llvm::StringRef, unsigned int)::'lambda'(clang::Sema::PragmaStack<unsigned int>::Slot const&)::operator()(clang::Sema::PragmaStack<unsigned int>::Slot const&) const
Line
Count
Source
322
10
      auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
323
10
        return x.StackSlotLabel == StackSlotLabel;
324
10
      });
clang::Sema::PragmaStack<clang::MSVtorDispAttr::Mode>::Act(clang::SourceLocation, clang::Sema::PragmaMsStackAction, llvm::StringRef, clang::MSVtorDispAttr::Mode)::'lambda'(clang::Sema::PragmaStack<clang::MSVtorDispAttr::Mode>::Slot const&)::operator()(clang::Sema::PragmaStack<clang::MSVtorDispAttr::Mode>::Slot const&) const
Line
Count
Source
322
1.13M
      auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
323
1.13M
        return x.StackSlotLabel == StackSlotLabel;
324
1.13M
      });
clang::Sema::PragmaStack<clang::StringLiteral*>::Act(clang::SourceLocation, clang::Sema::PragmaMsStackAction, llvm::StringRef, clang::StringLiteral*)::'lambda'(clang::Sema::PragmaStack<clang::StringLiteral*>::Slot const&)::operator()(clang::Sema::PragmaStack<clang::StringLiteral*>::Slot const&) const
Line
Count
Source
322
4.52M
      auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
323
4.52M
        return x.StackSlotLabel == StackSlotLabel;
324
4.52M
      });
325
5.65M
      // If we found the label so pop from there.
326
5.65M
      if (I != Stack.rend()) {
327
5.65M
        CurrentValue = I->Value;
328
5.65M
        CurrentPragmaLocation = I->PragmaLocation;
329
5.65M
        Stack.erase(std::prev(I.base()), Stack.end());
330
5.65M
      }
331
5.65M
    } else 
if (215
!Stack.empty()215
) {
332
201
      // We do not have a label, just pop the last entry.
333
201
      CurrentValue = Stack.back().Value;
334
201
      CurrentPragmaLocation = Stack.back().PragmaLocation;
335
201
      Stack.pop_back();
336
201
    }
337
5.65M
  }
338
11.3M
  if (Action & PSK_Set) {
339
37.3k
    CurrentValue = Value;
340
37.3k
    CurrentPragmaLocation = PragmaLocation;
341
37.3k
  }
342
11.3M
}
clang::Sema::PragmaStack<unsigned int>::Act(clang::SourceLocation, clang::Sema::PragmaMsStackAction, llvm::StringRef, unsigned int)
Line
Count
Source
310
74.5k
                                       ValueType Value) {
311
74.5k
  if (Action == PSK_Reset) {
312
36.9k
    CurrentValue = DefaultValue;
313
36.9k
    CurrentPragmaLocation = PragmaLocation;
314
36.9k
    return;
315
36.9k
  }
316
37.5k
  if (Action & PSK_Push)
317
211
    Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
318
211
                       PragmaLocation);
319
37.3k
  else if (Action & PSK_Pop) {
320
198
    if (!StackSlotLabel.empty()) {
321
9
      // If we've got a label, try to find it and jump there.
322
9
      auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
323
9
        return x.StackSlotLabel == StackSlotLabel;
324
9
      });
325
9
      // If we found the label so pop from there.
326
9
      if (I != Stack.rend()) {
327
5
        CurrentValue = I->Value;
328
5
        CurrentPragmaLocation = I->PragmaLocation;
329
5
        Stack.erase(std::prev(I.base()), Stack.end());
330
5
      }
331
189
    } else if (!Stack.empty()) {
332
179
      // We do not have a label, just pop the last entry.
333
179
      CurrentValue = Stack.back().Value;
334
179
      CurrentPragmaLocation = Stack.back().PragmaLocation;
335
179
      Stack.pop_back();
336
179
    }
337
198
  }
338
37.5k
  if (Action & PSK_Set) {
339
37.3k
    CurrentValue = Value;
340
37.3k
    CurrentPragmaLocation = PragmaLocation;
341
37.3k
  }
342
37.5k
}
clang::Sema::PragmaStack<clang::MSVtorDispAttr::Mode>::Act(clang::SourceLocation, clang::Sema::PragmaMsStackAction, llvm::StringRef, clang::MSVtorDispAttr::Mode)
Line
Count
Source
310
2.26M
                                       ValueType Value) {
311
2.26M
  if (Action == PSK_Reset) {
312
3
    CurrentValue = DefaultValue;
313
3
    CurrentPragmaLocation = PragmaLocation;
314
3
    return;
315
3
  }
316
2.26M
  if (Action & PSK_Push)
317
1.13M
    Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
318
1.13M
                       PragmaLocation);
319
1.13M
  else if (Action & PSK_Pop) {
320
1.13M
    if (!StackSlotLabel.empty()) {
321
1.13M
      // If we've got a label, try to find it and jump there.
322
1.13M
      auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
323
1.13M
        return x.StackSlotLabel == StackSlotLabel;
324
1.13M
      });
325
1.13M
      // If we found the label so pop from there.
326
1.13M
      if (I != Stack.rend()) {
327
1.13M
        CurrentValue = I->Value;
328
1.13M
        CurrentPragmaLocation = I->PragmaLocation;
329
1.13M
        Stack.erase(std::prev(I.base()), Stack.end());
330
1.13M
      }
331
1.13M
    } else 
if (20
!Stack.empty()20
) {
332
16
      // We do not have a label, just pop the last entry.
333
16
      CurrentValue = Stack.back().Value;
334
16
      CurrentPragmaLocation = Stack.back().PragmaLocation;
335
16
      Stack.pop_back();
336
16
    }
337
1.13M
  }
338
2.26M
  if (Action & PSK_Set) {
339
22
    CurrentValue = Value;
340
22
    CurrentPragmaLocation = PragmaLocation;
341
22
  }
342
2.26M
}
clang::Sema::PragmaStack<clang::StringLiteral*>::Act(clang::SourceLocation, clang::Sema::PragmaMsStackAction, llvm::StringRef, clang::StringLiteral*)
Line
Count
Source
310
9.04M
                                       ValueType Value) {
311
9.04M
  if (Action == PSK_Reset) {
312
4
    CurrentValue = DefaultValue;
313
4
    CurrentPragmaLocation = PragmaLocation;
314
4
    return;
315
4
  }
316
9.04M
  if (Action & PSK_Push)
317
4.52M
    Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
318
4.52M
                       PragmaLocation);
319
4.52M
  else if (Action & PSK_Pop) {
320
4.52M
    if (!StackSlotLabel.empty()) {
321
4.52M
      // If we've got a label, try to find it and jump there.
322
4.52M
      auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
323
4.52M
        return x.StackSlotLabel == StackSlotLabel;
324
4.52M
      });
325
4.52M
      // If we found the label so pop from there.
326
4.52M
      if (I != Stack.rend()) {
327
4.52M
        CurrentValue = I->Value;
328
4.52M
        CurrentPragmaLocation = I->PragmaLocation;
329
4.52M
        Stack.erase(std::prev(I.base()), Stack.end());
330
4.52M
      }
331
4.52M
    } else 
if (6
!Stack.empty()6
) {
332
6
      // We do not have a label, just pop the last entry.
333
6
      CurrentValue = Stack.back().Value;
334
6
      CurrentPragmaLocation = Stack.back().PragmaLocation;
335
6
      Stack.pop_back();
336
6
    }
337
4.52M
  }
338
9.04M
  if (Action & PSK_Set) {
339
44
    CurrentValue = Value;
340
44
    CurrentPragmaLocation = PragmaLocation;
341
44
  }
342
9.04M
}
343
344
bool Sema::UnifySection(StringRef SectionName,
345
                        int SectionFlags,
346
5.92k
                        DeclaratorDecl *Decl) {
347
5.92k
  auto Section = Context.SectionInfos.find(SectionName);
348
5.92k
  if (Section == Context.SectionInfos.end()) {
349
174
    Context.SectionInfos[SectionName] =
350
174
        ASTContext::SectionInfo(Decl, SourceLocation(), SectionFlags);
351
174
    return false;
352
174
  }
353
5.74k
  // A pre-declared section takes precedence w/o diagnostic.
354
5.74k
  if (Section->second.SectionFlags == SectionFlags ||
355
5.74k
      
!(Section->second.SectionFlags & ASTContext::PSF_Implicit)13
)
356
5.74k
    return false;
357
3
  auto OtherDecl = Section->second.Decl;
358
3
  Diag(Decl->getLocation(), diag::err_section_conflict)
359
3
      << Decl << OtherDecl;
360
3
  Diag(OtherDecl->getLocation(), diag::note_declared_at)
361
3
      << OtherDecl->getName();
362
3
  if (auto A = Decl->getAttr<SectionAttr>())
363
3
    if (A->isImplicit())
364
2
      Diag(A->getLocation(), diag::note_pragma_entered_here);
365
3
  if (auto A = OtherDecl->getAttr<SectionAttr>())
366
3
    if (A->isImplicit())
367
2
      Diag(A->getLocation(), diag::note_pragma_entered_here);
368
3
  return true;
369
3
}
370
371
bool Sema::UnifySection(StringRef SectionName,
372
                        int SectionFlags,
373
22
                        SourceLocation PragmaSectionLocation) {
374
22
  auto Section = Context.SectionInfos.find(SectionName);
375
22
  if (Section != Context.SectionInfos.end()) {
376
2
    if (Section->second.SectionFlags == SectionFlags)
377
0
      return false;
378
2
    if (!(Section->second.SectionFlags & ASTContext::PSF_Implicit)) {
379
2
      Diag(PragmaSectionLocation, diag::err_section_conflict)
380
2
          << "this" << "a prior #pragma section";
381
2
      Diag(Section->second.PragmaSectionLocation,
382
2
           diag::note_pragma_entered_here);
383
2
      return true;
384
2
    }
385
20
  }
386
20
  Context.SectionInfos[SectionName] =
387
20
      ASTContext::SectionInfo(nullptr, PragmaSectionLocation, SectionFlags);
388
20
  return false;
389
20
}
390
391
/// Called on well formed \#pragma bss_seg().
392
void Sema::ActOnPragmaMSSeg(SourceLocation PragmaLocation,
393
                            PragmaMsStackAction Action,
394
                            llvm::StringRef StackSlotLabel,
395
                            StringLiteral *SegmentName,
396
57
                            llvm::StringRef PragmaName) {
397
57
  PragmaStack<StringLiteral *> *Stack =
398
57
    llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
399
57
        .Case("data_seg", &DataSegStack)
400
57
        .Case("bss_seg", &BSSSegStack)
401
57
        .Case("const_seg", &ConstSegStack)
402
57
        .Case("code_seg", &CodeSegStack);
403
57
  if (Action & PSK_Pop && 
Stack->Stack.empty()7
)
404
0
    Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
405
0
        << "stack empty";
406
57
  if (SegmentName) {
407
45
    if (!checkSectionName(SegmentName->getBeginLoc(), SegmentName->getString()))
408
1
      return;
409
44
410
44
    if (SegmentName->getString() == ".drectve" &&
411
44
        
Context.getTargetInfo().getCXXABI().isMicrosoft()4
)
412
4
      Diag(PragmaLocation, diag::warn_attribute_section_drectve) << PragmaName;
413
44
  }
414
57
415
57
  Stack->Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
416
56
}
417
418
/// Called on well formed \#pragma bss_seg().
419
void Sema::ActOnPragmaMSSection(SourceLocation PragmaLocation,
420
22
                                int SectionFlags, StringLiteral *SegmentName) {
421
22
  UnifySection(SegmentName->getString(), SectionFlags, PragmaLocation);
422
22
}
423
424
void Sema::ActOnPragmaMSInitSeg(SourceLocation PragmaLocation,
425
17
                                StringLiteral *SegmentName) {
426
17
  // There's no stack to maintain, so we just have a current section.  When we
427
17
  // see the default section, reset our current section back to null so we stop
428
17
  // tacking on unnecessary attributes.
429
17
  CurInitSeg = SegmentName->getString() == ".CRT$XCU" ? 
nullptr1
:
SegmentName16
;
430
17
  CurInitSegLoc = PragmaLocation;
431
17
}
432
433
void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
434
46
                             SourceLocation PragmaLoc) {
435
46
436
46
  IdentifierInfo *Name = IdTok.getIdentifierInfo();
437
46
  LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
438
46
  LookupParsedName(Lookup, curScope, nullptr, true);
439
46
440
46
  if (Lookup.empty()) {
441
3
    Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
442
3
      << Name << SourceRange(IdTok.getLocation());
443
3
    return;
444
3
  }
445
43
446
43
  VarDecl *VD = Lookup.getAsSingle<VarDecl>();
447
43
  if (!VD) {
448
0
    Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
449
0
      << Name << SourceRange(IdTok.getLocation());
450
0
    return;
451
0
  }
452
43
453
43
  // Warn if this was used before being marked unused.
454
43
  if (VD->isUsed())
455
1
    Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
456
43
457
43
  VD->addAttr(UnusedAttr::CreateImplicit(Context, UnusedAttr::GNU_unused,
458
43
                                         IdTok.getLocation()));
459
43
}
460
461
6.03M
void Sema::AddCFAuditedAttribute(Decl *D) {
462
6.03M
  SourceLocation Loc = PP.getPragmaARCCFCodeAuditedLoc();
463
6.03M
  if (!Loc.isValid()) 
return6.02M
;
464
13.1k
465
13.1k
  // Don't add a redundant or conflicting attribute.
466
13.1k
  if (D->hasAttr<CFAuditedTransferAttr>() ||
467
13.1k
      D->hasAttr<CFUnknownTransferAttr>())
468
0
    return;
469
13.1k
470
13.1k
  D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Loc));
471
13.1k
}
472
473
namespace {
474
475
Optional<attr::SubjectMatchRule>
476
302
getParentAttrMatcherRule(attr::SubjectMatchRule Rule) {
477
302
  using namespace attr;
478
302
  switch (Rule) {
479
302
  default:
480
206
    return None;
481
302
#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
482
302
#define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated)    \
483
302
  case Value:                                                                  \
484
96
    return Parent;
485
302
#include 
"clang/Basic/AttrSubMatchRulesList.inc"14
486
302
  }
487
302
}
488
489
57
bool isNegatedAttrMatcherSubRule(attr::SubjectMatchRule Rule) {
490
57
  using namespace attr;
491
57
  switch (Rule) {
492
57
  default:
493
4
    return false;
494
57
#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
495
57
#define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated)    \
496
57
  case Value:                                                                  \
497
53
    return IsNegated;
498
57
#include 
"clang/Basic/AttrSubMatchRulesList.inc"5
499
57
  }
500
57
}
501
502
CharSourceRange replacementRangeForListElement(const Sema &S,
503
38
                                               SourceRange Range) {
504
38
  // Make sure that the ',' is removed as well.
505
38
  SourceLocation AfterCommaLoc = Lexer::findLocationAfterToken(
506
38
      Range.getEnd(), tok::comma, S.getSourceManager(), S.getLangOpts(),
507
38
      /*SkipTrailingWhitespaceAndNewLine=*/false);
508
38
  if (AfterCommaLoc.isValid())
509
15
    return CharSourceRange::getCharRange(Range.getBegin(), AfterCommaLoc);
510
23
  else
511
23
    return CharSourceRange::getTokenRange(Range);
512
38
}
513
514
std::string
515
17
attrMatcherRuleListToString(ArrayRef<attr::SubjectMatchRule> Rules) {
516
17
  std::string Result;
517
17
  llvm::raw_string_ostream OS(Result);
518
21
  for (const auto &I : llvm::enumerate(Rules)) {
519
21
    if (I.index())
520
4
      OS << (I.index() == Rules.size() - 1 ? ", and " : 
", "0
);
521
21
    OS << "'" << attr::getSubjectMatchRuleSpelling(I.value()) << "'";
522
21
  }
523
17
  return OS.str();
524
17
}
525
526
} // end anonymous namespace
527
528
void Sema::ActOnPragmaAttributeAttribute(
529
    ParsedAttr &Attribute, SourceLocation PragmaLoc,
530
654
    attr::ParsedSubjectMatchRuleSet Rules) {
531
654
  Attribute.setIsPragmaClangAttribute();
532
654
  SmallVector<attr::SubjectMatchRule, 4> SubjectMatchRules;
533
654
  // Gather the subject match rules that are supported by the attribute.
534
654
  SmallVector<std::pair<attr::SubjectMatchRule, bool>, 4>
535
654
      StrictSubjectMatchRuleSet;
536
654
  Attribute.getMatchRules(LangOpts, StrictSubjectMatchRuleSet);
537
654
538
654
  // Figure out which subject matching rules are valid.
539
654
  if (StrictSubjectMatchRuleSet.empty()) {
540
82
    // Check for contradicting match rules. Contradicting match rules are
541
82
    // either:
542
82
    //  - a top-level rule and one of its sub-rules. E.g. variable and
543
82
    //    variable(is_parameter).
544
82
    //  - a sub-rule and a sibling that's negated. E.g.
545
82
    //    variable(is_thread_local) and variable(unless(is_parameter))
546
82
    llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
547
82
        RulesToFirstSpecifiedNegatedSubRule;
548
151
    for (const auto &Rule : Rules) {
549
151
      attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
550
151
      Optional<attr::SubjectMatchRule> ParentRule =
551
151
          getParentAttrMatcherRule(MatchRule);
552
151
      if (!ParentRule)
553
103
        continue;
554
48
      auto It = Rules.find(*ParentRule);
555
48
      if (It != Rules.end()) {
556
11
        // A sub-rule contradicts a parent rule.
557
11
        Diag(Rule.second.getBegin(),
558
11
             diag::err_pragma_attribute_matcher_subrule_contradicts_rule)
559
11
            << attr::getSubjectMatchRuleSpelling(MatchRule)
560
11
            << attr::getSubjectMatchRuleSpelling(*ParentRule) << It->second
561
11
            << FixItHint::CreateRemoval(
562
11
                   replacementRangeForListElement(*this, Rule.second));
563
11
        // Keep going without removing this rule as it won't change the set of
564
11
        // declarations that receive the attribute.
565
11
        continue;
566
11
      }
567
37
      if (isNegatedAttrMatcherSubRule(MatchRule))
568
12
        RulesToFirstSpecifiedNegatedSubRule.insert(
569
12
            std::make_pair(*ParentRule, Rule));
570
37
    }
571
82
    bool IgnoreNegatedSubRules = false;
572
151
    for (const auto &Rule : Rules) {
573
151
      attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
574
151
      Optional<attr::SubjectMatchRule> ParentRule =
575
151
          getParentAttrMatcherRule(MatchRule);
576
151
      if (!ParentRule)
577
103
        continue;
578
48
      auto It = RulesToFirstSpecifiedNegatedSubRule.find(*ParentRule);
579
48
      if (It != RulesToFirstSpecifiedNegatedSubRule.end() &&
580
48
          
It->second != Rule14
) {
581
6
        // Negated sub-rule contradicts another sub-rule.
582
6
        Diag(
583
6
            It->second.second.getBegin(),
584
6
            diag::
585
6
                err_pragma_attribute_matcher_negated_subrule_contradicts_subrule)
586
6
            << attr::getSubjectMatchRuleSpelling(
587
6
                   attr::SubjectMatchRule(It->second.first))
588
6
            << attr::getSubjectMatchRuleSpelling(MatchRule) << Rule.second
589
6
            << FixItHint::CreateRemoval(
590
6
                   replacementRangeForListElement(*this, It->second.second));
591
6
        // Keep going but ignore all of the negated sub-rules.
592
6
        IgnoreNegatedSubRules = true;
593
6
        RulesToFirstSpecifiedNegatedSubRule.erase(It);
594
6
      }
595
48
    }
596
82
597
82
    if (!IgnoreNegatedSubRules) {
598
76
      for (const auto &Rule : Rules)
599
131
        SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
600
76
    } else {
601
20
      for (const auto &Rule : Rules) {
602
20
        if (!isNegatedAttrMatcherSubRule(attr::SubjectMatchRule(Rule.first)))
603
14
          SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
604
20
      }
605
6
    }
606
82
    Rules.clear();
607
572
  } else {
608
7.83k
    for (const auto &Rule : StrictSubjectMatchRuleSet) {
609
7.83k
      if (Rules.erase(Rule.first)) {
610
1.11k
        // Add the rule to the set of attribute receivers only if it's supported
611
1.11k
        // in the current language mode.
612
1.11k
        if (Rule.second)
613
1.10k
          SubjectMatchRules.push_back(Rule.first);
614
1.11k
      }
615
7.83k
    }
616
572
  }
617
654
618
654
  if (!Rules.empty()) {
619
17
    auto Diagnostic =
620
17
        Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers)
621
17
        << Attribute.getName();
622
17
    SmallVector<attr::SubjectMatchRule, 2> ExtraRules;
623
21
    for (const auto &Rule : Rules) {
624
21
      ExtraRules.push_back(attr::SubjectMatchRule(Rule.first));
625
21
      Diagnostic << FixItHint::CreateRemoval(
626
21
          replacementRangeForListElement(*this, Rule.second));
627
21
    }
628
17
    Diagnostic << attrMatcherRuleListToString(ExtraRules);
629
17
  }
630
654
631
654
  if (PragmaAttributeStack.empty()) {
632
1
    Diag(PragmaLoc, diag::err_pragma_attr_attr_no_push);
633
1
    return;
634
1
  }
635
653
636
653
  PragmaAttributeStack.back().Entries.push_back(
637
653
      {PragmaLoc, &Attribute, std::move(SubjectMatchRules), /*IsUsed=*/false});
638
653
}
639
640
void Sema::ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc,
641
653
                                         const IdentifierInfo *Namespace) {
642
653
  PragmaAttributeStack.emplace_back();
643
653
  PragmaAttributeStack.back().Loc = PragmaLoc;
644
653
  PragmaAttributeStack.back().Namespace = Namespace;
645
653
}
646
647
void Sema::ActOnPragmaAttributePop(SourceLocation PragmaLoc,
648
646
                                   const IdentifierInfo *Namespace) {
649
646
  if (PragmaAttributeStack.empty()) {
650
4
    Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
651
4
    return;
652
4
  }
653
642
654
642
  // Dig back through the stack trying to find the most recently pushed group
655
642
  // that in Namespace. Note that this works fine if no namespace is present,
656
642
  // think of push/pops without namespaces as having an implicit "nullptr"
657
642
  // namespace.
658
646
  
for (size_t Index = PragmaAttributeStack.size(); 642
Index;) {
659
644
    --Index;
660
644
    if (PragmaAttributeStack[Index].Namespace == Namespace) {
661
640
      for (const PragmaAttributeEntry &Entry :
662
640
           PragmaAttributeStack[Index].Entries) {
663
640
        if (!Entry.IsUsed) {
664
53
          assert(Entry.Attribute && "Expected an attribute");
665
53
          Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused)
666
53
              << *Entry.Attribute;
667
53
          Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
668
53
        }
669
640
      }
670
640
      PragmaAttributeStack.erase(PragmaAttributeStack.begin() + Index);
671
640
      return;
672
640
    }
673
644
  }
674
642
675
642
  
if (2
Namespace2
)
676
1
    Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch)
677
1
        << 0 << Namespace->getName();
678
1
  else
679
1
    Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
680
2
}
681
682
24.0M
void Sema::AddPragmaAttributes(Scope *S, Decl *D) {
683
24.0M
  if (PragmaAttributeStack.empty())
684
23.9M
    return;
685
293k
  
for (auto &Group : PragmaAttributeStack)73.9k
{
686
293k
    for (auto &Entry : Group.Entries) {
687
293k
      ParsedAttr *Attribute = Entry.Attribute;
688
293k
      assert(Attribute && "Expected an attribute");
689
293k
      assert(Attribute->isPragmaClangAttribute() &&
690
293k
             "expected #pragma clang attribute");
691
293k
692
293k
      // Ensure that the attribute can be applied to the given declaration.
693
293k
      bool Applies = false;
694
582k
      for (const auto &Rule : Entry.MatchRules) {
695
582k
        if (Attribute->appliesToDecl(D, Rule)) {
696
111k
          Applies = true;
697
111k
          break;
698
111k
        }
699
582k
      }
700
293k
      if (!Applies)
701
181k
        continue;
702
111k
      Entry.IsUsed = true;
703
111k
      PragmaAttributeCurrentTargetDecl = D;
704
111k
      ParsedAttributesView Attrs;
705
111k
      Attrs.addAtEnd(Attribute);
706
111k
      ProcessDeclAttributeList(S, D, Attrs);
707
111k
      PragmaAttributeCurrentTargetDecl = nullptr;
708
111k
    }
709
293k
  }
710
73.9k
}
711
712
22
void Sema::PrintPragmaAttributeInstantiationPoint() {
713
22
  assert(PragmaAttributeCurrentTargetDecl && "Expected an active declaration");
714
22
  Diags.Report(PragmaAttributeCurrentTargetDecl->getBeginLoc(),
715
22
               diag::note_pragma_attribute_applied_decl_here);
716
22
}
717
718
40.3k
void Sema::DiagnoseUnterminatedPragmaAttribute() {
719
40.3k
  if (PragmaAttributeStack.empty())
720
40.3k
    return;
721
3
  Diag(PragmaAttributeStack.back().Loc, diag::err_pragma_attribute_no_pop_eof);
722
3
}
723
724
29
void Sema::ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc) {
725
29
  if(On)
726
13
    OptimizeOffPragmaLocation = SourceLocation();
727
16
  else
728
16
    OptimizeOffPragmaLocation = PragmaLoc;
729
29
}
730
731
3.24M
void Sema::AddRangeBasedOptnone(FunctionDecl *FD) {
732
3.24M
  // In the future, check other pragmas if they're implemented (e.g. pragma
733
3.24M
  // optimize 0 will probably map to this functionality too).
734
3.24M
  if(OptimizeOffPragmaLocation.isValid())
735
28
    AddOptnoneAttributeIfNoConflicts(FD, OptimizeOffPragmaLocation);
736
3.24M
}
737
738
void Sema::AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD,
739
28
                                            SourceLocation Loc) {
740
28
  // Don't add a conflicting attribute. No diagnostic is needed.
741
28
  if (FD->hasAttr<MinSizeAttr>() || 
FD->hasAttr<AlwaysInlineAttr>()25
)
742
6
    return;
743
22
744
22
  // Add attributes only if required. Optnone requires noinline as well, but if
745
22
  // either is already present then don't bother adding them.
746
22
  if (!FD->hasAttr<OptimizeNoneAttr>())
747
22
    FD->addAttr(OptimizeNoneAttr::CreateImplicit(Context, Loc));
748
22
  if (!FD->hasAttr<NoInlineAttr>())
749
22
    FD->addAttr(NoInlineAttr::CreateImplicit(Context, Loc));
750
22
}
751
752
typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
753
enum : unsigned { NoVisibility = ~0U };
754
755
5.27M
void Sema::AddPushedVisibilityAttribute(Decl *D) {
756
5.27M
  if (!VisContext)
757
5.27M
    return;
758
1.26k
759
1.26k
  NamedDecl *ND = dyn_cast<NamedDecl>(D);
760
1.26k
  if (ND && ND->getExplicitVisibility(NamedDecl::VisibilityForValue))
761
257
    return;
762
1.00k
763
1.00k
  VisStack *Stack = static_cast<VisStack*>(VisContext);
764
1.00k
  unsigned rawType = Stack->back().first;
765
1.00k
  if (rawType == NoVisibility) 
return30
;
766
979
767
979
  VisibilityAttr::VisibilityType type
768
979
    = (VisibilityAttr::VisibilityType) rawType;
769
979
  SourceLocation loc = Stack->back().second;
770
979
771
979
  D->addAttr(VisibilityAttr::CreateImplicit(Context, type, loc));
772
979
}
773
774
/// FreeVisContext - Deallocate and null out VisContext.
775
82
void Sema::FreeVisContext() {
776
82
  delete static_cast<VisStack*>(VisContext);
777
82
  VisContext = nullptr;
778
82
}
779
780
86
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
781
86
  // Put visibility on stack.
782
86
  if (!S.VisContext)
783
82
    S.VisContext = new VisStack;
784
86
785
86
  VisStack *Stack = static_cast<VisStack*>(S.VisContext);
786
86
  Stack->push_back(std::make_pair(type, loc));
787
86
}
788
789
void Sema::ActOnPragmaVisibility(const IdentifierInfo* VisType,
790
127
                                 SourceLocation PragmaLoc) {
791
127
  if (VisType) {
792
65
    // Compute visibility to use.
793
65
    VisibilityAttr::VisibilityType T;
794
65
    if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->getName(), T)) {
795
1
      Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
796
1
      return;
797
1
    }
798
64
    PushPragmaVisibility(*this, T, PragmaLoc);
799
64
  } else {
800
62
    PopPragmaVisibility(false, PragmaLoc);
801
62
  }
802
127
}
803
804
97
void Sema::ActOnPragmaFPContract(LangOptions::FPContractModeKind FPC) {
805
97
  switch (FPC) {
806
97
  case LangOptions::FPC_On:
807
17
    FPFeatures.setAllowFPContractWithinStatement();
808
17
    break;
809
97
  case LangOptions::FPC_Fast:
810
6
    FPFeatures.setAllowFPContractAcrossStatement();
811
6
    break;
812
97
  case LangOptions::FPC_Off:
813
74
    FPFeatures.setDisallowFPContract();
814
74
    break;
815
97
  }
816
97
}
817
818
3
void Sema::ActOnPragmaFEnvAccess(LangOptions::FEnvAccessModeKind FPC) {
819
3
  switch (FPC) {
820
3
  case LangOptions::FEA_On:
821
1
    FPFeatures.setAllowFEnvAccess();
822
1
    break;
823
3
  case LangOptions::FEA_Off:
824
2
    FPFeatures.setDisallowFEnvAccess();
825
2
    break;
826
3
  }
827
3
}
828
829
830
void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
831
22
                                       SourceLocation Loc) {
832
22
  // Visibility calculations will consider the namespace's visibility.
833
22
  // Here we just want to note that we're in a visibility context
834
22
  // which overrides any enclosing #pragma context, but doesn't itself
835
22
  // contribute visibility.
836
22
  PushPragmaVisibility(*this, NoVisibility, Loc);
837
22
}
838
839
84
void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
840
84
  if (!VisContext) {
841
2
    Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
842
2
    return;
843
2
  }
844
82
845
82
  // Pop visibility from stack
846
82
  VisStack *Stack = static_cast<VisStack*>(VisContext);
847
82
848
82
  const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
849
82
  bool StartsWithPragma = Back->first != NoVisibility;
850
82
  if (StartsWithPragma && 
IsNamespaceEnd60
) {
851
1
    Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
852
1
    Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
853
1
854
1
    // For better error recovery, eat all pushes inside the namespace.
855
1
    do {
856
1
      Stack->pop_back();
857
1
      Back = &Stack->back();
858
1
      StartsWithPragma = Back->first != NoVisibility;
859
1
    } while (StartsWithPragma);
860
81
  } else if (!StartsWithPragma && 
!IsNamespaceEnd22
) {
861
1
    Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
862
1
    Diag(Back->second, diag::note_surrounding_namespace_starts_here);
863
1
    return;
864
1
  }
865
81
866
81
  Stack->pop_back();
867
81
  // To simplify the implementation, never keep around an empty stack.
868
81
  if (Stack->empty())
869
78
    FreeVisContext();
870
81
}