24#include "llvm/ADT/ArrayRef.h"
25#include "llvm/ADT/StringSwitch.h"
34 Token &FirstToken)
override;
38 explicit PragmaGCCVisibilityHandler() :
PragmaHandler(
"visibility") {}
40 Token &FirstToken)
override;
46 Token &FirstToken)
override;
52 Token &FirstToken)
override;
56 explicit PragmaClangSectionHandler(
Sema &S)
59 Token &FirstToken)
override;
66 explicit PragmaMSStructHandler() :
PragmaHandler(
"ms_struct") {}
68 Token &FirstToken)
override;
74 Token &FirstToken)
override;
80 Token &FirstToken)
override;
84 explicit PragmaRedefineExtnameHandler() :
PragmaHandler(
"redefine_extname") {}
86 Token &FirstToken)
override;
90 PragmaOpenCLExtensionHandler() :
PragmaHandler(
"EXTENSION") {}
92 Token &FirstToken)
override;
99 Token &FirstToken)
override;
106 PragmaSTDC_FENV_ACCESSHandler() :
PragmaHandler(
"FENV_ACCESS") {}
109 Token &Tok)
override {
110 Token PragmaName = Tok;
122 Toks[0].startToken();
123 Toks[0].setKind(tok::annot_pragma_fenv_access);
126 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
128 PP.EnterTokenStream(Toks,
true,
134struct PragmaSTDC_CX_LIMITED_RANGEHandler :
public PragmaHandler {
135 PragmaSTDC_CX_LIMITED_RANGEHandler() :
PragmaHandler(
"CX_LIMITED_RANGE") {}
138 Token &Tok)
override {
146 Toks[0].startToken();
147 Toks[0].setKind(tok::annot_pragma_cx_limited_range);
150 Toks[0].setAnnotationValue(
151 reinterpret_cast<void *
>(
static_cast<uintptr_t>(OOS)));
152 PP.EnterTokenStream(Toks,
true,
159 PragmaSTDC_FENV_ROUNDHandler() :
PragmaHandler(
"FENV_ROUND") {}
162 Token &Tok)
override;
167 PragmaSTDC_UnknownHandler() =
default;
170 Token &UnknownTok)
override {
172 PP.
Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
179 Token &FirstToken)
override;
185template <diag::kind IgnoredDiag>
187 PragmaNoSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
189 Token &FirstToken)
override;
192struct PragmaNoOpenMPHandler
193 :
public PragmaNoSupportHandler<diag::warn_pragma_omp_ignored> {
194 PragmaNoOpenMPHandler() : PragmaNoSupportHandler(
"omp") {}
197struct PragmaNoOpenACCHandler
198 :
public PragmaNoSupportHandler<diag::warn_pragma_acc_ignored> {
199 PragmaNoOpenACCHandler() : PragmaNoSupportHandler(
"acc") {}
208 PragmaSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
210 Token &FirstToken)
override;
213struct PragmaOpenMPHandler
214 :
public PragmaSupportHandler<tok::annot_pragma_openmp,
215 tok::annot_pragma_openmp_end,
216 diag::err_omp_unexpected_directive> {
217 PragmaOpenMPHandler() : PragmaSupportHandler(
"omp") {}
220struct PragmaOpenACCHandler
221 :
public PragmaSupportHandler<tok::annot_pragma_openacc,
222 tok::annot_pragma_openacc_end,
223 diag::err_acc_unexpected_directive> {
224 PragmaOpenACCHandler() : PragmaSupportHandler(
"acc") {}
229 PragmaCommentHandler(
Sema &Actions)
232 Token &FirstToken)
override;
239 PragmaDetectMismatchHandler(
Sema &Actions)
242 Token &FirstToken)
override;
249 PragmaFloatControlHandler(
Sema &Actions)
252 Token &FirstToken)
override;
256 explicit PragmaMSPointersToMembers() :
PragmaHandler(
"pointers_to_members") {}
258 Token &FirstToken)
override;
264 Token &FirstToken)
override;
270 Token &FirstToken)
override;
275 PragmaOptimizeHandler(
Sema &S)
278 Token &FirstToken)
override;
287 Token &FirstToken)
override;
293 Token &FirstToken)
override;
303 Token &FirstToken)
override;
308 PragmaMSFenvAccessHandler() :
PragmaHandler(
"fenv_access") {}
310 Token &FirstToken)
override {
320 if (Tok.
isNot(tok::l_paren)) {
326 if (Tok.
isNot(tok::identifier)) {
332 if (II->
isStr(
"on")) {
335 }
else if (II->
isStr(
"off")) {
342 if (Tok.
isNot(tok::r_paren)) {
349 if (Tok.
isNot(tok::eod)) {
357 Toks[0].startToken();
358 Toks[0].setKind(tok::annot_pragma_fenv_access_ms);
361 Toks[0].setAnnotationValue(
362 reinterpret_cast<void*
>(
static_cast<uintptr_t>(OOS)));
363 PP.EnterTokenStream(Toks,
true,
368struct PragmaForceCUDAHostDeviceHandler :
public PragmaHandler {
369 PragmaForceCUDAHostDeviceHandler(
Sema &Actions)
370 :
PragmaHandler(
"force_cuda_host_device"), Actions(Actions) {}
372 Token &FirstToken)
override;
381 :
PragmaHandler(
"attribute"), AttributesForPragmaAttribute(AttrFactory) {}
383 Token &FirstToken)
override;
390 PragmaMaxTokensHereHandler() :
PragmaHandler(
"max_tokens_here") {}
392 Token &FirstToken)
override;
396 PragmaMaxTokensTotalHandler() :
PragmaHandler(
"max_tokens_total") {}
398 Token &FirstToken)
override;
402 PragmaRISCVHandler(
Sema &Actions)
405 Token &FirstToken)
override;
417void Parser::initializePragmaHandlers() {
418 AlignHandler = std::make_unique<PragmaAlignHandler>();
421 GCCVisibilityHandler = std::make_unique<PragmaGCCVisibilityHandler>();
424 OptionsHandler = std::make_unique<PragmaOptionsHandler>();
427 PackHandler = std::make_unique<PragmaPackHandler>();
430 MSStructHandler = std::make_unique<PragmaMSStructHandler>();
433 UnusedHandler = std::make_unique<PragmaUnusedHandler>();
436 WeakHandler = std::make_unique<PragmaWeakHandler>();
439 RedefineExtnameHandler = std::make_unique<PragmaRedefineExtnameHandler>();
442 FPContractHandler = std::make_unique<PragmaFPContractHandler>();
445 STDCFenvAccessHandler = std::make_unique<PragmaSTDC_FENV_ACCESSHandler>();
448 STDCFenvRoundHandler = std::make_unique<PragmaSTDC_FENV_ROUNDHandler>();
451 STDCCXLIMITHandler = std::make_unique<PragmaSTDC_CX_LIMITED_RANGEHandler>();
454 STDCUnknownHandler = std::make_unique<PragmaSTDC_UnknownHandler>();
457 PCSectionHandler = std::make_unique<PragmaClangSectionHandler>(Actions);
461 OpenCLExtensionHandler = std::make_unique<PragmaOpenCLExtensionHandler>();
467 OpenMPHandler = std::make_unique<PragmaOpenMPHandler>();
469 OpenMPHandler = std::make_unique<PragmaNoOpenMPHandler>();
473 OpenACCHandler = std::make_unique<PragmaOpenACCHandler>();
475 OpenACCHandler = std::make_unique<PragmaNoOpenACCHandler>();
480 MSCommentHandler = std::make_unique<PragmaCommentHandler>(Actions);
484 FloatControlHandler = std::make_unique<PragmaFloatControlHandler>(Actions);
487 MSDetectMismatchHandler =
488 std::make_unique<PragmaDetectMismatchHandler>(Actions);
490 MSPointersToMembers = std::make_unique<PragmaMSPointersToMembers>();
492 MSVtorDisp = std::make_unique<PragmaMSVtorDisp>();
494 MSInitSeg = std::make_unique<PragmaMSPragma>(
"init_seg");
496 MSDataSeg = std::make_unique<PragmaMSPragma>(
"data_seg");
498 MSBSSSeg = std::make_unique<PragmaMSPragma>(
"bss_seg");
500 MSConstSeg = std::make_unique<PragmaMSPragma>(
"const_seg");
502 MSCodeSeg = std::make_unique<PragmaMSPragma>(
"code_seg");
504 MSSection = std::make_unique<PragmaMSPragma>(
"section");
506 MSStrictGuardStackCheck =
507 std::make_unique<PragmaMSPragma>(
"strict_gs_check");
509 MSFunction = std::make_unique<PragmaMSPragma>(
"function");
511 MSAllocText = std::make_unique<PragmaMSPragma>(
"alloc_text");
513 MSOptimize = std::make_unique<PragmaMSPragma>(
"optimize");
515 MSRuntimeChecks = std::make_unique<PragmaMSRuntimeChecksHandler>();
517 MSIntrinsic = std::make_unique<PragmaMSIntrinsicHandler>();
519 MSFenvAccess = std::make_unique<PragmaMSFenvAccessHandler>();
524 CUDAForceHostDeviceHandler =
525 std::make_unique<PragmaForceCUDAHostDeviceHandler>(Actions);
529 OptimizeHandler = std::make_unique<PragmaOptimizeHandler>(Actions);
532 LoopHintHandler = std::make_unique<PragmaLoopHintHandler>();
535 UnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"unroll");
539 NoUnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"nounroll");
543 UnrollAndJamHintHandler =
544 std::make_unique<PragmaUnrollHintHandler>(
"unroll_and_jam");
547 NoUnrollAndJamHintHandler =
548 std::make_unique<PragmaUnrollHintHandler>(
"nounroll_and_jam");
551 FPHandler = std::make_unique<PragmaFPHandler>();
554 AttributePragmaHandler =
555 std::make_unique<PragmaAttributeHandler>(AttrFactory);
558 MaxTokensHerePragmaHandler = std::make_unique<PragmaMaxTokensHereHandler>();
561 MaxTokensTotalPragmaHandler = std::make_unique<PragmaMaxTokensTotalHandler>();
565 RISCVPragmaHandler = std::make_unique<PragmaRISCVHandler>(Actions);
570void Parser::resetPragmaHandlers() {
573 AlignHandler.reset();
575 GCCVisibilityHandler.reset();
577 OptionsHandler.reset();
581 MSStructHandler.reset();
583 UnusedHandler.reset();
587 RedefineExtnameHandler.reset();
591 OpenCLExtensionHandler.reset();
595 OpenMPHandler.reset();
598 OpenACCHandler.reset();
603 MSCommentHandler.reset();
607 PCSectionHandler.reset();
610 FloatControlHandler.reset();
613 MSDetectMismatchHandler.reset();
615 MSPointersToMembers.reset();
631 MSStrictGuardStackCheck.reset();
637 MSRuntimeChecks.reset();
643 MSFenvAccess.reset();
648 CUDAForceHostDeviceHandler.reset();
652 FPContractHandler.reset();
655 STDCFenvAccessHandler.reset();
658 STDCFenvRoundHandler.reset();
661 STDCCXLIMITHandler.reset();
664 STDCUnknownHandler.reset();
667 OptimizeHandler.reset();
670 LoopHintHandler.reset();
674 UnrollHintHandler.reset();
678 NoUnrollHintHandler.reset();
681 UnrollAndJamHintHandler.reset();
684 NoUnrollAndJamHintHandler.reset();
690 AttributePragmaHandler.reset();
693 MaxTokensHerePragmaHandler.reset();
696 MaxTokensTotalPragmaHandler.reset();
700 RISCVPragmaHandler.reset();
709void Parser::HandlePragmaUnused() {
710 assert(Tok.
is(tok::annot_pragma_unused));
716void Parser::HandlePragmaVisibility() {
717 assert(Tok.
is(tok::annot_pragma_vis));
724void Parser::HandlePragmaPack() {
725 assert(Tok.
is(tok::annot_pragma_pack));
733 ConsumeAnnotationToken();
741 ConsumeAnnotationToken();
744void Parser::HandlePragmaMSStruct() {
745 assert(Tok.
is(tok::annot_pragma_msstruct));
749 ConsumeAnnotationToken();
752void Parser::HandlePragmaAlign() {
753 assert(Tok.
is(tok::annot_pragma_align));
760 ConsumeAnnotationToken();
763void Parser::HandlePragmaDump() {
764 assert(Tok.
is(tok::annot_pragma_dump));
765 ConsumeAnnotationToken();
766 if (Tok.
is(tok::eod)) {
767 PP.
Diag(Tok, diag::warn_pragma_debug_missing_argument) <<
"dump";
769 if (Tok.
isNot(tok::identifier)) {
770 PP.
Diag(Tok, diag::warn_pragma_debug_unexpected_argument);
772 ExpectAndConsume(tok::eod);
786 PP.
Diag(StartLoc, diag::warn_pragma_debug_dependent_argument)
794 ExpectAndConsume(tok::eod);
797void Parser::HandlePragmaWeak() {
798 assert(Tok.
is(tok::annot_pragma_weak));
805void Parser::HandlePragmaWeakAlias() {
806 assert(Tok.
is(tok::annot_pragma_weakalias));
815 WeakNameLoc, AliasNameLoc);
819void Parser::HandlePragmaRedefineExtname() {
820 assert(Tok.
is(tok::annot_pragma_redefine_extname));
829 RedefNameLoc, AliasNameLoc);
832void Parser::HandlePragmaFPContract() {
833 assert(Tok.
is(tok::annot_pragma_fp_contract));
855void Parser::HandlePragmaFloatControl() {
856 assert(Tok.
is(tok::annot_pragma_float_control));
871void Parser::HandlePragmaFEnvAccess() {
872 assert(Tok.
is(tok::annot_pragma_fenv_access) ||
873 Tok.
is(tok::annot_pragma_fenv_access_ms));
895void Parser::HandlePragmaFEnvRound() {
896 assert(Tok.
is(tok::annot_pragma_fenv_round));
897 auto RM =
static_cast<llvm::RoundingMode
>(
904void Parser::HandlePragmaCXLimitedRange() {
905 assert(Tok.
is(tok::annot_pragma_cx_limited_range));
931 assert(Tok.
is(tok::annot_pragma_captured));
932 ConsumeAnnotationToken();
934 if (Tok.
isNot(tok::l_brace)) {
935 PP.
Diag(Tok, diag::err_expected) << tok::l_brace;
947 CapturedRegionScope.Exit();
958 enum OpenCLExtState :
char {
959 Disable, Enable,
Begin, End
961 typedef std::pair<const IdentifierInfo *, OpenCLExtState> OpenCLExtData;
964void Parser::HandlePragmaOpenCLExtension() {
965 assert(Tok.
is(tok::annot_pragma_opencl_extension));
967 auto State =
Data->second;
968 auto Ident =
Data->first;
970 ConsumeAnnotationToken();
973 auto Name = Ident->getName();
978 if (State == Disable)
981 PP.
Diag(NameLoc, diag::warn_pragma_expected_predicate) << 1;
982 }
else if (State ==
Begin) {
983 if (!Opt.isKnown(Name) || !Opt.isSupported(Name,
getLangOpts())) {
987 Opt.acceptsPragma(Name);
989 }
else if (State == End) {
992 }
else if (!Opt.isKnown(Name) || !Opt.isWithPragma(Name))
993 PP.
Diag(NameLoc, diag::warn_pragma_unknown_extension) << Ident;
994 else if (Opt.isSupportedExtension(Name,
getLangOpts()))
995 Opt.enable(Name, State == Enable);
996 else if (Opt.isSupportedCoreOrOptionalCore(Name,
getLangOpts()))
997 PP.
Diag(NameLoc, diag::warn_pragma_extension_is_core) << Ident;
999 PP.
Diag(NameLoc, diag::warn_pragma_unsupported_extension) << Ident;
1002void Parser::HandlePragmaMSPointersToMembers() {
1003 assert(Tok.
is(tok::annot_pragma_ms_pointers_to_members));
1011void Parser::HandlePragmaMSVtorDisp() {
1012 assert(Tok.
is(tok::annot_pragma_ms_vtordisp));
1021void Parser::HandlePragmaMSPragma() {
1022 assert(Tok.
is(tok::annot_pragma_ms_pragma));
1026 PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second,
true,
1037 llvm::StringSwitch<PragmaHandler>(PragmaName)
1038 .Case(
"data_seg", &Parser::HandlePragmaMSSegment)
1039 .Case(
"bss_seg", &Parser::HandlePragmaMSSegment)
1040 .Case(
"const_seg", &Parser::HandlePragmaMSSegment)
1041 .Case(
"code_seg", &Parser::HandlePragmaMSSegment)
1042 .Case(
"section", &Parser::HandlePragmaMSSection)
1043 .Case(
"init_seg", &Parser::HandlePragmaMSInitSeg)
1044 .Case(
"strict_gs_check", &Parser::HandlePragmaMSStrictGuardStackCheck)
1045 .Case(
"function", &Parser::HandlePragmaMSFunction)
1046 .Case(
"alloc_text", &Parser::HandlePragmaMSAllocText)
1047 .Case(
"optimize", &Parser::HandlePragmaMSOptimize);
1049 if (!(this->*Handler)(PragmaName, PragmaLocation)) {
1052 while (Tok.
isNot(tok::eof))
1058bool Parser::HandlePragmaMSSection(StringRef PragmaName,
1060 if (Tok.
isNot(tok::l_paren)) {
1061 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1066 if (Tok.
isNot(tok::string_literal)) {
1067 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1076 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1081 bool SectionFlagsAreDefault =
true;
1082 while (Tok.
is(tok::comma)) {
1087 if (Tok.
is(tok::kw_long) || Tok.
is(tok::kw_short)) {
1093 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren)
1098 llvm::StringSwitch<ASTContext::PragmaSectionFlag>(
1111 ? diag::warn_pragma_invalid_specific_action
1112 : diag::warn_pragma_unsupported_action)
1116 SectionFlags |= Flag;
1117 SectionFlagsAreDefault =
false;
1122 if (SectionFlagsAreDefault)
1124 if (Tok.
isNot(tok::r_paren)) {
1125 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1129 if (Tok.
isNot(tok::eof)) {
1130 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1139bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
1141 if (Tok.
isNot(tok::l_paren)) {
1142 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1147 StringRef SlotLabel;
1150 if (PushPop ==
"push")
1152 else if (PushPop ==
"pop")
1155 PP.
Diag(PragmaLocation,
1156 diag::warn_pragma_expected_section_push_pop_or_name)
1162 if (Tok.
is(tok::comma)) {
1168 if (Tok.
is(tok::comma))
1170 else if (Tok.
isNot(tok::r_paren)) {
1171 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc)
1176 }
else if (Tok.
isNot(tok::r_paren)) {
1177 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc) << PragmaName;
1184 if (Tok.
isNot(tok::r_paren)) {
1185 if (Tok.
isNot(tok::string_literal)) {
1187 diag::warn_pragma_expected_section_name :
1188 diag::warn_pragma_expected_section_label_or_name :
1189 diag::warn_pragma_expected_section_push_pop_or_name;
1190 PP.
Diag(PragmaLocation, DiagID) << PragmaName;
1196 SegmentName = cast<StringLiteral>(StringResult.
get());
1198 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1206 if (Tok.
isNot(tok::r_paren)) {
1207 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1211 if (Tok.
isNot(tok::eof)) {
1212 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1218 SegmentName, PragmaName);
1223bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
1225 if (
getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) {
1226 PP.
Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target);
1230 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1238 StringRef Section = llvm::StringSwitch<StringRef>(II->
getName())
1239 .Case(
"compiler",
"\".CRT$XCC\"")
1240 .Case(
"lib",
"\".CRT$XCL\"")
1241 .Case(
"user",
"\".CRT$XCU\"")
1244 if (!Section.empty()) {
1248 Toks[0].
setKind(tok::string_literal);
1256 }
else if (Tok.
is(tok::string_literal)) {
1260 SegmentName = cast<StringLiteral>(StringResult.
get());
1262 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1270 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName;
1274 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1276 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1287bool Parser::HandlePragmaMSStrictGuardStackCheck(
1289 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1294 if (Tok.
is(tok::identifier)) {
1296 if (PushPop ==
"push") {
1299 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_punc,
1302 }
else if (PushPop ==
"pop") {
1311 if (II && II->
isStr(
"off")) {
1314 }
else if (II && II->
isStr(
"on")) {
1325 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1329 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1337bool Parser::HandlePragmaMSAllocText(StringRef PragmaName,
1339 Token FirstTok = Tok;
1340 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1345 if (Tok.
is(tok::string_literal)) {
1351 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1356 }
else if (Tok.
is(tok::identifier)) {
1360 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1365 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
1371 if (Tok.
isNot(tok::identifier)) {
1381 if (Tok.
isNot(tok::comma))
1386 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1388 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1398 std::string ClangLoopStr(
"clang loop ");
1401 return std::string(llvm::StringSwitch<StringRef>(Str)
1402 .Case(
"loop", ClangLoopStr)
1403 .Case(
"unroll_and_jam", Str)
1404 .Case(
"unroll", Str)
1408bool Parser::HandlePragmaLoopHint(
LoopHint &Hint) {
1409 assert(Tok.
is(tok::annot_pragma_loop_hint));
1429 auto IsLoopHint = llvm::StringSwitch<bool>(PragmaNameInfo->
getName())
1430 .Cases(
"unroll",
"nounroll",
"unroll_and_jam",
1431 "nounroll_and_jam",
true)
1434 if (Toks.empty() && IsLoopHint) {
1435 ConsumeAnnotationToken();
1442 assert(!Toks.empty() &&
1443 "PragmaLoopHintInfo::Toks must contain at least one token.");
1446 bool OptionUnroll =
false;
1447 bool OptionUnrollAndJam =
false;
1448 bool OptionDistribute =
false;
1449 bool OptionPipelineDisabled =
false;
1450 bool StateOption =
false;
1452 OptionUnroll = OptionInfo->
isStr(
"unroll");
1453 OptionUnrollAndJam = OptionInfo->
isStr(
"unroll_and_jam");
1454 OptionDistribute = OptionInfo->
isStr(
"distribute");
1455 OptionPipelineDisabled = OptionInfo->
isStr(
"pipeline");
1456 StateOption = llvm::StringSwitch<bool>(OptionInfo->
getName())
1457 .Case(
"vectorize",
true)
1458 .Case(
"interleave",
true)
1459 .Case(
"vectorize_predicate",
true)
1461 OptionUnroll || OptionUnrollAndJam || OptionDistribute ||
1462 OptionPipelineDisabled;
1465 bool AssumeSafetyArg = !OptionUnroll && !OptionUnrollAndJam &&
1466 !OptionDistribute && !OptionPipelineDisabled;
1468 if (Toks[0].is(tok::eof)) {
1469 ConsumeAnnotationToken();
1470 Diag(Toks[0].getLocation(), diag::err_pragma_loop_missing_argument)
1472 << (OptionUnroll || OptionUnrollAndJam)
1479 ConsumeAnnotationToken();
1483 bool Valid = StateInfo &&
1484 llvm::StringSwitch<bool>(StateInfo->
getName())
1485 .Case(
"disable",
true)
1486 .Case(
"enable", !OptionPipelineDisabled)
1487 .Case(
"full", OptionUnroll || OptionUnrollAndJam)
1488 .Case(
"assume_safety", AssumeSafetyArg)
1491 if (OptionPipelineDisabled) {
1492 Diag(Toks[0].getLocation(), diag::err_pragma_pipeline_invalid_keyword);
1494 Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword)
1495 << (OptionUnroll || OptionUnrollAndJam)
1500 if (Toks.size() > 2)
1504 }
else if (OptionInfo && OptionInfo->
getName() ==
"vectorize_width") {
1505 PP.EnterTokenStream(Toks,
false,
1507 ConsumeAnnotationToken();
1511 StringRef IsScalableStr = StateInfo ? StateInfo->
getName() :
"";
1514 if (IsScalableStr ==
"scalable" || IsScalableStr ==
"fixed") {
1517 if (Toks.size() > 2) {
1520 while (Tok.
isNot(tok::eof))
1533 Diag(Toks[0].getLocation(),
1534 diag::note_pragma_loop_invalid_vectorize_option);
1536 bool Arg2Error =
false;
1537 if (Tok.
is(tok::comma)) {
1541 IsScalableStr = StateInfo->
getName();
1543 if (IsScalableStr !=
"scalable" && IsScalableStr !=
"fixed") {
1545 diag::err_pragma_loop_invalid_vectorize_option);
1556 if (Tok.
isNot(tok::eof)) {
1559 while (Tok.
isNot(tok::eof))
1574 PP.EnterTokenStream(Toks,
false,
1576 ConsumeAnnotationToken();
1581 if (Tok.
isNot(tok::eof)) {
1584 while (Tok.
isNot(tok::eof))
1599 Info->
Toks.back().getLocation());
1604struct PragmaAttributeInfo {
1605 enum ActionType { Push,
Pop, Attribute };
1611 PragmaAttributeInfo(
ParsedAttributes &Attributes) : Attributes(Attributes) {}
1614#include "clang/Parse/AttrSubMatchRulesParserStringSwitches.inc"
1619 if (Tok.
is(tok::identifier))
1628 using namespace attr;
1630#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract) \
1633#include "clang/Basic/AttrSubMatchRulesList.inc"
1635 llvm_unreachable(
"Invalid attribute subject match rule");
1643 PRef.
Diag(SubRuleLoc,
1644 diag::err_pragma_attribute_expected_subject_sub_identifier)
1646 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1657 PRef.
Diag(SubRuleLoc, diag::err_pragma_attribute_unknown_subject_sub_rule)
1658 << SubRuleName << PrimaryRuleName;
1659 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1665bool Parser::ParsePragmaAttributeSubjectMatchRuleSet(
1673 if (AnyParens.expectAndConsume())
1681 Diag(Tok, diag::err_pragma_attribute_expected_subject_identifier);
1684 std::pair<std::optional<attr::SubjectMatchRule>,
1685 std::optional<attr::SubjectMatchRule> (*)(StringRef,
bool)>
1686 Rule = isAttributeSubjectMatchRule(Name);
1688 Diag(Tok, diag::err_pragma_attribute_unknown_subject_rule) << Name;
1696 if (
Parens.expectAndConsume())
1698 }
else if (
Parens.consumeOpen()) {
1699 if (!SubjectMatchRules
1701 std::make_pair(PrimaryRule,
SourceRange(RuleLoc, RuleLoc)))
1703 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1706 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleLoc));
1707 LastMatchRuleEndLoc = RuleLoc;
1713 if (SubRuleName.empty()) {
1719 if (SubRuleName ==
"unless") {
1722 if (
Parens.expectAndConsume())
1725 if (SubRuleName.empty()) {
1730 auto SubRuleOrNone = Rule.second(SubRuleName,
true);
1731 if (!SubRuleOrNone) {
1732 std::string SubRuleUnlessName =
"unless(" + SubRuleName.str() +
")";
1734 SubRuleUnlessName, SubRuleLoc);
1737 SubRule = *SubRuleOrNone;
1739 if (
Parens.consumeClose())
1742 auto SubRuleOrNone = Rule.second(SubRuleName,
false);
1743 if (!SubRuleOrNone) {
1748 SubRule = *SubRuleOrNone;
1752 LastMatchRuleEndLoc = RuleEndLoc;
1753 if (
Parens.consumeClose())
1755 if (!SubjectMatchRules
1756 .insert(std::make_pair(SubRule,
SourceRange(RuleLoc, RuleEndLoc)))
1758 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1761 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleEndLoc));
1767 if (AnyParens.consumeClose())
1776enum class MissingAttributeSubjectRulesRecoveryPoint {
1784MissingAttributeSubjectRulesRecoveryPoint
1785getAttributeSubjectRulesRecoveryPointForToken(
const Token &Tok) {
1787 if (II->
isStr(
"apply_to"))
1788 return MissingAttributeSubjectRulesRecoveryPoint::ApplyTo;
1789 if (II->
isStr(
"any"))
1790 return MissingAttributeSubjectRulesRecoveryPoint::Any;
1792 if (Tok.
is(tok::equal))
1793 return MissingAttributeSubjectRulesRecoveryPoint::Equals;
1794 return MissingAttributeSubjectRulesRecoveryPoint::None;
1802 MissingAttributeSubjectRulesRecoveryPoint Point,
Parser &PRef) {
1808 MissingAttributeSubjectRulesRecoveryPoint EndPoint =
1809 getAttributeSubjectRulesRecoveryPointForToken(PRef.
getCurToken());
1810 if (Point == MissingAttributeSubjectRulesRecoveryPoint::Comma)
1812 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::ApplyTo &&
1813 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::ApplyTo)
1814 FixIt +=
"apply_to";
1815 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::Equals &&
1816 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::Equals)
1819 if (EndPoint == MissingAttributeSubjectRulesRecoveryPoint::None) {
1826 Attribute.getMatchRules(PRef.
getLangOpts(), MatchRules);
1828 for (
const auto &Rule : MatchRules) {
1833 IsSupported[Rule.first] =
true;
1835 IsMatchRuleAvailable &= IsSupported;
1837 if (IsMatchRuleAvailable.count() == 0) {
1843 bool NeedsComma =
false;
1845 if (!IsMatchRuleAvailable[I])
1859 if (FixItRange.getBegin() == FixItRange.getEnd())
1869void Parser::HandlePragmaAttribute() {
1870 assert(Tok.
is(tok::annot_pragma_attribute) &&
1871 "Expected #pragma attribute annotation token");
1874 if (Info->Action == PragmaAttributeInfo::Pop) {
1875 ConsumeAnnotationToken();
1880 assert((Info->Action == PragmaAttributeInfo::Push ||
1881 Info->Action == PragmaAttributeInfo::Attribute) &&
1882 "Unexpected #pragma attribute command");
1884 if (Info->Action == PragmaAttributeInfo::Push && Info->Tokens.empty()) {
1885 ConsumeAnnotationToken();
1890 PP.EnterTokenStream(Info->Tokens,
false,
1892 ConsumeAnnotationToken();
1897 auto SkipToEnd = [
this]() {
1902 if ((Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) ||
1905 ParseCXX11AttributeSpecifier(Attrs);
1906 }
else if (Tok.
is(tok::kw___attribute)) {
1908 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
1911 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"("))
1916 if (Tok.
is(tok::code_completion)) {
1925 if (Tok.
isNot(tok::identifier)) {
1926 Diag(Tok, diag::err_pragma_attribute_expected_attribute_name);
1933 if (Tok.
isNot(tok::l_paren))
1934 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1935 ParsedAttr::Form::GNU());
1937 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs,
nullptr,
1940 ParsedAttr::Form::GNU(),
1944 if (ExpectAndConsume(tok::r_paren))
1946 if (ExpectAndConsume(tok::r_paren))
1948 }
else if (Tok.
is(tok::kw___declspec)) {
1949 ParseMicrosoftDeclSpecs(Attrs);
1951 Diag(Tok, diag::err_pragma_attribute_expected_attribute_syntax);
1960 if (Tok.
is(tok::l_paren)) {
1963 if (Tok.
isNot(tok::r_paren))
1966 Diag(Tok, diag::note_pragma_attribute_use_attribute_kw)
1975 if (Attrs.
empty() || Attrs.
begin()->isInvalid()) {
1981 if (!Attribute.isSupportedByPragmaAttribute()) {
1982 Diag(PragmaLoc, diag::err_pragma_attribute_unsupported_attribute)
1991 createExpectedAttributeSubjectRulesTokenDiagnostic(
1992 diag::err_expected, Attrs,
1993 MissingAttributeSubjectRulesRecoveryPoint::Comma, *
this)
1999 if (Tok.
isNot(tok::identifier)) {
2000 createExpectedAttributeSubjectRulesTokenDiagnostic(
2001 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2002 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2007 if (!II->
isStr(
"apply_to")) {
2008 createExpectedAttributeSubjectRulesTokenDiagnostic(
2009 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2010 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2017 createExpectedAttributeSubjectRulesTokenDiagnostic(
2018 diag::err_expected, Attrs,
2019 MissingAttributeSubjectRulesRecoveryPoint::Equals, *
this)
2027 if (ParsePragmaAttributeSubjectMatchRuleSet(SubjectMatchRules, AnyLoc,
2028 LastMatchRuleEndLoc)) {
2035 if (Tok.
isNot(tok::eof)) {
2036 Diag(Tok, diag::err_pragma_attribute_extra_tokens_after_attribute);
2045 if (Info->Action == PragmaAttributeInfo::Push)
2057void PragmaGCCVisibilityHandler::HandlePragma(
Preprocessor &PP,
2068 if (PushPop && PushPop->
isStr(
"pop")) {
2070 }
else if (PushPop && PushPop->
isStr(
"push")) {
2072 if (Tok.
isNot(tok::l_paren)) {
2085 if (Tok.
isNot(tok::r_paren)) {
2097 if (Tok.
isNot(tok::eod)) {
2103 auto Toks = std::make_unique<Token[]>(1);
2104 Toks[0].startToken();
2105 Toks[0].setKind(tok::annot_pragma_vis);
2106 Toks[0].setLocation(VisLoc);
2107 Toks[0].setAnnotationEndLoc(EndLoc);
2108 Toks[0].setAnnotationValue(
2109 const_cast<void *
>(
static_cast<const void *
>(VisType)));
2110 PP.EnterTokenStream(std::move(Toks), 1,
true,
2125 if (Tok.
isNot(tok::l_paren)) {
2126 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"pack";
2131 StringRef SlotLabel;
2135 if (Tok.
is(tok::numeric_constant)) {
2146 }
else if (Tok.
is(tok::identifier)) {
2148 if (II->
isStr(
"show")) {
2152 if (II->
isStr(
"push")) {
2154 }
else if (II->
isStr(
"pop")) {
2157 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_invalid_action) <<
"pack";
2162 if (Tok.
is(tok::comma)) {
2165 if (Tok.
is(tok::numeric_constant)) {
2170 }
else if (Tok.
is(tok::identifier)) {
2174 if (Tok.
is(tok::comma)) {
2177 if (Tok.
isNot(tok::numeric_constant)) {
2202 if (Tok.
isNot(tok::r_paren)) {
2203 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"pack";
2209 if (Tok.
isNot(tok::eod)) {
2210 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"pack";
2222 Toks[0].startToken();
2223 Toks[0].setKind(tok::annot_pragma_pack);
2224 Toks[0].setLocation(PackLoc);
2225 Toks[0].setAnnotationEndLoc(RParenLoc);
2226 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2227 PP.EnterTokenStream(Toks,
true,
2233void PragmaMSStructHandler::HandlePragma(
Preprocessor &PP,
2235 Token &MSStructTok) {
2240 if (Tok.
isNot(tok::identifier)) {
2246 if (II->
isStr(
"on")) {
2250 else if (II->
isStr(
"off") || II->
isStr(
"reset"))
2257 if (Tok.
isNot(tok::eod)) {
2265 Toks[0].startToken();
2266 Toks[0].setKind(tok::annot_pragma_msstruct);
2268 Toks[0].setAnnotationEndLoc(EndLoc);
2269 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2271 PP.EnterTokenStream(Toks,
true,
2276void PragmaClangSectionHandler::HandlePragma(
Preprocessor &PP,
2278 Token &FirstToken) {
2284 while (Tok.
isNot(tok::eod)) {
2285 if (Tok.
isNot(tok::identifier)) {
2286 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2291 if (SecType->
isStr(
"bss"))
2293 else if (SecType->
isStr(
"data"))
2295 else if (SecType->
isStr(
"rodata"))
2297 else if (SecType->
isStr(
"relro"))
2299 else if (SecType->
isStr(
"text"))
2302 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2308 if (Tok.
isNot(tok::equal)) {
2309 PP.
Diag(Tok.
getLocation(), diag::err_pragma_clang_section_expected_equal) << SecKind;
2313 std::string SecName;
2317 Actions.ActOnPragmaClangSection(
2334 if (Tok.
isNot(tok::identifier) ||
2343 if (Tok.
isNot(tok::l_paren)) {
2344 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"align";
2347 }
else if (Tok.
isNot(tok::equal)) {
2354 if (Tok.
isNot(tok::identifier)) {
2356 << (IsOptions ?
"options" :
"align");
2362 if (II->
isStr(
"native"))
2364 else if (II->
isStr(
"natural"))
2366 else if (II->
isStr(
"packed"))
2368 else if (II->
isStr(
"power"))
2370 else if (II->
isStr(
"mac68k"))
2372 else if (II->
isStr(
"reset"))
2382 if (Tok.
isNot(tok::r_paren)) {
2383 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"align";
2390 if (Tok.
isNot(tok::eod)) {
2392 << (IsOptions ?
"options" :
"align");
2398 Toks[0].startToken();
2399 Toks[0].setKind(tok::annot_pragma_align);
2401 Toks[0].setAnnotationEndLoc(EndLoc);
2402 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2404 PP.EnterTokenStream(Toks,
true,
2414void PragmaOptionsHandler::HandlePragma(
Preprocessor &PP,
2416 Token &OptionsTok) {
2421void PragmaUnusedHandler::HandlePragma(
Preprocessor &PP,
2430 if (Tok.
isNot(tok::l_paren)) {
2431 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"unused";
2444 if (Tok.
is(tok::identifier)) {
2445 Identifiers.push_back(Tok);
2456 if (Tok.
is(tok::comma)) {
2461 if (Tok.
is(tok::r_paren)) {
2467 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_punc) <<
"unused";
2472 if (Tok.
isNot(tok::eod)) {
2479 assert(RParenLoc.
isValid() &&
"Valid '#pragma unused' must have ')'");
2480 assert(!Identifiers.empty() &&
"Valid '#pragma unused' must have arguments");
2489 2 * Identifiers.size());
2490 for (
unsigned i=0; i != Identifiers.size(); i++) {
2491 Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
2493 pragmaUnusedTok.
setKind(tok::annot_pragma_unused);
2495 idTok = Identifiers[i];
2497 PP.EnterTokenStream(Toks,
true,
2510 if (Tok.
isNot(tok::identifier)) {
2511 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_identifier) <<
"weak";
2515 Token WeakName = Tok;
2516 bool HasAlias =
false;
2520 if (Tok.
is(tok::equal)) {
2523 if (Tok.
isNot(tok::identifier)) {
2532 if (Tok.
isNot(tok::eod)) {
2533 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"weak";
2540 Token &pragmaUnusedTok = Toks[0];
2542 pragmaUnusedTok.
setKind(tok::annot_pragma_weakalias);
2546 Toks[2] = AliasName;
2547 PP.EnterTokenStream(Toks,
true,
2552 Token &pragmaUnusedTok = Toks[0];
2554 pragmaUnusedTok.
setKind(tok::annot_pragma_weak);
2558 PP.EnterTokenStream(Toks,
true,
2564void PragmaRedefineExtnameHandler::HandlePragma(
Preprocessor &PP,
2566 Token &RedefToken) {
2571 if (Tok.
isNot(tok::identifier)) {
2577 Token RedefName = Tok;
2580 if (Tok.
isNot(tok::identifier)) {
2582 <<
"redefine_extname";
2586 Token AliasName = Tok;
2589 if (Tok.
isNot(tok::eod)) {
2597 Token &pragmaRedefTok = Toks[0];
2599 pragmaRedefTok.
setKind(tok::annot_pragma_redefine_extname);
2602 Toks[1] = RedefName;
2603 Toks[2] = AliasName;
2604 PP.EnterTokenStream(Toks,
true,
2608void PragmaFPContractHandler::HandlePragma(
Preprocessor &PP,
2617 Toks[0].startToken();
2618 Toks[0].setKind(tok::annot_pragma_fp_contract);
2621 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2623 PP.EnterTokenStream(Toks,
true,
2627void PragmaOpenCLExtensionHandler::HandlePragma(
Preprocessor &PP,
2631 if (Tok.
isNot(tok::identifier)) {
2640 if (Tok.
isNot(tok::colon)) {
2646 if (Tok.
isNot(tok::identifier)) {
2647 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_predicate) << 0;
2652 OpenCLExtState State;
2653 if (Pred->
isStr(
"enable")) {
2655 }
else if (Pred->
isStr(
"disable")) {
2657 }
else if (Pred->
isStr(
"begin"))
2659 else if (Pred->
isStr(
"end"))
2663 << Ext->
isStr(
"all");
2669 if (Tok.
isNot(tok::eod)) {
2677 Info->second = State;
2680 Toks[0].startToken();
2681 Toks[0].setKind(tok::annot_pragma_opencl_extension);
2682 Toks[0].setLocation(NameLoc);
2683 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2684 Toks[0].setAnnotationEndLoc(StateLoc);
2685 PP.EnterTokenStream(Toks,
true,
2695template <diag::kind IgnoredDiag>
2696void PragmaNoSupportHandler<IgnoredDiag>::HandlePragma(
2699 PP.
Diag(FirstTok, IgnoredDiag);
2710void PragmaSupportHandler<StartTok, EndTok, UnexpectedDiag>::HandlePragma(
2718 while (Tok.
isNot(tok::eod) && Tok.
isNot(tok::eof)) {
2719 Pragma.push_back(Tok);
2721 if (Tok.
is(StartTok)) {
2722 PP.
Diag(Tok, UnexpectedDiag) << 0;
2723 unsigned InnerPragmaCnt = 1;
2724 while (InnerPragmaCnt != 0) {
2726 if (Tok.
is(StartTok))
2728 else if (Tok.
is(EndTok))
2738 Pragma.push_back(Tok);
2740 auto Toks = std::make_unique<Token[]>(Pragma.size());
2741 std::copy(Pragma.begin(), Pragma.end(), Toks.get());
2742 PP.EnterTokenStream(std::move(Toks), Pragma.size(),
2754void PragmaMSPointersToMembers::HandlePragma(
Preprocessor &PP,
2759 if (Tok.
isNot(tok::l_paren)) {
2760 PP.
Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen)
2761 <<
"pointers_to_members";
2768 <<
"pointers_to_members";
2774 if (Arg->
isStr(
"best_case")) {
2777 if (Arg->
isStr(
"full_generality")) {
2778 if (Tok.
is(tok::comma)) {
2784 diag::err_pragma_pointers_to_members_unknown_kind)
2789 }
else if (Tok.
is(tok::r_paren)) {
2796 <<
"full_generality";
2802 if (Arg->
isStr(
"single_inheritance")) {
2803 RepresentationMethod =
2805 }
else if (Arg->
isStr(
"multiple_inheritance")) {
2806 RepresentationMethod =
2808 }
else if (Arg->
isStr(
"virtual_inheritance")) {
2809 RepresentationMethod =
2813 diag::err_pragma_pointers_to_members_unknown_kind)
2820 if (Tok.
isNot(tok::r_paren)) {
2822 << (Arg ? Arg->
getName() :
"full_generality");
2828 if (Tok.
isNot(tok::eod)) {
2830 <<
"pointers_to_members";
2836 AnnotTok.
setKind(tok::annot_pragma_ms_pointers_to_members);
2840 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RepresentationMethod)));
2856 if (Tok.
isNot(tok::l_paren)) {
2857 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) <<
"vtordisp";
2865 if (II->
isStr(
"push")) {
2868 if (Tok.
isNot(tok::comma)) {
2869 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_punc) <<
"vtordisp";
2875 }
else if (II->
isStr(
"pop")) {
2882 if (Tok.
is(tok::r_paren)) {
2892 if (II && II->
isStr(
"off")) {
2895 }
else if (II && II->
isStr(
"on")) {
2898 }
else if (Tok.
is(tok::numeric_constant) &&
2902 << 0 << 2 <<
"vtordisp";
2913 if (Tok.
isNot(tok::r_paren)) {
2914 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) <<
"vtordisp";
2919 if (Tok.
isNot(tok::eod)) {
2928 AnnotTok.
setKind(tok::annot_pragma_ms_vtordisp);
2940 Token EoF, AnnotTok;
2944 AnnotTok.
setKind(tok::annot_pragma_ms_pragma);
2949 for (; Tok.
isNot(tok::eod); PP.
Lex(Tok)) {
2950 TokenVector.push_back(Tok);
2954 TokenVector.push_back(EoF);
2957 markAsReinjectedForRelexing(TokenVector);
2958 auto TokenArray = std::make_unique<Token[]>(TokenVector.size());
2959 std::copy(TokenVector.begin(), TokenVector.end(), TokenArray.get());
2961 std::pair<std::unique_ptr<
Token[]>,
size_t>(std::move(TokenArray),
2962 TokenVector.size());
2978void PragmaFloatControlHandler::HandlePragma(
Preprocessor &PP,
2983 Token PragmaName = Tok;
2990 if (Tok.
isNot(tok::l_paren)) {
2991 PP.
Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
2997 if (Tok.
isNot(tok::identifier)) {
3005 llvm::StringSwitch<PragmaFloatControlKind>(II->
getName())
3016 if (Tok.
isNot(tok::r_paren)) {
3023 if (Tok.
is(tok::r_paren))
3026 else if (Tok.
isNot(tok::comma)) {
3036 if (PushOnOff ==
"on")
3039 else if (PushOnOff ==
"off") {
3044 }
else if (PushOnOff ==
"push") {
3051 if (Tok.
is(tok::comma)) {
3058 if (ExpectedPush ==
"push") {
3066 if (Tok.
isNot(tok::r_paren)) {
3074 if (Tok.
isNot(tok::eod)) {
3083 auto TokenArray = std::make_unique<Token[]>(1);
3084 TokenArray[0].startToken();
3085 TokenArray[0].setKind(tok::annot_pragma_float_control);
3086 TokenArray[0].setLocation(FloatControlLoc);
3087 TokenArray[0].setAnnotationEndLoc(EndLoc);
3090 TokenArray[0].setAnnotationValue(
reinterpret_cast<void *
>(
3091 static_cast<uintptr_t>((Action << 16) | (Kind & 0xFFFF))));
3092 PP.EnterTokenStream(std::move(TokenArray), 1,
3106void PragmaDetectMismatchHandler::HandlePragma(
Preprocessor &PP,
3111 if (Tok.
isNot(tok::l_paren)) {
3112 PP.
Diag(DetectMismatchLoc, diag::err_expected) << tok::l_paren;
3117 std::string NameString;
3119 "pragma detect_mismatch",
3124 std::string ValueString;
3125 if (Tok.
isNot(tok::comma)) {
3126 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3134 if (Tok.
isNot(tok::r_paren)) {
3140 if (Tok.
isNot(tok::eod)) {
3141 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3150 Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString);
3162void PragmaCommentHandler::HandlePragma(
Preprocessor &PP,
3167 if (Tok.
isNot(tok::l_paren)) {
3168 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3174 if (Tok.
isNot(tok::identifier)) {
3175 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3182 llvm::StringSwitch<PragmaMSCommentKind>(II->
getName())
3202 std::string ArgumentString;
3215 if (Tok.
isNot(tok::r_paren)) {
3221 if (Tok.
isNot(tok::eod)) {
3230 Actions.ActOnPragmaMSComment(CommentLoc, Kind, ArgumentString);
3235void PragmaOptimizeHandler::HandlePragma(
Preprocessor &PP,
3237 Token &FirstToken) {
3240 if (Tok.
is(tok::eod)) {
3242 <<
"clang optimize" <<
true <<
"'on' or 'off'";
3245 if (Tok.
isNot(tok::identifier)) {
3246 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3253 if (II->
isStr(
"on")) {
3255 }
else if (!II->
isStr(
"off")) {
3256 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3262 if (Tok.
isNot(tok::eod)) {
3268 Actions.ActOnPragmaOptimize(IsOn, FirstToken.
getLocation());
3273struct TokFPAnnotValue {
3274 enum FlagValues { On, Off, Fast };
3276 std::optional<LangOptions::FPModeKind> ContractValue;
3277 std::optional<LangOptions::FPModeKind> ReassociateValue;
3278 std::optional<LangOptions::FPModeKind> ReciprocalValue;
3279 std::optional<LangOptions::FPExceptionModeKind> ExceptionsValue;
3280 std::optional<LangOptions::FPEvalMethodKind> EvalMethodValue;
3287 Token PragmaName = Tok;
3291 if (Tok.
isNot(tok::identifier)) {
3298 while (Tok.
is(tok::identifier)) {
3302 llvm::StringSwitch<std::optional<PragmaFPKind>>(OptionInfo->
getName())
3308 .Default(std::nullopt);
3311 <<
false << OptionInfo;
3317 if (Tok.
isNot(tok::l_paren)) {
3322 bool isEvalMethodDouble =
3326 if (Tok.
isNot(tok::identifier) && !isEvalMethodDouble) {
3329 <<
static_cast<int>(*FlagKind);
3335 AnnotValue->ContractValue =
3336 llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3341 .Default(std::nullopt);
3342 if (!AnnotValue->ContractValue) {
3349 : AnnotValue->ReciprocalValue;
3350 Value = llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3354 .Default(std::nullopt);
3361 AnnotValue->ExceptionsValue =
3362 llvm::StringSwitch<std::optional<LangOptions::FPExceptionModeKind>>(
3367 .Default(std::nullopt);
3368 if (!AnnotValue->ExceptionsValue) {
3374 AnnotValue->EvalMethodValue =
3375 llvm::StringSwitch<std::optional<LangOptions::FPEvalMethodKind>>(
3380 .Default(std::nullopt);
3381 if (!AnnotValue->EvalMethodValue) {
3390 if (Tok.
isNot(tok::r_paren)) {
3397 if (Tok.
isNot(tok::eod)) {
3405 FPTok.
setKind(tok::annot_pragma_fp);
3409 TokenList.push_back(FPTok);
3411 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3412 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3414 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3418void PragmaSTDC_FENV_ROUNDHandler::HandlePragma(
Preprocessor &PP,
3421 Token PragmaName = Tok;
3430 if (Tok.
isNot(tok::identifier)) {
3438 llvm::StringSwitch<llvm::RoundingMode>(II->
getName())
3439 .Case(
"FE_TOWARDZERO", llvm::RoundingMode::TowardZero)
3440 .Case(
"FE_TONEAREST", llvm::RoundingMode::NearestTiesToEven)
3441 .Case(
"FE_UPWARD", llvm::RoundingMode::TowardPositive)
3442 .Case(
"FE_DOWNWARD", llvm::RoundingMode::TowardNegative)
3443 .Case(
"FE_TONEARESTFROMZERO", llvm::RoundingMode::NearestTiesToAway)
3444 .Case(
"FE_DYNAMIC", llvm::RoundingMode::Dynamic)
3445 .Default(llvm::RoundingMode::Invalid);
3446 if (RM == llvm::RoundingMode::Invalid) {
3452 if (Tok.
isNot(tok::eod)) {
3454 <<
"STDC FENV_ROUND";
3463 Toks[0].startToken();
3464 Toks[0].setKind(tok::annot_pragma_fenv_round);
3467 Toks[0].setAnnotationValue(
3468 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RM)));
3469 PP.EnterTokenStream(Toks,
true,
3473void Parser::HandlePragmaFP() {
3474 assert(Tok.
is(tok::annot_pragma_fp));
3478 if (AnnotValue->ReassociateValue)
3483 if (AnnotValue->ReciprocalValue)
3488 if (AnnotValue->ContractValue)
3490 *AnnotValue->ContractValue);
3491 if (AnnotValue->ExceptionsValue)
3493 *AnnotValue->ExceptionsValue);
3494 if (AnnotValue->EvalMethodValue)
3496 *AnnotValue->EvalMethodValue);
3497 ConsumeAnnotationToken();
3502 Token Option,
bool ValueInParens,
3505 int OpenParens = ValueInParens ? 1 : 0;
3507 while (Tok.
isNot(tok::eod)) {
3508 if (Tok.
is(tok::l_paren))
3510 else if (Tok.
is(tok::r_paren)) {
3512 if (OpenParens == 0 && ValueInParens)
3520 if (ValueInParens) {
3522 if (Tok.
isNot(tok::r_paren)) {
3591void PragmaLoopHintHandler::HandlePragma(
Preprocessor &PP,
3595 Token PragmaName = Tok;
3600 if (Tok.
isNot(tok::identifier)) {
3606 while (Tok.
is(tok::identifier)) {
3610 bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->
getName())
3611 .Case(
"vectorize",
true)
3612 .Case(
"interleave",
true)
3613 .Case(
"unroll",
true)
3614 .Case(
"distribute",
true)
3615 .Case(
"vectorize_predicate",
true)
3616 .Case(
"vectorize_width",
true)
3617 .Case(
"interleave_count",
true)
3618 .Case(
"unroll_count",
true)
3619 .Case(
"pipeline",
true)
3620 .Case(
"pipeline_initiation_interval",
true)
3624 <<
false << OptionInfo;
3630 if (Tok.
isNot(tok::l_paren)) {
3644 LoopHintTok.
setKind(tok::annot_pragma_loop_hint);
3648 TokenList.push_back(LoopHintTok);
3651 if (Tok.
isNot(tok::eod)) {
3657 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3658 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3660 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3685void PragmaUnrollHintHandler::HandlePragma(
Preprocessor &PP,
3690 Token PragmaName = Tok;
3693 if (Tok.
is(tok::eod)) {
3695 Info->PragmaName = PragmaName;
3696 Info->Option.startToken();
3706 bool ValueInParens = Tok.
is(tok::l_paren);
3718 PP.
Diag(Info->Toks[0].getLocation(),
3719 diag::warn_pragma_unroll_cuda_value_in_parens);
3721 if (Tok.
isNot(tok::eod)) {
3729 auto TokenArray = std::make_unique<Token[]>(1);
3730 TokenArray[0].startToken();
3731 TokenArray[0].setKind(tok::annot_pragma_loop_hint);
3732 TokenArray[0].setLocation(Introducer.
Loc);
3733 TokenArray[0].setAnnotationEndLoc(PragmaName.
getLocation());
3734 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
3735 PP.EnterTokenStream(std::move(TokenArray), 1,
3751void PragmaMSIntrinsicHandler::HandlePragma(
Preprocessor &PP,
3756 if (Tok.
isNot(tok::l_paren)) {
3765 while (Tok.
is(tok::identifier)) {
3769 << II << SuggestIntrinH;
3772 if (Tok.
isNot(tok::comma))
3777 if (Tok.
isNot(tok::r_paren)) {
3784 if (Tok.
isNot(tok::eod))
3789bool Parser::HandlePragmaMSFunction(StringRef PragmaName,
3791 Token FirstTok = Tok;
3793 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3800 while (Tok.
is(tok::identifier)) {
3804 << II << SuggestIntrinH;
3806 NoBuiltins.emplace_back(II->
getName());
3809 if (Tok.
isNot(tok::comma))
3814 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3816 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3825bool Parser::HandlePragmaMSOptimize(StringRef PragmaName,
3827 Token FirstTok = Tok;
3828 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3832 if (Tok.
isNot(tok::string_literal)) {
3833 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_string) << PragmaName;
3841 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
3846 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
3850 if (Tok.
is(tok::eof) || Tok.
is(tok::r_paren)) {
3851 PP.
Diag(PragmaLocation, diag::warn_pragma_missing_argument)
3852 << PragmaName <<
true <<
"'on' or 'off'";
3856 if (!II || (!II->
isStr(
"on") && !II->
isStr(
"off"))) {
3857 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3862 bool IsOn = II->
isStr(
"on");
3865 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3870 if (!OptimizationList->
getString().empty()) {
3871 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3872 << OptimizationList->
getString() << PragmaName <<
true
3877 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3885void PragmaForceCUDAHostDeviceHandler::HandlePragma(
3887 Token FirstTok = Tok;
3891 if (!Info || (!Info->
isStr(
"begin") && !Info->
isStr(
"end"))) {
3893 diag::warn_pragma_force_cuda_host_device_bad_arg);
3897 if (Info->
isStr(
"begin"))
3898 Actions.PushForceCUDAHostDevice();
3899 else if (!Actions.PopForceCUDAHostDevice())
3901 diag::err_pragma_cannot_end_force_cuda_host_device);
3904 if (!Tok.
is(tok::eod))
3906 diag::warn_pragma_force_cuda_host_device_bad_arg);
3936void PragmaAttributeHandler::HandlePragma(
Preprocessor &PP,
3938 Token &FirstToken) {
3942 PragmaAttributeInfo(AttributesForPragmaAttribute);
3945 if (Tok.
is(tok::identifier)) {
3947 if (!II->
isStr(
"push") && !II->
isStr(
"pop")) {
3948 Info->Namespace = II;
3951 if (!Tok.
is(tok::period)) {
3952 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_period)
3960 if (!Tok.
isOneOf(tok::identifier, tok::l_paren)) {
3962 diag::err_pragma_attribute_expected_push_pop_paren);
3967 if (Tok.
is(tok::l_paren)) {
3968 if (Info->Namespace) {
3970 diag::err_pragma_attribute_namespace_on_attribute);
3972 diag::note_pragma_attribute_namespace_on_attribute);
3975 Info->Action = PragmaAttributeInfo::Attribute;
3978 if (II->
isStr(
"push"))
3979 Info->Action = PragmaAttributeInfo::Push;
3981 Info->Action = PragmaAttributeInfo::Pop;
3983 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_invalid_argument)
3992 if ((Info->Action == PragmaAttributeInfo::Push && Tok.
isNot(tok::eod)) ||
3993 Info->Action == PragmaAttributeInfo::Attribute) {
3994 if (Tok.
isNot(tok::l_paren)) {
4003 while (Tok.
isNot(tok::eod)) {
4004 if (Tok.
is(tok::l_paren))
4006 else if (Tok.
is(tok::r_paren)) {
4008 if (OpenParens == 0)
4012 AttributeTokens.push_back(Tok);
4016 if (AttributeTokens.empty()) {
4017 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_attribute);
4020 if (Tok.
isNot(tok::r_paren)) {
4032 AttributeTokens.push_back(EOFTok);
4034 markAsReinjectedForRelexing(AttributeTokens);
4039 if (Tok.
isNot(tok::eod))
4041 <<
"clang attribute";
4044 auto TokenArray = std::make_unique<Token[]>(1);
4045 TokenArray[0].startToken();
4046 TokenArray[0].setKind(tok::annot_pragma_attribute);
4047 TokenArray[0].setLocation(FirstToken.
getLocation());
4048 TokenArray[0].setAnnotationEndLoc(FirstToken.
getLocation());
4049 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
4050 PP.EnterTokenStream(std::move(TokenArray), 1,
4055void PragmaMaxTokensHereHandler::HandlePragma(
Preprocessor &PP,
4059 if (Tok.
is(tok::eod)) {
4061 <<
"clang max_tokens_here" <<
true <<
"integer";
4067 if (Tok.
isNot(tok::numeric_constant) ||
4070 <<
"clang max_tokens_here";
4074 if (Tok.
isNot(tok::eod)) {
4076 <<
"clang max_tokens_here";
4081 PP.
Diag(Loc, diag::warn_max_tokens)
4087void PragmaMaxTokensTotalHandler::HandlePragma(
Preprocessor &PP,
4091 if (Tok.
is(tok::eod)) {
4093 <<
"clang max_tokens_total" <<
true <<
"integer";
4099 if (Tok.
isNot(tok::numeric_constant) ||
4102 <<
"clang max_tokens_total";
4106 if (Tok.
isNot(tok::eod)) {
4108 <<
"clang max_tokens_total";
4119 Token &FirstToken) {
4124 if (!II || !II->
isStr(
"intrinsic")) {
4126 << PP.
getSpelling(Tok) <<
"riscv" <<
true <<
"'intrinsic'";
4132 if (!II || !(II->
isStr(
"vector") || II->
isStr(
"sifive_vector"))) {
4135 <<
"'vector' or 'sifive_vector'";
4140 if (Tok.
isNot(tok::eod)) {
4142 <<
"clang riscv intrinsic";
4146 if (II->
isStr(
"vector"))
4147 Actions.DeclareRISCVVBuiltins =
true;
4148 else if (II->
isStr(
"sifive_vector"))
4149 Actions.DeclareRISCVSiFiveVectorBuiltins =
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
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) ...
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, e.g.
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.
@ 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.
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.
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, IdentifierInfo *scopeName, SourceLocation scopeLoc, 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 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
SourceLocation getEndOfPreviousToken()
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(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral=false)
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.
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 ...
SourceRange DiscardUntilEndOfDirective()
Read and discard all tokens remaining on the current line until the tok::eod token is found.
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.
Sema - This implements semantic analysis and AST building for C.
void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn)
#pragma optimize("[optimization-list]", on | off).
void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
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().
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().
void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, CapturedRegionKind Kind, unsigned NumParams)
void ActOnPragmaWeakID(IdentifierInfo *WeakName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc)
ActOnPragmaWeakID - Called on well formed #pragma weak ident.
void CodeCompleteAttribute(AttributeCommonInfo::Syntax Syntax, AttributeCompletion Completion=AttributeCompletion::Attribute, const IdentifierInfo *Scope=nullptr)
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....
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc)
@ 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.
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,...
void setLocation(SourceLocation L)
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
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)
@ Ignored
Do not present this diagnostic, ignore it.
@ FixIt
Parse and apply any fixits to the source.
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.
MSVtorDispMode
In the Microsoft ABI, this controls the placement of virtual displacement members used to implement v...
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
@ 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...
static IdentifierLoc * create(ASTContext &Ctx, SourceLocation Loc, IdentifierInfo *Ident)
Loop optimization hint for loop and unroll pragmas.
IdentifierLoc * OptionLoc
IdentifierLoc * PragmaNameLoc
Describes how and where the pragma was introduced.
PragmaMsStackAction Action