27#include "llvm/ADT/ArrayRef.h"
28#include "llvm/ADT/StringSwitch.h"
37 Token &FirstToken)
override;
41 explicit PragmaGCCVisibilityHandler() :
PragmaHandler(
"visibility") {}
43 Token &FirstToken)
override;
49 Token &FirstToken)
override;
55 Token &FirstToken)
override;
59 explicit PragmaClangSectionHandler(
Sema &S)
62 Token &FirstToken)
override;
69 explicit PragmaMSStructHandler() :
PragmaHandler(
"ms_struct") {}
71 Token &FirstToken)
override;
77 Token &FirstToken)
override;
83 Token &FirstToken)
override;
87 explicit PragmaRedefineExtnameHandler() :
PragmaHandler(
"redefine_extname") {}
89 Token &FirstToken)
override;
93 PragmaOpenCLExtensionHandler() :
PragmaHandler(
"EXTENSION") {}
95 Token &FirstToken)
override;
102 Token &FirstToken)
override;
109 PragmaSTDC_FENV_ACCESSHandler() :
PragmaHandler(
"FENV_ACCESS") {}
112 Token &Tok)
override {
113 Token PragmaName = Tok;
125 Toks[0].startToken();
126 Toks[0].setKind(tok::annot_pragma_fenv_access);
129 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
131 PP.EnterTokenStream(Toks,
true,
137struct PragmaSTDC_CX_LIMITED_RANGEHandler :
public PragmaHandler {
138 PragmaSTDC_CX_LIMITED_RANGEHandler() :
PragmaHandler(
"CX_LIMITED_RANGE") {}
141 Token &Tok)
override {
149 Toks[0].startToken();
150 Toks[0].setKind(tok::annot_pragma_cx_limited_range);
153 Toks[0].setAnnotationValue(
154 reinterpret_cast<void *
>(
static_cast<uintptr_t>(OOS)));
155 PP.EnterTokenStream(Toks,
true,
162 PragmaSTDC_FENV_ROUNDHandler() :
PragmaHandler(
"FENV_ROUND") {}
165 Token &Tok)
override;
170 PragmaSTDC_UnknownHandler() =
default;
173 Token &UnknownTok)
override {
175 PP.
Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
182 Token &FirstToken)
override;
188template <diag::kind IgnoredDiag>
190 PragmaNoSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
192 Token &FirstToken)
override;
195struct PragmaNoOpenMPHandler
196 :
public PragmaNoSupportHandler<diag::warn_pragma_omp_ignored> {
197 PragmaNoOpenMPHandler() : PragmaNoSupportHandler(
"omp") {}
200struct PragmaNoOpenACCHandler
201 :
public PragmaNoSupportHandler<diag::warn_pragma_acc_ignored> {
202 PragmaNoOpenACCHandler() : PragmaNoSupportHandler(
"acc") {}
211 PragmaSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
213 Token &FirstToken)
override;
216struct PragmaOpenMPHandler
217 :
public PragmaSupportHandler<tok::annot_pragma_openmp,
218 tok::annot_pragma_openmp_end,
219 diag::err_omp_unexpected_directive> {
220 PragmaOpenMPHandler() : PragmaSupportHandler(
"omp") {}
223struct PragmaOpenACCHandler
224 :
public PragmaSupportHandler<tok::annot_pragma_openacc,
225 tok::annot_pragma_openacc_end,
226 diag::err_acc_unexpected_directive> {
227 PragmaOpenACCHandler() : PragmaSupportHandler(
"acc") {}
232 PragmaCommentHandler(
Sema &Actions)
235 Token &FirstToken)
override;
242 PragmaDetectMismatchHandler(
Sema &Actions)
245 Token &FirstToken)
override;
252 PragmaFloatControlHandler(
Sema &Actions)
255 Token &FirstToken)
override;
259 explicit PragmaMSPointersToMembers() :
PragmaHandler(
"pointers_to_members") {}
261 Token &FirstToken)
override;
267 Token &FirstToken)
override;
273 Token &FirstToken)
override;
278 PragmaOptimizeHandler(
Sema &S)
281 Token &FirstToken)
override;
290 Token &FirstToken)
override;
296 Token &FirstToken)
override;
305 PragmaMSFenvAccessHandler() :
PragmaHandler(
"fenv_access") {}
307 Token &FirstToken)
override {
317 if (Tok.
isNot(tok::l_paren)) {
323 if (Tok.
isNot(tok::identifier)) {
329 if (II->
isStr(
"on")) {
332 }
else if (II->
isStr(
"off")) {
339 if (Tok.
isNot(tok::r_paren)) {
346 if (Tok.
isNot(tok::eod)) {
354 Toks[0].startToken();
355 Toks[0].setKind(tok::annot_pragma_fenv_access_ms);
358 Toks[0].setAnnotationValue(
359 reinterpret_cast<void*
>(
static_cast<uintptr_t>(OOS)));
360 PP.EnterTokenStream(Toks,
true,
365struct PragmaForceCUDAHostDeviceHandler :
public PragmaHandler {
366 PragmaForceCUDAHostDeviceHandler(
Sema &Actions)
367 :
PragmaHandler(
"force_cuda_host_device"), Actions(Actions) {}
369 Token &FirstToken)
override;
378 :
PragmaHandler(
"attribute"), AttributesForPragmaAttribute(AttrFactory) {}
380 Token &FirstToken)
override;
387 PragmaMaxTokensHereHandler() :
PragmaHandler(
"max_tokens_here") {}
389 Token &FirstToken)
override;
393 PragmaMaxTokensTotalHandler() :
PragmaHandler(
"max_tokens_total") {}
395 Token &FirstToken)
override;
399 PragmaRISCVHandler(
Sema &Actions)
402 Token &FirstToken)
override;
414void Parser::initializePragmaHandlers() {
415 AlignHandler = std::make_unique<PragmaAlignHandler>();
418 GCCVisibilityHandler = std::make_unique<PragmaGCCVisibilityHandler>();
421 OptionsHandler = std::make_unique<PragmaOptionsHandler>();
424 PackHandler = std::make_unique<PragmaPackHandler>();
427 MSStructHandler = std::make_unique<PragmaMSStructHandler>();
430 UnusedHandler = std::make_unique<PragmaUnusedHandler>();
433 WeakHandler = std::make_unique<PragmaWeakHandler>();
436 RedefineExtnameHandler = std::make_unique<PragmaRedefineExtnameHandler>();
439 FPContractHandler = std::make_unique<PragmaFPContractHandler>();
442 STDCFenvAccessHandler = std::make_unique<PragmaSTDC_FENV_ACCESSHandler>();
445 STDCFenvRoundHandler = std::make_unique<PragmaSTDC_FENV_ROUNDHandler>();
448 STDCCXLIMITHandler = std::make_unique<PragmaSTDC_CX_LIMITED_RANGEHandler>();
451 STDCUnknownHandler = std::make_unique<PragmaSTDC_UnknownHandler>();
454 PCSectionHandler = std::make_unique<PragmaClangSectionHandler>(Actions);
458 OpenCLExtensionHandler = std::make_unique<PragmaOpenCLExtensionHandler>();
464 OpenMPHandler = std::make_unique<PragmaOpenMPHandler>();
466 OpenMPHandler = std::make_unique<PragmaNoOpenMPHandler>();
470 OpenACCHandler = std::make_unique<PragmaOpenACCHandler>();
472 OpenACCHandler = std::make_unique<PragmaNoOpenACCHandler>();
477 MSCommentHandler = std::make_unique<PragmaCommentHandler>(Actions);
481 FloatControlHandler = std::make_unique<PragmaFloatControlHandler>(Actions);
484 MSDetectMismatchHandler =
485 std::make_unique<PragmaDetectMismatchHandler>(Actions);
487 MSPointersToMembers = std::make_unique<PragmaMSPointersToMembers>();
489 MSVtorDisp = std::make_unique<PragmaMSVtorDisp>();
491 MSInitSeg = std::make_unique<PragmaMSPragma>(
"init_seg");
493 MSDataSeg = std::make_unique<PragmaMSPragma>(
"data_seg");
495 MSBSSSeg = std::make_unique<PragmaMSPragma>(
"bss_seg");
497 MSConstSeg = std::make_unique<PragmaMSPragma>(
"const_seg");
499 MSCodeSeg = std::make_unique<PragmaMSPragma>(
"code_seg");
501 MSSection = std::make_unique<PragmaMSPragma>(
"section");
503 MSStrictGuardStackCheck =
504 std::make_unique<PragmaMSPragma>(
"strict_gs_check");
506 MSFunction = std::make_unique<PragmaMSPragma>(
"function");
508 MSAllocText = std::make_unique<PragmaMSPragma>(
"alloc_text");
510 MSOptimize = std::make_unique<PragmaMSPragma>(
"optimize");
512 MSRuntimeChecks = std::make_unique<PragmaMSRuntimeChecksHandler>();
514 MSIntrinsic = std::make_unique<PragmaMSPragma>(
"intrinsic");
516 MSFenvAccess = std::make_unique<PragmaMSFenvAccessHandler>();
521 CUDAForceHostDeviceHandler =
522 std::make_unique<PragmaForceCUDAHostDeviceHandler>(Actions);
526 OptimizeHandler = std::make_unique<PragmaOptimizeHandler>(Actions);
529 LoopHintHandler = std::make_unique<PragmaLoopHintHandler>();
532 UnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"unroll");
536 NoUnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"nounroll");
540 UnrollAndJamHintHandler =
541 std::make_unique<PragmaUnrollHintHandler>(
"unroll_and_jam");
544 NoUnrollAndJamHintHandler =
545 std::make_unique<PragmaUnrollHintHandler>(
"nounroll_and_jam");
548 FPHandler = std::make_unique<PragmaFPHandler>();
551 AttributePragmaHandler =
552 std::make_unique<PragmaAttributeHandler>(AttrFactory);
555 MaxTokensHerePragmaHandler = std::make_unique<PragmaMaxTokensHereHandler>();
558 MaxTokensTotalPragmaHandler = std::make_unique<PragmaMaxTokensTotalHandler>();
562 RISCVPragmaHandler = std::make_unique<PragmaRISCVHandler>(Actions);
567void Parser::resetPragmaHandlers() {
570 AlignHandler.reset();
572 GCCVisibilityHandler.reset();
574 OptionsHandler.reset();
578 MSStructHandler.reset();
580 UnusedHandler.reset();
584 RedefineExtnameHandler.reset();
588 OpenCLExtensionHandler.reset();
592 OpenMPHandler.reset();
595 OpenACCHandler.reset();
600 MSCommentHandler.reset();
604 PCSectionHandler.reset();
607 FloatControlHandler.reset();
610 MSDetectMismatchHandler.reset();
612 MSPointersToMembers.reset();
628 MSStrictGuardStackCheck.reset();
634 MSRuntimeChecks.reset();
640 MSFenvAccess.reset();
645 CUDAForceHostDeviceHandler.reset();
649 FPContractHandler.reset();
652 STDCFenvAccessHandler.reset();
655 STDCFenvRoundHandler.reset();
658 STDCCXLIMITHandler.reset();
661 STDCUnknownHandler.reset();
664 OptimizeHandler.reset();
667 LoopHintHandler.reset();
671 UnrollHintHandler.reset();
675 NoUnrollHintHandler.reset();
678 UnrollAndJamHintHandler.reset();
681 NoUnrollAndJamHintHandler.reset();
687 AttributePragmaHandler.reset();
690 MaxTokensHerePragmaHandler.reset();
693 MaxTokensTotalPragmaHandler.reset();
697 RISCVPragmaHandler.reset();
701void Parser::HandlePragmaUnused() {
702 assert(Tok.
is(tok::annot_pragma_unused));
708void Parser::HandlePragmaVisibility() {
709 assert(Tok.
is(tok::annot_pragma_vis));
716void Parser::HandlePragmaPack() {
717 assert(Tok.
is(tok::annot_pragma_pack));
725 ConsumeAnnotationToken();
733 ConsumeAnnotationToken();
736void Parser::HandlePragmaMSStruct() {
737 assert(Tok.
is(tok::annot_pragma_msstruct));
741 ConsumeAnnotationToken();
744void Parser::HandlePragmaAlign() {
745 assert(Tok.
is(tok::annot_pragma_align));
751 ConsumeAnnotationToken();
754void Parser::HandlePragmaDump() {
755 assert(Tok.
is(tok::annot_pragma_dump));
756 ConsumeAnnotationToken();
757 if (Tok.
is(tok::eod)) {
758 PP.
Diag(Tok, diag::warn_pragma_debug_missing_argument) <<
"dump";
760 if (Tok.
isNot(tok::identifier)) {
761 PP.
Diag(Tok, diag::warn_pragma_debug_unexpected_argument);
763 ExpectAndConsume(tok::eod);
777 PP.
Diag(StartLoc, diag::warn_pragma_debug_dependent_argument)
785 ExpectAndConsume(tok::eod);
788void Parser::HandlePragmaWeak() {
789 assert(Tok.
is(tok::annot_pragma_weak));
796void Parser::HandlePragmaWeakAlias() {
797 assert(Tok.
is(tok::annot_pragma_weakalias));
806 WeakNameLoc, AliasNameLoc);
810void Parser::HandlePragmaRedefineExtname() {
811 assert(Tok.
is(tok::annot_pragma_redefine_extname));
820 RedefNameLoc, AliasNameLoc);
823void Parser::HandlePragmaFPContract() {
824 assert(Tok.
is(tok::annot_pragma_fp_contract));
851void Parser::HandlePragmaFloatControl() {
852 assert(Tok.
is(tok::annot_pragma_float_control));
867void Parser::HandlePragmaFEnvAccess() {
868 assert(Tok.
is(tok::annot_pragma_fenv_access) ||
869 Tok.
is(tok::annot_pragma_fenv_access_ms));
891void Parser::HandlePragmaFEnvRound() {
892 assert(Tok.
is(tok::annot_pragma_fenv_round));
893 auto RM =
static_cast<llvm::RoundingMode
>(
900void Parser::HandlePragmaCXLimitedRange() {
901 assert(Tok.
is(tok::annot_pragma_cx_limited_range));
927 assert(Tok.
is(tok::annot_pragma_captured));
928 ConsumeAnnotationToken();
930 if (Tok.
isNot(tok::l_brace)) {
931 PP.
Diag(Tok, diag::err_expected) << tok::l_brace;
943 CapturedRegionScope.Exit();
954 enum OpenCLExtState :
char {
955 Disable, Enable,
Begin, End
957 typedef std::pair<const IdentifierInfo *, OpenCLExtState> OpenCLExtData;
960void Parser::HandlePragmaOpenCLExtension() {
961 assert(Tok.
is(tok::annot_pragma_opencl_extension));
963 auto State =
Data->second;
964 auto Ident =
Data->first;
966 ConsumeAnnotationToken();
969 auto Name = Ident->getName();
974 if (State == Disable)
977 PP.
Diag(NameLoc, diag::warn_pragma_expected_predicate) << 1;
978 }
else if (State ==
Begin) {
979 if (!Opt.isKnown(Name) || !Opt.isSupported(Name,
getLangOpts())) {
983 Opt.acceptsPragma(Name);
985 }
else if (State == End) {
988 }
else if (!Opt.isKnown(Name) || !Opt.isWithPragma(Name))
989 PP.
Diag(NameLoc, diag::warn_pragma_unknown_extension) << Ident;
990 else if (Opt.isSupportedExtension(Name,
getLangOpts()))
991 Opt.enable(Name, State == Enable);
992 else if (Opt.isSupportedCoreOrOptionalCore(Name,
getLangOpts()))
993 PP.
Diag(NameLoc, diag::warn_pragma_extension_is_core) << Ident;
995 PP.
Diag(NameLoc, diag::warn_pragma_unsupported_extension) << Ident;
998void Parser::HandlePragmaMSPointersToMembers() {
999 assert(Tok.
is(tok::annot_pragma_ms_pointers_to_members));
1007void Parser::HandlePragmaMSVtorDisp() {
1008 assert(Tok.
is(tok::annot_pragma_ms_vtordisp));
1017void Parser::HandlePragmaMSPragma() {
1018 assert(Tok.
is(tok::annot_pragma_ms_pragma));
1022 PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second,
true,
1033 llvm::StringSwitch<PragmaHandler>(PragmaName)
1034 .Case(
"data_seg", &Parser::HandlePragmaMSSegment)
1035 .Case(
"bss_seg", &Parser::HandlePragmaMSSegment)
1036 .Case(
"const_seg", &Parser::HandlePragmaMSSegment)
1037 .Case(
"code_seg", &Parser::HandlePragmaMSSegment)
1038 .Case(
"section", &Parser::HandlePragmaMSSection)
1039 .Case(
"init_seg", &Parser::HandlePragmaMSInitSeg)
1040 .Case(
"strict_gs_check", &Parser::HandlePragmaMSStrictGuardStackCheck)
1041 .Case(
"function", &Parser::HandlePragmaMSFunction)
1042 .Case(
"alloc_text", &Parser::HandlePragmaMSAllocText)
1043 .Case(
"optimize", &Parser::HandlePragmaMSOptimize)
1044 .Case(
"intrinsic", &Parser::HandlePragmaMSIntrinsic);
1046 if (!(this->*Handler)(PragmaName, PragmaLocation)) {
1049 while (Tok.
isNot(tok::eof))
1055bool Parser::HandlePragmaMSSection(StringRef PragmaName,
1057 if (Tok.
isNot(tok::l_paren)) {
1058 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1063 if (Tok.
isNot(tok::string_literal)) {
1064 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1073 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1078 bool SectionFlagsAreDefault =
true;
1079 while (Tok.
is(tok::comma)) {
1084 if (Tok.
is(tok::kw_long) || Tok.
is(tok::kw_short)) {
1090 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren)
1095 llvm::StringSwitch<ASTContext::PragmaSectionFlag>(
1108 ? diag::warn_pragma_invalid_specific_action
1109 : diag::warn_pragma_unsupported_action)
1113 SectionFlags |= Flag;
1114 SectionFlagsAreDefault =
false;
1119 if (SectionFlagsAreDefault)
1121 if (Tok.
isNot(tok::r_paren)) {
1122 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1126 if (Tok.
isNot(tok::eof)) {
1127 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1136bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
1138 if (Tok.
isNot(tok::l_paren)) {
1139 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1144 StringRef SlotLabel;
1147 if (PushPop ==
"push")
1149 else if (PushPop ==
"pop")
1152 PP.
Diag(PragmaLocation,
1153 diag::warn_pragma_expected_section_push_pop_or_name)
1159 if (Tok.
is(tok::comma)) {
1165 if (Tok.
is(tok::comma))
1167 else if (Tok.
isNot(tok::r_paren)) {
1168 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc)
1173 }
else if (Tok.
isNot(tok::r_paren)) {
1174 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc) << PragmaName;
1181 if (Tok.
isNot(tok::r_paren)) {
1182 if (Tok.
isNot(tok::string_literal)) {
1184 diag::warn_pragma_expected_section_name :
1185 diag::warn_pragma_expected_section_label_or_name :
1186 diag::warn_pragma_expected_section_push_pop_or_name;
1187 PP.
Diag(PragmaLocation, DiagID) << PragmaName;
1193 SegmentName = cast<StringLiteral>(StringResult.
get());
1195 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1203 if (Tok.
isNot(tok::r_paren)) {
1204 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1208 if (Tok.
isNot(tok::eof)) {
1209 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1215 SegmentName, PragmaName);
1219bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
1221 if (
getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) {
1222 PP.
Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target);
1226 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1234 StringRef Section = llvm::StringSwitch<StringRef>(II->
getName())
1235 .Case(
"compiler",
"\".CRT$XCC\"")
1236 .Case(
"lib",
"\".CRT$XCL\"")
1237 .Case(
"user",
"\".CRT$XCU\"")
1240 if (!Section.empty()) {
1244 Toks[0].
setKind(tok::string_literal);
1252 }
else if (Tok.
is(tok::string_literal)) {
1256 SegmentName = cast<StringLiteral>(StringResult.
get());
1258 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1266 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName;
1270 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1272 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1280bool Parser::HandlePragmaMSStrictGuardStackCheck(
1282 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1287 if (Tok.
is(tok::identifier)) {
1289 if (PushPop ==
"push") {
1292 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_punc,
1295 }
else if (PushPop ==
"pop") {
1304 if (II && II->
isStr(
"off")) {
1307 }
else if (II && II->
isStr(
"on")) {
1318 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1322 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1330bool Parser::HandlePragmaMSAllocText(StringRef PragmaName,
1332 Token FirstTok = Tok;
1333 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1338 if (Tok.
is(tok::string_literal)) {
1344 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1349 }
else if (Tok.
is(tok::identifier)) {
1353 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1358 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
1364 if (Tok.
isNot(tok::identifier)) {
1374 if (Tok.
isNot(tok::comma))
1379 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1381 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1391 std::string ClangLoopStr(
"clang loop ");
1394 return std::string(llvm::StringSwitch<StringRef>(Str)
1395 .Case(
"loop", ClangLoopStr)
1396 .Case(
"unroll_and_jam", Str)
1397 .Case(
"unroll", Str)
1401bool Parser::HandlePragmaLoopHint(
LoopHint &Hint) {
1402 assert(Tok.
is(tok::annot_pragma_loop_hint));
1422 auto IsLoopHint = llvm::StringSwitch<bool>(PragmaNameInfo->
getName())
1423 .Cases(
"unroll",
"nounroll",
"unroll_and_jam",
1424 "nounroll_and_jam",
true)
1427 if (Toks.empty() && IsLoopHint) {
1428 ConsumeAnnotationToken();
1435 assert(!Toks.empty() &&
1436 "PragmaLoopHintInfo::Toks must contain at least one token.");
1439 bool OptionUnroll =
false;
1440 bool OptionUnrollAndJam =
false;
1441 bool OptionDistribute =
false;
1442 bool OptionPipelineDisabled =
false;
1443 bool StateOption =
false;
1445 OptionUnroll = OptionInfo->
isStr(
"unroll");
1446 OptionUnrollAndJam = OptionInfo->
isStr(
"unroll_and_jam");
1447 OptionDistribute = OptionInfo->
isStr(
"distribute");
1448 OptionPipelineDisabled = OptionInfo->
isStr(
"pipeline");
1449 StateOption = llvm::StringSwitch<bool>(OptionInfo->
getName())
1450 .Case(
"vectorize",
true)
1451 .Case(
"interleave",
true)
1452 .Case(
"vectorize_predicate",
true)
1454 OptionUnroll || OptionUnrollAndJam || OptionDistribute ||
1455 OptionPipelineDisabled;
1458 bool AssumeSafetyArg = !OptionUnroll && !OptionUnrollAndJam &&
1459 !OptionDistribute && !OptionPipelineDisabled;
1461 if (Toks[0].is(tok::eof)) {
1462 ConsumeAnnotationToken();
1463 Diag(Toks[0].getLocation(), diag::err_pragma_loop_missing_argument)
1465 << (OptionUnroll || OptionUnrollAndJam)
1472 ConsumeAnnotationToken();
1476 bool Valid = StateInfo &&
1477 llvm::StringSwitch<bool>(StateInfo->
getName())
1478 .Case(
"disable",
true)
1479 .Case(
"enable", !OptionPipelineDisabled)
1480 .Case(
"full", OptionUnroll || OptionUnrollAndJam)
1481 .Case(
"assume_safety", AssumeSafetyArg)
1484 if (OptionPipelineDisabled) {
1485 Diag(Toks[0].getLocation(), diag::err_pragma_pipeline_invalid_keyword);
1487 Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword)
1488 << (OptionUnroll || OptionUnrollAndJam)
1493 if (Toks.size() > 2)
1497 }
else if (OptionInfo && OptionInfo->
getName() ==
"vectorize_width") {
1498 PP.EnterTokenStream(Toks,
false,
1500 ConsumeAnnotationToken();
1504 StringRef IsScalableStr = StateInfo ? StateInfo->
getName() :
"";
1507 if (IsScalableStr ==
"scalable" || IsScalableStr ==
"fixed") {
1510 if (Toks.size() > 2) {
1513 while (Tok.
isNot(tok::eof))
1525 Diag(Toks[0].getLocation(),
1526 diag::note_pragma_loop_invalid_vectorize_option);
1528 bool Arg2Error =
false;
1529 if (Tok.
is(tok::comma)) {
1533 IsScalableStr = StateInfo->
getName();
1535 if (IsScalableStr !=
"scalable" && IsScalableStr !=
"fixed") {
1537 diag::err_pragma_loop_invalid_vectorize_option);
1548 if (Tok.
isNot(tok::eof)) {
1551 while (Tok.
isNot(tok::eof))
1567 PP.EnterTokenStream(Toks,
false,
1569 ConsumeAnnotationToken();
1574 if (Tok.
isNot(tok::eof)) {
1577 while (Tok.
isNot(tok::eof))
1593 Info->
Toks.back().getLocation());
1598struct PragmaAttributeInfo {
1599 enum ActionType { Push,
Pop, Attribute };
1605 PragmaAttributeInfo(
ParsedAttributes &Attributes) : Attributes(Attributes) {}
1608#include "clang/Parse/AttrSubMatchRulesParserStringSwitches.inc"
1613 if (Tok.
is(tok::identifier))
1622 using namespace attr;
1624#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract) \
1627#include "clang/Basic/AttrSubMatchRulesList.inc"
1629 llvm_unreachable(
"Invalid attribute subject match rule");
1637 PRef.
Diag(SubRuleLoc,
1638 diag::err_pragma_attribute_expected_subject_sub_identifier)
1640 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1651 PRef.
Diag(SubRuleLoc, diag::err_pragma_attribute_unknown_subject_sub_rule)
1652 << SubRuleName << PrimaryRuleName;
1653 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1659bool Parser::ParsePragmaAttributeSubjectMatchRuleSet(
1667 if (AnyParens.expectAndConsume())
1675 Diag(Tok, diag::err_pragma_attribute_expected_subject_identifier);
1678 std::pair<std::optional<attr::SubjectMatchRule>,
1679 std::optional<attr::SubjectMatchRule> (*)(StringRef,
bool)>
1680 Rule = isAttributeSubjectMatchRule(Name);
1682 Diag(Tok, diag::err_pragma_attribute_unknown_subject_rule) << Name;
1690 if (
Parens.expectAndConsume())
1692 }
else if (
Parens.consumeOpen()) {
1693 if (!SubjectMatchRules
1695 std::make_pair(PrimaryRule,
SourceRange(RuleLoc, RuleLoc)))
1697 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1700 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleLoc));
1701 LastMatchRuleEndLoc = RuleLoc;
1707 if (SubRuleName.empty()) {
1713 if (SubRuleName ==
"unless") {
1716 if (
Parens.expectAndConsume())
1719 if (SubRuleName.empty()) {
1724 auto SubRuleOrNone =
Rule.second(SubRuleName,
true);
1725 if (!SubRuleOrNone) {
1726 std::string SubRuleUnlessName =
"unless(" + SubRuleName.str() +
")";
1728 SubRuleUnlessName, SubRuleLoc);
1731 SubRule = *SubRuleOrNone;
1733 if (
Parens.consumeClose())
1736 auto SubRuleOrNone =
Rule.second(SubRuleName,
false);
1737 if (!SubRuleOrNone) {
1742 SubRule = *SubRuleOrNone;
1746 LastMatchRuleEndLoc = RuleEndLoc;
1747 if (
Parens.consumeClose())
1749 if (!SubjectMatchRules
1750 .insert(std::make_pair(SubRule,
SourceRange(RuleLoc, RuleEndLoc)))
1752 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1755 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleEndLoc));
1761 if (AnyParens.consumeClose())
1770enum class MissingAttributeSubjectRulesRecoveryPoint {
1778MissingAttributeSubjectRulesRecoveryPoint
1779getAttributeSubjectRulesRecoveryPointForToken(
const Token &Tok) {
1781 if (II->
isStr(
"apply_to"))
1782 return MissingAttributeSubjectRulesRecoveryPoint::ApplyTo;
1783 if (II->
isStr(
"any"))
1784 return MissingAttributeSubjectRulesRecoveryPoint::Any;
1786 if (Tok.
is(tok::equal))
1787 return MissingAttributeSubjectRulesRecoveryPoint::Equals;
1788 return MissingAttributeSubjectRulesRecoveryPoint::None;
1796 MissingAttributeSubjectRulesRecoveryPoint Point,
Parser &PRef) {
1802 MissingAttributeSubjectRulesRecoveryPoint EndPoint =
1803 getAttributeSubjectRulesRecoveryPointForToken(PRef.
getCurToken());
1804 if (Point == MissingAttributeSubjectRulesRecoveryPoint::Comma)
1806 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::ApplyTo &&
1807 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::ApplyTo)
1808 FixIt +=
"apply_to";
1809 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::Equals &&
1810 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::Equals)
1813 if (EndPoint == MissingAttributeSubjectRulesRecoveryPoint::None) {
1820 Attribute.getMatchRules(PRef.
getLangOpts(), MatchRules);
1822 for (
const auto &Rule : MatchRules) {
1827 IsSupported[
Rule.first] =
true;
1829 IsMatchRuleAvailable &= IsSupported;
1831 if (IsMatchRuleAvailable.count() == 0) {
1837 bool NeedsComma =
false;
1839 if (!IsMatchRuleAvailable[I])
1853 if (FixItRange.getBegin() == FixItRange.getEnd())
1863void Parser::HandlePragmaAttribute() {
1864 assert(Tok.
is(tok::annot_pragma_attribute) &&
1865 "Expected #pragma attribute annotation token");
1868 if (Info->Action == PragmaAttributeInfo::Pop) {
1869 ConsumeAnnotationToken();
1874 assert((Info->Action == PragmaAttributeInfo::Push ||
1875 Info->Action == PragmaAttributeInfo::Attribute) &&
1876 "Unexpected #pragma attribute command");
1878 if (Info->Action == PragmaAttributeInfo::Push && Info->Tokens.empty()) {
1879 ConsumeAnnotationToken();
1884 PP.EnterTokenStream(Info->Tokens,
false,
1886 ConsumeAnnotationToken();
1891 auto SkipToEnd = [
this]() {
1896 if ((Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) ||
1899 ParseCXX11AttributeSpecifier(Attrs);
1900 }
else if (Tok.
is(tok::kw___attribute)) {
1902 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
1905 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"("))
1910 if (Tok.
is(tok::code_completion)) {
1920 if (Tok.
isNot(tok::identifier)) {
1921 Diag(Tok, diag::err_pragma_attribute_expected_attribute_name);
1928 if (Tok.
isNot(tok::l_paren))
1930 ParsedAttr::Form::GNU());
1932 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs,
nullptr,
1935 ParsedAttr::Form::GNU(),
1939 if (ExpectAndConsume(tok::r_paren))
1941 if (ExpectAndConsume(tok::r_paren))
1943 }
else if (Tok.
is(tok::kw___declspec)) {
1944 ParseMicrosoftDeclSpecs(Attrs);
1946 Diag(Tok, diag::err_pragma_attribute_expected_attribute_syntax);
1955 if (Tok.
is(tok::l_paren)) {
1958 if (Tok.
isNot(tok::r_paren))
1961 Diag(Tok, diag::note_pragma_attribute_use_attribute_kw)
1970 if (Attrs.
empty() || Attrs.
begin()->isInvalid()) {
1976 if (!Attribute.isSupportedByPragmaAttribute()) {
1977 Diag(PragmaLoc, diag::err_pragma_attribute_unsupported_attribute)
1986 createExpectedAttributeSubjectRulesTokenDiagnostic(
1987 diag::err_expected, Attrs,
1988 MissingAttributeSubjectRulesRecoveryPoint::Comma, *
this)
1994 if (Tok.
isNot(tok::identifier)) {
1995 createExpectedAttributeSubjectRulesTokenDiagnostic(
1996 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
1997 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2002 if (!II->
isStr(
"apply_to")) {
2003 createExpectedAttributeSubjectRulesTokenDiagnostic(
2004 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2005 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2012 createExpectedAttributeSubjectRulesTokenDiagnostic(
2013 diag::err_expected, Attrs,
2014 MissingAttributeSubjectRulesRecoveryPoint::Equals, *
this)
2022 if (ParsePragmaAttributeSubjectMatchRuleSet(SubjectMatchRules, AnyLoc,
2023 LastMatchRuleEndLoc)) {
2030 if (Tok.
isNot(tok::eof)) {
2031 Diag(Tok, diag::err_pragma_attribute_extra_tokens_after_attribute);
2040 if (Info->Action == PragmaAttributeInfo::Push)
2052void PragmaGCCVisibilityHandler::HandlePragma(
Preprocessor &PP,
2063 if (PushPop && PushPop->
isStr(
"pop")) {
2065 }
else if (PushPop && PushPop->
isStr(
"push")) {
2067 if (Tok.
isNot(tok::l_paren)) {
2080 if (Tok.
isNot(tok::r_paren)) {
2092 if (Tok.
isNot(tok::eod)) {
2098 auto Toks = std::make_unique<Token[]>(1);
2099 Toks[0].startToken();
2100 Toks[0].setKind(tok::annot_pragma_vis);
2101 Toks[0].setLocation(VisLoc);
2102 Toks[0].setAnnotationEndLoc(EndLoc);
2103 Toks[0].setAnnotationValue(
2104 const_cast<void *
>(
static_cast<const void *
>(VisType)));
2105 PP.EnterTokenStream(std::move(Toks), 1,
true,
2121 if (Tok.
isNot(tok::l_paren)) {
2122 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"pack";
2127 StringRef SlotLabel;
2131 if (Tok.
is(tok::numeric_constant)) {
2142 }
else if (Tok.
is(tok::identifier)) {
2144 auto MapPack = [&](
const char *
Literal) {
2147 Alignment.
setKind(tok::numeric_constant);
2153 if (II->
isStr(
"show")) {
2173 if (II->
isStr(
"push")) {
2175 }
else if (II->
isStr(
"pop")) {
2178 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_invalid_action) <<
"pack";
2183 if (Tok.
is(tok::comma)) {
2186 if (Tok.
is(tok::numeric_constant)) {
2191 }
else if (Tok.
is(tok::identifier)) {
2195 if (Tok.
is(tok::comma)) {
2198 if (Tok.
isNot(tok::numeric_constant)) {
2223 if (Tok.
isNot(tok::r_paren)) {
2224 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"pack";
2230 if (Tok.
isNot(tok::eod)) {
2231 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"pack";
2243 Toks[0].startToken();
2244 Toks[0].setKind(tok::annot_pragma_pack);
2245 Toks[0].setLocation(PackLoc);
2246 Toks[0].setAnnotationEndLoc(RParenLoc);
2247 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2248 PP.EnterTokenStream(Toks,
true,
2254void PragmaMSStructHandler::HandlePragma(
Preprocessor &PP,
2256 Token &MSStructTok) {
2261 if (Tok.
isNot(tok::identifier)) {
2267 if (II->
isStr(
"on")) {
2271 else if (II->
isStr(
"off") || II->
isStr(
"reset"))
2278 if (Tok.
isNot(tok::eod)) {
2286 Toks[0].startToken();
2287 Toks[0].setKind(tok::annot_pragma_msstruct);
2289 Toks[0].setAnnotationEndLoc(EndLoc);
2290 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2292 PP.EnterTokenStream(Toks,
true,
2297void PragmaClangSectionHandler::HandlePragma(
Preprocessor &PP,
2299 Token &FirstToken) {
2305 while (Tok.
isNot(tok::eod)) {
2306 if (Tok.
isNot(tok::identifier)) {
2307 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2312 if (SecType->
isStr(
"bss"))
2314 else if (SecType->
isStr(
"data"))
2316 else if (SecType->
isStr(
"rodata"))
2318 else if (SecType->
isStr(
"relro"))
2320 else if (SecType->
isStr(
"text"))
2323 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2329 if (Tok.
isNot(tok::equal)) {
2330 PP.
Diag(Tok.
getLocation(), diag::err_pragma_clang_section_expected_equal)
2335 std::string SecName;
2339 Actions.ActOnPragmaClangSection(PragmaLocation,
2356 if (Tok.
isNot(tok::identifier) ||
2365 if (Tok.
isNot(tok::l_paren)) {
2366 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"align";
2369 }
else if (Tok.
isNot(tok::equal)) {
2376 if (Tok.
isNot(tok::identifier)) {
2378 << (IsOptions ?
"options" :
"align");
2384 if (II->
isStr(
"native"))
2386 else if (II->
isStr(
"natural"))
2388 else if (II->
isStr(
"packed"))
2390 else if (II->
isStr(
"power"))
2392 else if (II->
isStr(
"mac68k"))
2394 else if (II->
isStr(
"reset"))
2404 if (Tok.
isNot(tok::r_paren)) {
2405 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"align";
2412 if (Tok.
isNot(tok::eod)) {
2414 << (IsOptions ?
"options" :
"align");
2420 Toks[0].startToken();
2421 Toks[0].setKind(tok::annot_pragma_align);
2423 Toks[0].setAnnotationEndLoc(EndLoc);
2424 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2426 PP.EnterTokenStream(Toks,
true,
2436void PragmaOptionsHandler::HandlePragma(
Preprocessor &PP,
2438 Token &OptionsTok) {
2443void PragmaUnusedHandler::HandlePragma(
Preprocessor &PP,
2452 if (Tok.
isNot(tok::l_paren)) {
2453 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"unused";
2466 if (Tok.
is(tok::identifier)) {
2467 Identifiers.push_back(Tok);
2478 if (Tok.
is(tok::comma)) {
2483 if (Tok.
is(tok::r_paren)) {
2489 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_punc) <<
"unused";
2494 if (Tok.
isNot(tok::eod)) {
2501 assert(RParenLoc.
isValid() &&
"Valid '#pragma unused' must have ')'");
2502 assert(!Identifiers.empty() &&
"Valid '#pragma unused' must have arguments");
2511 2 * Identifiers.size());
2512 for (
unsigned i=0; i != Identifiers.size(); i++) {
2513 Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
2515 pragmaUnusedTok.
setKind(tok::annot_pragma_unused);
2517 idTok = Identifiers[i];
2519 PP.EnterTokenStream(Toks,
true,
2532 if (Tok.
isNot(tok::identifier)) {
2533 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_identifier) <<
"weak";
2537 Token WeakName = Tok;
2538 bool HasAlias =
false;
2542 if (Tok.
is(tok::equal)) {
2545 if (Tok.
isNot(tok::identifier)) {
2554 if (Tok.
isNot(tok::eod)) {
2555 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"weak";
2562 Token &pragmaUnusedTok = Toks[0];
2564 pragmaUnusedTok.
setKind(tok::annot_pragma_weakalias);
2568 Toks[2] = AliasName;
2569 PP.EnterTokenStream(Toks,
true,
2574 Token &pragmaUnusedTok = Toks[0];
2576 pragmaUnusedTok.
setKind(tok::annot_pragma_weak);
2580 PP.EnterTokenStream(Toks,
true,
2586void PragmaRedefineExtnameHandler::HandlePragma(
Preprocessor &PP,
2588 Token &RedefToken) {
2593 if (Tok.
isNot(tok::identifier)) {
2599 Token RedefName = Tok;
2602 if (Tok.
isNot(tok::identifier)) {
2604 <<
"redefine_extname";
2608 Token AliasName = Tok;
2611 if (Tok.
isNot(tok::eod)) {
2619 Token &pragmaRedefTok = Toks[0];
2621 pragmaRedefTok.
setKind(tok::annot_pragma_redefine_extname);
2624 Toks[1] = RedefName;
2625 Toks[2] = AliasName;
2626 PP.EnterTokenStream(Toks,
true,
2630void PragmaFPContractHandler::HandlePragma(
Preprocessor &PP,
2639 Toks[0].startToken();
2640 Toks[0].setKind(tok::annot_pragma_fp_contract);
2643 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2645 PP.EnterTokenStream(Toks,
true,
2649void PragmaOpenCLExtensionHandler::HandlePragma(
Preprocessor &PP,
2653 if (Tok.
isNot(tok::identifier)) {
2662 if (Tok.
isNot(tok::colon)) {
2668 if (Tok.
isNot(tok::identifier)) {
2669 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_predicate) << 0;
2674 OpenCLExtState State;
2675 if (Pred->
isStr(
"enable")) {
2677 }
else if (Pred->
isStr(
"disable")) {
2679 }
else if (Pred->
isStr(
"begin"))
2681 else if (Pred->
isStr(
"end"))
2685 << Ext->
isStr(
"all");
2691 if (Tok.
isNot(tok::eod)) {
2699 Info->second = State;
2702 Toks[0].startToken();
2703 Toks[0].setKind(tok::annot_pragma_opencl_extension);
2704 Toks[0].setLocation(NameLoc);
2705 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2706 Toks[0].setAnnotationEndLoc(StateLoc);
2707 PP.EnterTokenStream(Toks,
true,
2717template <diag::kind IgnoredDiag>
2718void PragmaNoSupportHandler<IgnoredDiag>::HandlePragma(
2721 PP.
Diag(FirstTok, IgnoredDiag);
2732void PragmaSupportHandler<StartTok, EndTok, UnexpectedDiag>::HandlePragma(
2740 while (Tok.
isNot(tok::eod) && Tok.
isNot(tok::eof)) {
2741 Pragma.push_back(Tok);
2743 if (Tok.
is(StartTok)) {
2744 PP.
Diag(Tok, UnexpectedDiag) << 0;
2745 unsigned InnerPragmaCnt = 1;
2746 while (InnerPragmaCnt != 0) {
2748 if (Tok.
is(StartTok))
2750 else if (Tok.
is(EndTok))
2760 Pragma.push_back(Tok);
2762 auto Toks = std::make_unique<Token[]>(Pragma.size());
2763 std::copy(Pragma.begin(), Pragma.end(), Toks.get());
2764 PP.EnterTokenStream(std::move(Toks), Pragma.size(),
2776void PragmaMSPointersToMembers::HandlePragma(
Preprocessor &PP,
2781 if (Tok.
isNot(tok::l_paren)) {
2782 PP.
Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen)
2783 <<
"pointers_to_members";
2790 <<
"pointers_to_members";
2796 if (Arg->
isStr(
"best_case")) {
2799 if (Arg->
isStr(
"full_generality")) {
2800 if (Tok.
is(tok::comma)) {
2806 diag::err_pragma_pointers_to_members_unknown_kind)
2811 }
else if (Tok.
is(tok::r_paren)) {
2818 <<
"full_generality";
2824 if (Arg->
isStr(
"single_inheritance")) {
2825 RepresentationMethod =
2827 }
else if (Arg->
isStr(
"multiple_inheritance")) {
2828 RepresentationMethod =
2830 }
else if (Arg->
isStr(
"virtual_inheritance")) {
2831 RepresentationMethod =
2835 diag::err_pragma_pointers_to_members_unknown_kind)
2842 if (Tok.
isNot(tok::r_paren)) {
2844 << (Arg ? Arg->
getName() :
"full_generality");
2850 if (Tok.
isNot(tok::eod)) {
2852 <<
"pointers_to_members";
2858 AnnotTok.
setKind(tok::annot_pragma_ms_pointers_to_members);
2862 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RepresentationMethod)));
2878 if (Tok.
isNot(tok::l_paren)) {
2879 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) <<
"vtordisp";
2887 if (II->
isStr(
"push")) {
2890 if (Tok.
isNot(tok::comma)) {
2891 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_punc) <<
"vtordisp";
2897 }
else if (II->
isStr(
"pop")) {
2904 if (Tok.
is(tok::r_paren)) {
2914 if (II && II->
isStr(
"off")) {
2917 }
else if (II && II->
isStr(
"on")) {
2920 }
else if (Tok.
is(tok::numeric_constant) &&
2924 << 0 << 2 <<
"vtordisp";
2935 if (Tok.
isNot(tok::r_paren)) {
2936 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) <<
"vtordisp";
2941 if (Tok.
isNot(tok::eod)) {
2950 AnnotTok.
setKind(tok::annot_pragma_ms_vtordisp);
2962 Token EoF, AnnotTok;
2966 AnnotTok.
setKind(tok::annot_pragma_ms_pragma);
2971 for (; Tok.
isNot(tok::eod); PP.
Lex(Tok)) {
2972 TokenVector.push_back(Tok);
2976 TokenVector.push_back(EoF);
2979 markAsReinjectedForRelexing(TokenVector);
2980 auto TokenArray = std::make_unique<Token[]>(TokenVector.size());
2981 std::copy(TokenVector.begin(), TokenVector.end(), TokenArray.get());
2983 std::pair<std::unique_ptr<
Token[]>,
size_t>(std::move(TokenArray),
2984 TokenVector.size());
3000void PragmaFloatControlHandler::HandlePragma(
Preprocessor &PP,
3005 Token PragmaName = Tok;
3012 if (Tok.
isNot(tok::l_paren)) {
3013 PP.
Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
3019 if (Tok.
isNot(tok::identifier)) {
3027 llvm::StringSwitch<PragmaFloatControlKind>(II->
getName())
3038 if (Tok.
isNot(tok::r_paren)) {
3045 if (Tok.
is(tok::r_paren))
3048 else if (Tok.
isNot(tok::comma)) {
3058 if (PushOnOff ==
"on")
3061 else if (PushOnOff ==
"off") {
3066 }
else if (PushOnOff ==
"push") {
3073 if (Tok.
is(tok::comma)) {
3080 if (ExpectedPush ==
"push") {
3088 if (Tok.
isNot(tok::r_paren)) {
3096 if (Tok.
isNot(tok::eod)) {
3105 auto TokenArray = std::make_unique<Token[]>(1);
3106 TokenArray[0].startToken();
3107 TokenArray[0].setKind(tok::annot_pragma_float_control);
3108 TokenArray[0].setLocation(FloatControlLoc);
3109 TokenArray[0].setAnnotationEndLoc(EndLoc);
3112 TokenArray[0].setAnnotationValue(
reinterpret_cast<void *
>(
3113 static_cast<uintptr_t>((Action << 16) | (Kind & 0xFFFF))));
3114 PP.EnterTokenStream(std::move(TokenArray), 1,
3128void PragmaDetectMismatchHandler::HandlePragma(
Preprocessor &PP,
3133 if (Tok.
isNot(tok::l_paren)) {
3134 PP.
Diag(DetectMismatchLoc, diag::err_expected) << tok::l_paren;
3139 std::string NameString;
3141 "pragma detect_mismatch",
3146 std::string ValueString;
3147 if (Tok.
isNot(tok::comma)) {
3148 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3156 if (Tok.
isNot(tok::r_paren)) {
3162 if (Tok.
isNot(tok::eod)) {
3163 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3172 Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString);
3184void PragmaCommentHandler::HandlePragma(
Preprocessor &PP,
3189 if (Tok.
isNot(tok::l_paren)) {
3190 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3196 if (Tok.
isNot(tok::identifier)) {
3197 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3204 llvm::StringSwitch<PragmaMSCommentKind>(II->
getName())
3224 std::string ArgumentString;
3237 if (Tok.
isNot(tok::r_paren)) {
3243 if (Tok.
isNot(tok::eod)) {
3252 Actions.ActOnPragmaMSComment(CommentLoc, Kind, ArgumentString);
3257void PragmaOptimizeHandler::HandlePragma(
Preprocessor &PP,
3259 Token &FirstToken) {
3262 if (Tok.
is(tok::eod)) {
3264 <<
"clang optimize" <<
true <<
"'on' or 'off'";
3267 if (Tok.
isNot(tok::identifier)) {
3268 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3275 if (II->
isStr(
"on")) {
3277 }
else if (!II->
isStr(
"off")) {
3278 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3284 if (Tok.
isNot(tok::eod)) {
3290 Actions.ActOnPragmaOptimize(IsOn, FirstToken.
getLocation());
3295struct TokFPAnnotValue {
3296 enum FlagValues { On, Off, Fast };
3298 std::optional<LangOptions::FPModeKind> ContractValue;
3299 std::optional<LangOptions::FPModeKind> ReassociateValue;
3300 std::optional<LangOptions::FPModeKind> ReciprocalValue;
3301 std::optional<LangOptions::FPExceptionModeKind> ExceptionsValue;
3302 std::optional<LangOptions::FPEvalMethodKind> EvalMethodValue;
3309 Token PragmaName = Tok;
3313 if (Tok.
isNot(tok::identifier)) {
3320 while (Tok.
is(tok::identifier)) {
3324 llvm::StringSwitch<std::optional<PragmaFPKind>>(OptionInfo->
getName())
3330 .Default(std::nullopt);
3333 <<
false << OptionInfo;
3339 if (Tok.
isNot(tok::l_paren)) {
3344 bool isEvalMethodDouble =
3348 if (Tok.
isNot(tok::identifier) && !isEvalMethodDouble) {
3351 <<
static_cast<int>(*FlagKind);
3357 AnnotValue->ContractValue =
3358 llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3363 .Default(std::nullopt);
3364 if (!AnnotValue->ContractValue) {
3371 : AnnotValue->ReciprocalValue;
3372 Value = llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3376 .Default(std::nullopt);
3383 AnnotValue->ExceptionsValue =
3384 llvm::StringSwitch<std::optional<LangOptions::FPExceptionModeKind>>(
3389 .Default(std::nullopt);
3390 if (!AnnotValue->ExceptionsValue) {
3396 AnnotValue->EvalMethodValue =
3397 llvm::StringSwitch<std::optional<LangOptions::FPEvalMethodKind>>(
3402 .Default(std::nullopt);
3403 if (!AnnotValue->EvalMethodValue) {
3412 if (Tok.
isNot(tok::r_paren)) {
3419 if (Tok.
isNot(tok::eod)) {
3427 FPTok.
setKind(tok::annot_pragma_fp);
3431 TokenList.push_back(FPTok);
3433 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3434 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3436 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3440void PragmaSTDC_FENV_ROUNDHandler::HandlePragma(
Preprocessor &PP,
3443 Token PragmaName = Tok;
3451 if (Tok.
isNot(tok::identifier)) {
3459 llvm::StringSwitch<llvm::RoundingMode>(II->
getName())
3460 .Case(
"FE_TOWARDZERO", llvm::RoundingMode::TowardZero)
3461 .Case(
"FE_TONEAREST", llvm::RoundingMode::NearestTiesToEven)
3462 .Case(
"FE_UPWARD", llvm::RoundingMode::TowardPositive)
3463 .Case(
"FE_DOWNWARD", llvm::RoundingMode::TowardNegative)
3464 .Case(
"FE_TONEARESTFROMZERO", llvm::RoundingMode::NearestTiesToAway)
3465 .Case(
"FE_DYNAMIC", llvm::RoundingMode::Dynamic)
3466 .Default(llvm::RoundingMode::Invalid);
3467 if (RM == llvm::RoundingMode::Invalid) {
3473 if (Tok.
isNot(tok::eod)) {
3475 <<
"STDC FENV_ROUND";
3484 Toks[0].startToken();
3485 Toks[0].setKind(tok::annot_pragma_fenv_round);
3488 Toks[0].setAnnotationValue(
3489 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RM)));
3490 PP.EnterTokenStream(Toks,
true,
3494void Parser::HandlePragmaFP() {
3495 assert(Tok.
is(tok::annot_pragma_fp));
3499 if (AnnotValue->ReassociateValue)
3504 if (AnnotValue->ReciprocalValue)
3509 if (AnnotValue->ContractValue)
3511 *AnnotValue->ContractValue);
3512 if (AnnotValue->ExceptionsValue)
3514 *AnnotValue->ExceptionsValue);
3515 if (AnnotValue->EvalMethodValue)
3517 *AnnotValue->EvalMethodValue);
3518 ConsumeAnnotationToken();
3523 Token Option,
bool ValueInParens,
3526 int OpenParens = ValueInParens ? 1 : 0;
3528 while (Tok.
isNot(tok::eod)) {
3529 if (Tok.
is(tok::l_paren))
3531 else if (Tok.
is(tok::r_paren)) {
3533 if (OpenParens == 0 && ValueInParens)
3541 if (ValueInParens) {
3543 if (Tok.
isNot(tok::r_paren)) {
3612void PragmaLoopHintHandler::HandlePragma(
Preprocessor &PP,
3616 Token PragmaName = Tok;
3621 if (Tok.
isNot(tok::identifier)) {
3627 while (Tok.
is(tok::identifier)) {
3631 bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->
getName())
3632 .Case(
"vectorize",
true)
3633 .Case(
"interleave",
true)
3634 .Case(
"unroll",
true)
3635 .Case(
"distribute",
true)
3636 .Case(
"vectorize_predicate",
true)
3637 .Case(
"vectorize_width",
true)
3638 .Case(
"interleave_count",
true)
3639 .Case(
"unroll_count",
true)
3640 .Case(
"pipeline",
true)
3641 .Case(
"pipeline_initiation_interval",
true)
3645 <<
false << OptionInfo;
3651 if (Tok.
isNot(tok::l_paren)) {
3665 LoopHintTok.
setKind(tok::annot_pragma_loop_hint);
3669 TokenList.push_back(LoopHintTok);
3672 if (Tok.
isNot(tok::eod)) {
3678 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3679 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3681 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3706void PragmaUnrollHintHandler::HandlePragma(
Preprocessor &PP,
3711 Token PragmaName = Tok;
3714 if (Tok.
is(tok::eod)) {
3716 Info->PragmaName = PragmaName;
3717 Info->Option.startToken();
3727 bool ValueInParens = Tok.
is(tok::l_paren);
3739 PP.
Diag(Info->Toks[0].getLocation(),
3740 diag::warn_pragma_unroll_cuda_value_in_parens);
3742 if (Tok.
isNot(tok::eod)) {
3750 auto TokenArray = std::make_unique<Token[]>(1);
3751 TokenArray[0].startToken();
3752 TokenArray[0].setKind(tok::annot_pragma_loop_hint);
3753 TokenArray[0].setLocation(Introducer.
Loc);
3754 TokenArray[0].setAnnotationEndLoc(PragmaName.
getLocation());
3755 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
3756 PP.EnterTokenStream(std::move(TokenArray), 1,
3760bool Parser::HandlePragmaMSFunction(StringRef PragmaName,
3762 Token FirstTok = Tok;
3764 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3771 while (Tok.
is(tok::identifier)) {
3775 << II << SuggestIntrinH;
3777 NoBuiltins.emplace_back(II->
getName());
3780 if (Tok.
isNot(tok::comma))
3785 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3787 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3795bool Parser::HandlePragmaMSOptimize(StringRef PragmaName,
3797 Token FirstTok = Tok;
3798 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3802 if (Tok.
isNot(tok::string_literal)) {
3803 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_string) << PragmaName;
3811 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
3816 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
3820 if (Tok.
is(tok::eof) || Tok.
is(tok::r_paren)) {
3821 PP.
Diag(PragmaLocation, diag::warn_pragma_missing_argument)
3822 << PragmaName <<
true <<
"'on' or 'off'";
3826 if (!II || (!II->
isStr(
"on") && !II->
isStr(
"off"))) {
3827 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3832 bool IsOn = II->
isStr(
"on");
3835 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3840 if (!OptimizationList->
getString().empty()) {
3841 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3842 << OptimizationList->
getString() << PragmaName <<
true
3847 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3868bool Parser::HandlePragmaMSIntrinsic(StringRef PragmaName,
3870 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3876 while (Tok.
is(tok::identifier)) {
3880 << II << SuggestIntrinH;
3884 RedeclarationKind::NotForRedeclaration);
3891 if (Tok.
isNot(tok::comma))
3895 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3899 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3905void PragmaForceCUDAHostDeviceHandler::HandlePragma(
3907 Token FirstTok = Tok;
3911 if (!Info || (!Info->
isStr(
"begin") && !Info->
isStr(
"end"))) {
3913 diag::warn_pragma_force_cuda_host_device_bad_arg);
3917 if (Info->
isStr(
"begin"))
3918 Actions.CUDA().PushForceHostDevice();
3919 else if (!Actions.CUDA().PopForceHostDevice())
3921 diag::err_pragma_cannot_end_force_cuda_host_device);
3924 if (!Tok.
is(tok::eod))
3926 diag::warn_pragma_force_cuda_host_device_bad_arg);
3956void PragmaAttributeHandler::HandlePragma(
Preprocessor &PP,
3958 Token &FirstToken) {
3962 PragmaAttributeInfo(AttributesForPragmaAttribute);
3965 if (Tok.
is(tok::identifier)) {
3967 if (!II->
isStr(
"push") && !II->
isStr(
"pop")) {
3968 Info->Namespace = II;
3971 if (!Tok.
is(tok::period)) {
3972 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_period)
3980 if (!Tok.
isOneOf(tok::identifier, tok::l_paren)) {
3982 diag::err_pragma_attribute_expected_push_pop_paren);
3987 if (Tok.
is(tok::l_paren)) {
3988 if (Info->Namespace) {
3990 diag::err_pragma_attribute_namespace_on_attribute);
3992 diag::note_pragma_attribute_namespace_on_attribute);
3995 Info->Action = PragmaAttributeInfo::Attribute;
3998 if (II->
isStr(
"push"))
3999 Info->Action = PragmaAttributeInfo::Push;
4001 Info->Action = PragmaAttributeInfo::Pop;
4003 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_invalid_argument)
4012 if ((Info->Action == PragmaAttributeInfo::Push && Tok.
isNot(tok::eod)) ||
4013 Info->Action == PragmaAttributeInfo::Attribute) {
4014 if (Tok.
isNot(tok::l_paren)) {
4023 while (Tok.
isNot(tok::eod)) {
4024 if (Tok.
is(tok::l_paren))
4026 else if (Tok.
is(tok::r_paren)) {
4028 if (OpenParens == 0)
4032 AttributeTokens.push_back(Tok);
4036 if (AttributeTokens.empty()) {
4037 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_attribute);
4040 if (Tok.
isNot(tok::r_paren)) {
4052 AttributeTokens.push_back(EOFTok);
4054 markAsReinjectedForRelexing(AttributeTokens);
4059 if (Tok.
isNot(tok::eod))
4061 <<
"clang attribute";
4064 auto TokenArray = std::make_unique<Token[]>(1);
4065 TokenArray[0].startToken();
4066 TokenArray[0].setKind(tok::annot_pragma_attribute);
4067 TokenArray[0].setLocation(FirstToken.
getLocation());
4068 TokenArray[0].setAnnotationEndLoc(FirstToken.
getLocation());
4069 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
4070 PP.EnterTokenStream(std::move(TokenArray), 1,
4075void PragmaMaxTokensHereHandler::HandlePragma(
Preprocessor &PP,
4079 if (Tok.
is(tok::eod)) {
4081 <<
"clang max_tokens_here" <<
true <<
"integer";
4087 if (Tok.
isNot(tok::numeric_constant) ||
4090 <<
"clang max_tokens_here";
4094 if (Tok.
isNot(tok::eod)) {
4096 <<
"clang max_tokens_here";
4101 PP.
Diag(
Loc, diag::warn_max_tokens)
4107void PragmaMaxTokensTotalHandler::HandlePragma(
Preprocessor &PP,
4111 if (Tok.
is(tok::eod)) {
4113 <<
"clang max_tokens_total" <<
true <<
"integer";
4119 if (Tok.
isNot(tok::numeric_constant) ||
4122 <<
"clang max_tokens_total";
4126 if (Tok.
isNot(tok::eod)) {
4128 <<
"clang max_tokens_total";
4140 Token &FirstToken) {
4145 if (!II || !II->
isStr(
"intrinsic")) {
4147 << PP.
getSpelling(Tok) <<
"riscv" <<
true <<
"'intrinsic'";
4153 if (!II || !(II->
isStr(
"vector") || II->
isStr(
"sifive_vector") ||
4154 II->
isStr(
"andes_vector"))) {
4157 <<
"'vector', 'sifive_vector' or 'andes_vector'";
4162 if (Tok.
isNot(tok::eod)) {
4164 <<
"clang riscv intrinsic";
4168 if (II->
isStr(
"vector"))
4169 Actions.RISCV().DeclareRVVBuiltins =
true;
4170 else if (II->
isStr(
"sifive_vector"))
4171 Actions.RISCV().DeclareSiFiveVectorBuiltins =
true;
4172 else if (II->
isStr(
"andes_vector"))
4173 Actions.RISCV().DeclareAndesVectorBuiltins =
true;
Defines the clang::ASTContext interface.
static void ParseAlignPragma(Preprocessor &PP, Token &FirstTok, bool IsOptions)
static void diagnoseUnknownAttributeSubjectSubRule(Parser &PRef, attr::SubjectMatchRule PrimaryRule, StringRef PrimaryRuleName, StringRef SubRuleName, SourceLocation SubRuleLoc)
static bool ParseLoopHintValue(Preprocessor &PP, Token &Tok, Token PragmaName, Token Option, bool ValueInParens, PragmaLoopHintInfo &Info)
Parses loop or unroll pragma hint value and fills in Info.
static void diagnoseExpectedAttributeSubjectSubRule(Parser &PRef, attr::SubjectMatchRule PrimaryRule, StringRef PrimaryRuleName, SourceLocation SubRuleLoc)
static bool isAbstractAttrMatcherRule(attr::SubjectMatchRule Rule)
static StringRef getIdentifier(const Token &Tok)
static std::string PragmaLoopHintString(Token PragmaName, Token Option)
Defines the clang::Preprocessor interface.
ArrayRef< SVal > ValueList
This file declares semantic analysis for CUDA constructs.
This file declares facilities that support code completion.
This file declares semantic analysis functions specific to RISC-V.
Kind getParsedKind() const
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
static CharSourceRange getCharRange(SourceRange R)
A little helper class used to produce diagnostics.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
void setSeverity(diag::kind Diag, diag::Severity Map, SourceLocation Loc)
This allows the client to specify that certain warnings are ignored.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
EmptyPragmaHandler - A pragma handler which takes no action, which can be used to ignore particular p...
RAII object that enters a new expression evaluation context.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
ExprDependence getDependence() const
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
A simple pair of identifier info and location.
@ FEM_Extended
Use extended type for fp arithmetic.
@ FEM_Double
Use the type double for fp arithmetic.
@ FEM_Source
Use the declared type for fp arithmetic.
ComplexRangeKind
Controls the various implementations for complex multiplication and.
@ CX_Full
Implementation of complex division and multiplication using a call to runtime library functions(gener...
@ CX_Basic
Implementation of complex division and multiplication using algebraic formulas at source precision.
PragmaMSPointersToMembersKind
@ PPTMK_FullGeneralityMultipleInheritance
@ PPTMK_FullGeneralityVirtualInheritance
@ PPTMK_FullGeneralitySingleInheritance
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
@ FPE_MayTrap
Transformations do not cause new exceptions but may hide some.
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Represents the results of name lookup.
virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, StringRef Str)
Callback invoked when a #pragma comment directive is read.
virtual void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State)
Called when an OpenCL extension is either disabled or enabled with a pragma.
virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
Callback invoked when a #pragma detect_mismatch directive is read.
ParsedAttr - Represents a syntactic attribute.
ParsedAttributes - A collection of parsed attributes.
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
Parser - This implements a parser for the C family of languages.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation getEndOfPreviousToken() const
ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral=false)
ParseStringLiteralExpression - This handles the various token types that form string literals,...
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
ExprResult ParseConstantExpression()
bool TryConsumeToken(tok::TokenKind Expected)
Scope * getCurScope() const
const TargetInfo & getTargetInfo() const
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
const Token & getCurToken() const
const LangOptions & getLangOpts() const
ExprResult ParseExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Simple precedence-based parser for binary/ternary operators.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
PragmaHandler - Instances of this interface defined to handle the various pragmas that the language f...
virtual void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &FirstToken)=0
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
PPCallbacks * getPPCallbacks() const
void overrideMaxTokens(unsigned Value, SourceLocation Loc)
void Lex(Token &Result)
Lex the next token for this preprocessor.
SourceRange DiscardUntilEndOfDirective()
Read and discard all tokens remaining on the current line until the tok::eod token is found.
bool LexOnOffSwitch(tok::OnOffSwitch &Result)
Lex an on-off-switch (C99 6.10.6p2) and verify that it is followed by EOD.
bool isMacroDefined(StringRef Id)
unsigned getTokenCount() const
Get the number of tokens processed so far.
const TargetInfo & getTargetInfo() const
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value)
Parses a simple integer literal to get its numeric value.
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Add the specified pragma handler to this preprocessor.
llvm::BumpPtrAllocator & getPreprocessorAllocator()
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
const LangOptions & getLangOpts() const
DiagnosticsEngine & getDiagnostics() const
void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Remove the specific pragma handler from this preprocessor.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
bool LexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
Lex a string literal, which may be the concatenation of multiple string literals and may even come fr...
@ CompoundStmtScope
This is a compound statement scope.
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ DeclScope
This is a scope that can contain a declaration.
void CodeCompleteAttribute(AttributeCommonInfo::Syntax Syntax, AttributeCompletion Completion=AttributeCompletion::Attribute, const IdentifierInfo *Scope=nullptr)
Sema - This implements semantic analysis and AST building for C.
void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn)
#pragma optimize("[optimization-list]", on | off).
Scope * getCurScope() const
Retrieve the parser's current scope.
void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
void ActOnPragmaAttributePop(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Called on well-formed '#pragma clang attribute pop'.
void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode)
Called to set constant rounding mode for floating point operations.
void ActOnPragmaMSSeg(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, StringLiteral *SegmentName, llvm::StringRef PragmaName)
Called on well formed #pragma bss_seg/data_seg/const_seg/code_seg.
void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, PragmaFloatControlKind Value)
ActOnPragmaFloatControl - Call on well-formed #pragma float_control.
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
void ActOnCapturedRegionError()
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
void ActOnPragmaMSAllocText(SourceLocation PragmaLocation, StringRef Section, const SmallVector< std::tuple< IdentifierInfo *, SourceLocation > > &Functions)
Called on well-formed #pragma alloc_text().
NamedDecl * LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, bool ForRedeclaration, SourceLocation Loc)
LazilyCreateBuiltin - The specified Builtin-ID was first used at file scope.
void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
void ActOnPragmaCXLimitedRange(SourceLocation Loc, LangOptions::ComplexRangeKind Range)
ActOnPragmaCXLimitedRange - Called on well formed #pragma STDC CX_LIMITED_RANGE.
void ActOnPragmaFPExceptions(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called on well formed '#pragma clang fp' that has option 'exceptions'.
void ActOnPragmaFPEvalMethod(SourceLocation Loc, LangOptions::FPEvalMethodKind Value)
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispMode Value)
Called on well formed #pragma vtordisp().
SemaCodeCompletion & CodeCompletion()
void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, CapturedRegionKind Kind, unsigned NumParams)
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero)
void ActOnPragmaWeakID(IdentifierInfo *WeakName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc)
ActOnPragmaWeakID - Called on well formed #pragma weak ident.
void ActOnPragmaMSFunction(SourceLocation Loc, const llvm::SmallVectorImpl< StringRef > &NoBuiltins)
Call on well formed #pragma function.
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
StmtResult ActOnCapturedRegionEnd(Stmt *S)
void ActOnPragmaFPValueChangingOption(SourceLocation Loc, PragmaFPKind Kind, bool IsEnabled)
Called on well formed #pragma clang fp reassociate or #pragma clang fp reciprocal.
void ActOnPragmaRedefineExtname(IdentifierInfo *WeakName, IdentifierInfo *AliasName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc, SourceLocation AliasNameLoc)
ActOnPragmaRedefineExtname - Called on well formed #pragma redefine_extname oldname newname.
ExprResult ActOnStringLiteral(ArrayRef< Token > StringToks, Scope *UDLScope=nullptr)
ActOnStringLiteral - The specified tokens were lexed as pasted string fragments (e....
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
OpenCLOptions & getOpenCLOptions()
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, PragmaMsStackAction Action, bool Value)
ActOnPragmaMSStrictGuardStackCheck - Called on well formed #pragma strict_gs_check.
ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope=nullptr)
void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
void ActOnPragmaWeakAlias(IdentifierInfo *WeakName, IdentifierInfo *AliasName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc, SourceLocation AliasNameLoc)
ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II)
Called on #pragma clang __debug dump II.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled)
ActOnPragmaFenvAccess - Called on well formed #pragma STDC FENV_ACCESS.
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
StringRef getString() const
unsigned getCharByteWidth() const
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
virtual bool hasStrictFP() const
Determine whether constrained floating point is supported on this target.
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
void setLiteralData(const char *Ptr)
bool isAnyIdentifier() const
Return true if this is a raw identifier (when lexing in raw mode) or a non-keyword identifier (when l...
SourceLocation getEndLoc() const
void setAnnotationEndLoc(SourceLocation L)
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
void setLength(unsigned Len)
void setKind(tok::TokenKind K)
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
void * getAnnotationValue() const
tok::TokenKind getKind() const
bool isRegularKeywordAttribute() const
Return true if the token is a keyword that is parsed in the same position as a standard attribute,...
bool isOneOf(Ts... Ks) const
void setLocation(SourceLocation L)
bool isNot(tok::TokenKind K) const
void setAnnotationValue(void *val)
void startToken()
Reset all flags to cleared.
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
SubjectMatchRule
A list of all the recognized kinds of attributes.
const char * getSubjectMatchRuleSpelling(SubjectMatchRule Rule)
uint32_t Literal
Literals are represented as positive integers.
@ Ignored
Do not present this diagnostic, ignore it.
@ FixIt
Parse and apply any fixits to the source.
const Regex Rule("(.+)/(.+)\\.framework/")
bool Pop(InterpState &S, CodePtr OpPC)
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
The JSON file list parser is used to communicate input to InstallAPI.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
MSVtorDispMode
In the Microsoft ABI, this controls the placement of virtual displacement members used to implement v...
const FunctionProtoType * T
@ None
The alignment was not explicit in code.
@ Parens
New-expression has a C++98 paren-delimited initializer.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Loop optimization hint for loop and unroll pragmas.
IdentifierLoc * OptionLoc
IdentifierLoc * PragmaNameLoc
Describes how and where the pragma was introduced.
PragmaMsStackAction Action