25#include "llvm/ADT/ArrayRef.h"
26#include "llvm/ADT/StringSwitch.h"
35 Token &FirstToken)
override;
39 explicit PragmaGCCVisibilityHandler() :
PragmaHandler(
"visibility") {}
41 Token &FirstToken)
override;
47 Token &FirstToken)
override;
53 Token &FirstToken)
override;
57 explicit PragmaClangSectionHandler(
Sema &S)
60 Token &FirstToken)
override;
67 explicit PragmaMSStructHandler() :
PragmaHandler(
"ms_struct") {}
69 Token &FirstToken)
override;
75 Token &FirstToken)
override;
81 Token &FirstToken)
override;
85 explicit PragmaRedefineExtnameHandler() :
PragmaHandler(
"redefine_extname") {}
87 Token &FirstToken)
override;
91 PragmaOpenCLExtensionHandler() :
PragmaHandler(
"EXTENSION") {}
93 Token &FirstToken)
override;
100 Token &FirstToken)
override;
107 PragmaSTDC_FENV_ACCESSHandler() :
PragmaHandler(
"FENV_ACCESS") {}
110 Token &Tok)
override {
111 Token PragmaName = Tok;
123 Toks[0].startToken();
124 Toks[0].setKind(tok::annot_pragma_fenv_access);
127 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
129 PP.EnterTokenStream(Toks,
true,
135struct PragmaSTDC_CX_LIMITED_RANGEHandler :
public PragmaHandler {
136 PragmaSTDC_CX_LIMITED_RANGEHandler() :
PragmaHandler(
"CX_LIMITED_RANGE") {}
139 Token &Tok)
override {
147 Toks[0].startToken();
148 Toks[0].setKind(tok::annot_pragma_cx_limited_range);
151 Toks[0].setAnnotationValue(
152 reinterpret_cast<void *
>(
static_cast<uintptr_t>(OOS)));
153 PP.EnterTokenStream(Toks,
true,
160 PragmaSTDC_FENV_ROUNDHandler() :
PragmaHandler(
"FENV_ROUND") {}
163 Token &Tok)
override;
168 PragmaSTDC_UnknownHandler() =
default;
171 Token &UnknownTok)
override {
173 PP.
Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
180 Token &FirstToken)
override;
186template <diag::kind IgnoredDiag>
188 PragmaNoSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
190 Token &FirstToken)
override;
193struct PragmaNoOpenMPHandler
194 :
public PragmaNoSupportHandler<diag::warn_pragma_omp_ignored> {
195 PragmaNoOpenMPHandler() : PragmaNoSupportHandler(
"omp") {}
198struct PragmaNoOpenACCHandler
199 :
public PragmaNoSupportHandler<diag::warn_pragma_acc_ignored> {
200 PragmaNoOpenACCHandler() : PragmaNoSupportHandler(
"acc") {}
209 PragmaSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
211 Token &FirstToken)
override;
214struct PragmaOpenMPHandler
215 :
public PragmaSupportHandler<tok::annot_pragma_openmp,
216 tok::annot_pragma_openmp_end,
217 diag::err_omp_unexpected_directive> {
218 PragmaOpenMPHandler() : PragmaSupportHandler(
"omp") {}
221struct PragmaOpenACCHandler
222 :
public PragmaSupportHandler<tok::annot_pragma_openacc,
223 tok::annot_pragma_openacc_end,
224 diag::err_acc_unexpected_directive> {
225 PragmaOpenACCHandler() : PragmaSupportHandler(
"acc") {}
230 PragmaCommentHandler(
Sema &Actions)
233 Token &FirstToken)
override;
240 PragmaDetectMismatchHandler(
Sema &Actions)
243 Token &FirstToken)
override;
250 PragmaFloatControlHandler(
Sema &Actions)
253 Token &FirstToken)
override;
257 explicit PragmaMSPointersToMembers() :
PragmaHandler(
"pointers_to_members") {}
259 Token &FirstToken)
override;
265 Token &FirstToken)
override;
271 Token &FirstToken)
override;
276 PragmaOptimizeHandler(
Sema &S)
279 Token &FirstToken)
override;
288 Token &FirstToken)
override;
294 Token &FirstToken)
override;
304 Token &FirstToken)
override;
309 PragmaMSFenvAccessHandler() :
PragmaHandler(
"fenv_access") {}
311 Token &FirstToken)
override {
321 if (Tok.
isNot(tok::l_paren)) {
327 if (Tok.
isNot(tok::identifier)) {
333 if (II->
isStr(
"on")) {
336 }
else if (II->
isStr(
"off")) {
343 if (Tok.
isNot(tok::r_paren)) {
350 if (Tok.
isNot(tok::eod)) {
358 Toks[0].startToken();
359 Toks[0].setKind(tok::annot_pragma_fenv_access_ms);
362 Toks[0].setAnnotationValue(
363 reinterpret_cast<void*
>(
static_cast<uintptr_t>(OOS)));
364 PP.EnterTokenStream(Toks,
true,
369struct PragmaForceCUDAHostDeviceHandler :
public PragmaHandler {
370 PragmaForceCUDAHostDeviceHandler(
Sema &Actions)
371 :
PragmaHandler(
"force_cuda_host_device"), Actions(Actions) {}
373 Token &FirstToken)
override;
382 :
PragmaHandler(
"attribute"), AttributesForPragmaAttribute(AttrFactory) {}
384 Token &FirstToken)
override;
391 PragmaMaxTokensHereHandler() :
PragmaHandler(
"max_tokens_here") {}
393 Token &FirstToken)
override;
397 PragmaMaxTokensTotalHandler() :
PragmaHandler(
"max_tokens_total") {}
399 Token &FirstToken)
override;
403 PragmaRISCVHandler(
Sema &Actions)
406 Token &FirstToken)
override;
418void Parser::initializePragmaHandlers() {
419 AlignHandler = std::make_unique<PragmaAlignHandler>();
422 GCCVisibilityHandler = std::make_unique<PragmaGCCVisibilityHandler>();
425 OptionsHandler = std::make_unique<PragmaOptionsHandler>();
428 PackHandler = std::make_unique<PragmaPackHandler>();
431 MSStructHandler = std::make_unique<PragmaMSStructHandler>();
434 UnusedHandler = std::make_unique<PragmaUnusedHandler>();
437 WeakHandler = std::make_unique<PragmaWeakHandler>();
440 RedefineExtnameHandler = std::make_unique<PragmaRedefineExtnameHandler>();
443 FPContractHandler = std::make_unique<PragmaFPContractHandler>();
446 STDCFenvAccessHandler = std::make_unique<PragmaSTDC_FENV_ACCESSHandler>();
449 STDCFenvRoundHandler = std::make_unique<PragmaSTDC_FENV_ROUNDHandler>();
452 STDCCXLIMITHandler = std::make_unique<PragmaSTDC_CX_LIMITED_RANGEHandler>();
455 STDCUnknownHandler = std::make_unique<PragmaSTDC_UnknownHandler>();
458 PCSectionHandler = std::make_unique<PragmaClangSectionHandler>(Actions);
462 OpenCLExtensionHandler = std::make_unique<PragmaOpenCLExtensionHandler>();
468 OpenMPHandler = std::make_unique<PragmaOpenMPHandler>();
470 OpenMPHandler = std::make_unique<PragmaNoOpenMPHandler>();
474 OpenACCHandler = std::make_unique<PragmaOpenACCHandler>();
476 OpenACCHandler = std::make_unique<PragmaNoOpenACCHandler>();
481 MSCommentHandler = std::make_unique<PragmaCommentHandler>(Actions);
485 FloatControlHandler = std::make_unique<PragmaFloatControlHandler>(Actions);
488 MSDetectMismatchHandler =
489 std::make_unique<PragmaDetectMismatchHandler>(Actions);
491 MSPointersToMembers = std::make_unique<PragmaMSPointersToMembers>();
493 MSVtorDisp = std::make_unique<PragmaMSVtorDisp>();
495 MSInitSeg = std::make_unique<PragmaMSPragma>(
"init_seg");
497 MSDataSeg = std::make_unique<PragmaMSPragma>(
"data_seg");
499 MSBSSSeg = std::make_unique<PragmaMSPragma>(
"bss_seg");
501 MSConstSeg = std::make_unique<PragmaMSPragma>(
"const_seg");
503 MSCodeSeg = std::make_unique<PragmaMSPragma>(
"code_seg");
505 MSSection = std::make_unique<PragmaMSPragma>(
"section");
507 MSStrictGuardStackCheck =
508 std::make_unique<PragmaMSPragma>(
"strict_gs_check");
510 MSFunction = std::make_unique<PragmaMSPragma>(
"function");
512 MSAllocText = std::make_unique<PragmaMSPragma>(
"alloc_text");
514 MSOptimize = std::make_unique<PragmaMSPragma>(
"optimize");
516 MSRuntimeChecks = std::make_unique<PragmaMSRuntimeChecksHandler>();
518 MSIntrinsic = std::make_unique<PragmaMSIntrinsicHandler>();
520 MSFenvAccess = std::make_unique<PragmaMSFenvAccessHandler>();
525 CUDAForceHostDeviceHandler =
526 std::make_unique<PragmaForceCUDAHostDeviceHandler>(Actions);
530 OptimizeHandler = std::make_unique<PragmaOptimizeHandler>(Actions);
533 LoopHintHandler = std::make_unique<PragmaLoopHintHandler>();
536 UnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"unroll");
540 NoUnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"nounroll");
544 UnrollAndJamHintHandler =
545 std::make_unique<PragmaUnrollHintHandler>(
"unroll_and_jam");
548 NoUnrollAndJamHintHandler =
549 std::make_unique<PragmaUnrollHintHandler>(
"nounroll_and_jam");
552 FPHandler = std::make_unique<PragmaFPHandler>();
555 AttributePragmaHandler =
556 std::make_unique<PragmaAttributeHandler>(AttrFactory);
559 MaxTokensHerePragmaHandler = std::make_unique<PragmaMaxTokensHereHandler>();
562 MaxTokensTotalPragmaHandler = std::make_unique<PragmaMaxTokensTotalHandler>();
566 RISCVPragmaHandler = std::make_unique<PragmaRISCVHandler>(Actions);
571void Parser::resetPragmaHandlers() {
574 AlignHandler.reset();
576 GCCVisibilityHandler.reset();
578 OptionsHandler.reset();
582 MSStructHandler.reset();
584 UnusedHandler.reset();
588 RedefineExtnameHandler.reset();
592 OpenCLExtensionHandler.reset();
596 OpenMPHandler.reset();
599 OpenACCHandler.reset();
604 MSCommentHandler.reset();
608 PCSectionHandler.reset();
611 FloatControlHandler.reset();
614 MSDetectMismatchHandler.reset();
616 MSPointersToMembers.reset();
632 MSStrictGuardStackCheck.reset();
638 MSRuntimeChecks.reset();
644 MSFenvAccess.reset();
649 CUDAForceHostDeviceHandler.reset();
653 FPContractHandler.reset();
656 STDCFenvAccessHandler.reset();
659 STDCFenvRoundHandler.reset();
662 STDCCXLIMITHandler.reset();
665 STDCUnknownHandler.reset();
668 OptimizeHandler.reset();
671 LoopHintHandler.reset();
675 UnrollHintHandler.reset();
679 NoUnrollHintHandler.reset();
682 UnrollAndJamHintHandler.reset();
685 NoUnrollAndJamHintHandler.reset();
691 AttributePragmaHandler.reset();
694 MaxTokensHerePragmaHandler.reset();
697 MaxTokensTotalPragmaHandler.reset();
701 RISCVPragmaHandler.reset();
710void Parser::HandlePragmaUnused() {
711 assert(Tok.
is(tok::annot_pragma_unused));
717void Parser::HandlePragmaVisibility() {
718 assert(Tok.
is(tok::annot_pragma_vis));
725void Parser::HandlePragmaPack() {
726 assert(Tok.
is(tok::annot_pragma_pack));
734 ConsumeAnnotationToken();
742 ConsumeAnnotationToken();
745void Parser::HandlePragmaMSStruct() {
746 assert(Tok.
is(tok::annot_pragma_msstruct));
750 ConsumeAnnotationToken();
753void Parser::HandlePragmaAlign() {
754 assert(Tok.
is(tok::annot_pragma_align));
761 ConsumeAnnotationToken();
764void Parser::HandlePragmaDump() {
765 assert(Tok.
is(tok::annot_pragma_dump));
766 ConsumeAnnotationToken();
767 if (Tok.
is(tok::eod)) {
768 PP.
Diag(Tok, diag::warn_pragma_debug_missing_argument) <<
"dump";
770 if (Tok.
isNot(tok::identifier)) {
771 PP.
Diag(Tok, diag::warn_pragma_debug_unexpected_argument);
773 ExpectAndConsume(tok::eod);
787 PP.
Diag(StartLoc, diag::warn_pragma_debug_dependent_argument)
795 ExpectAndConsume(tok::eod);
798void Parser::HandlePragmaWeak() {
799 assert(Tok.
is(tok::annot_pragma_weak));
806void Parser::HandlePragmaWeakAlias() {
807 assert(Tok.
is(tok::annot_pragma_weakalias));
816 WeakNameLoc, AliasNameLoc);
820void Parser::HandlePragmaRedefineExtname() {
821 assert(Tok.
is(tok::annot_pragma_redefine_extname));
830 RedefNameLoc, AliasNameLoc);
833void Parser::HandlePragmaFPContract() {
834 assert(Tok.
is(tok::annot_pragma_fp_contract));
861void Parser::HandlePragmaFloatControl() {
862 assert(Tok.
is(tok::annot_pragma_float_control));
877void Parser::HandlePragmaFEnvAccess() {
878 assert(Tok.
is(tok::annot_pragma_fenv_access) ||
879 Tok.
is(tok::annot_pragma_fenv_access_ms));
901void Parser::HandlePragmaFEnvRound() {
902 assert(Tok.
is(tok::annot_pragma_fenv_round));
903 auto RM =
static_cast<llvm::RoundingMode
>(
910void Parser::HandlePragmaCXLimitedRange() {
911 assert(Tok.
is(tok::annot_pragma_cx_limited_range));
937 assert(Tok.
is(tok::annot_pragma_captured));
938 ConsumeAnnotationToken();
940 if (Tok.
isNot(tok::l_brace)) {
941 PP.
Diag(Tok, diag::err_expected) << tok::l_brace;
953 CapturedRegionScope.Exit();
964 enum OpenCLExtState :
char {
965 Disable, Enable,
Begin, End
967 typedef std::pair<const IdentifierInfo *, OpenCLExtState> OpenCLExtData;
970void Parser::HandlePragmaOpenCLExtension() {
971 assert(Tok.
is(tok::annot_pragma_opencl_extension));
973 auto State =
Data->second;
974 auto Ident =
Data->first;
976 ConsumeAnnotationToken();
979 auto Name = Ident->getName();
984 if (State == Disable)
987 PP.
Diag(NameLoc, diag::warn_pragma_expected_predicate) << 1;
988 }
else if (State ==
Begin) {
989 if (!Opt.isKnown(Name) || !Opt.isSupported(Name,
getLangOpts())) {
993 Opt.acceptsPragma(Name);
995 }
else if (State == End) {
998 }
else if (!Opt.isKnown(Name) || !Opt.isWithPragma(Name))
999 PP.
Diag(NameLoc, diag::warn_pragma_unknown_extension) << Ident;
1000 else if (Opt.isSupportedExtension(Name,
getLangOpts()))
1001 Opt.enable(Name, State == Enable);
1002 else if (Opt.isSupportedCoreOrOptionalCore(Name,
getLangOpts()))
1003 PP.
Diag(NameLoc, diag::warn_pragma_extension_is_core) << Ident;
1005 PP.
Diag(NameLoc, diag::warn_pragma_unsupported_extension) << Ident;
1008void Parser::HandlePragmaMSPointersToMembers() {
1009 assert(Tok.
is(tok::annot_pragma_ms_pointers_to_members));
1017void Parser::HandlePragmaMSVtorDisp() {
1018 assert(Tok.
is(tok::annot_pragma_ms_vtordisp));
1027void Parser::HandlePragmaMSPragma() {
1028 assert(Tok.
is(tok::annot_pragma_ms_pragma));
1032 PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second,
true,
1043 llvm::StringSwitch<PragmaHandler>(PragmaName)
1044 .Case(
"data_seg", &Parser::HandlePragmaMSSegment)
1045 .Case(
"bss_seg", &Parser::HandlePragmaMSSegment)
1046 .Case(
"const_seg", &Parser::HandlePragmaMSSegment)
1047 .Case(
"code_seg", &Parser::HandlePragmaMSSegment)
1048 .Case(
"section", &Parser::HandlePragmaMSSection)
1049 .Case(
"init_seg", &Parser::HandlePragmaMSInitSeg)
1050 .Case(
"strict_gs_check", &Parser::HandlePragmaMSStrictGuardStackCheck)
1051 .Case(
"function", &Parser::HandlePragmaMSFunction)
1052 .Case(
"alloc_text", &Parser::HandlePragmaMSAllocText)
1053 .Case(
"optimize", &Parser::HandlePragmaMSOptimize);
1055 if (!(this->*Handler)(PragmaName, PragmaLocation)) {
1058 while (Tok.
isNot(tok::eof))
1064bool Parser::HandlePragmaMSSection(StringRef PragmaName,
1066 if (Tok.
isNot(tok::l_paren)) {
1067 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1072 if (Tok.
isNot(tok::string_literal)) {
1073 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1082 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1087 bool SectionFlagsAreDefault =
true;
1088 while (Tok.
is(tok::comma)) {
1093 if (Tok.
is(tok::kw_long) || Tok.
is(tok::kw_short)) {
1099 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren)
1104 llvm::StringSwitch<ASTContext::PragmaSectionFlag>(
1117 ? diag::warn_pragma_invalid_specific_action
1118 : diag::warn_pragma_unsupported_action)
1122 SectionFlags |= Flag;
1123 SectionFlagsAreDefault =
false;
1128 if (SectionFlagsAreDefault)
1130 if (Tok.
isNot(tok::r_paren)) {
1131 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1135 if (Tok.
isNot(tok::eof)) {
1136 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1145bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
1147 if (Tok.
isNot(tok::l_paren)) {
1148 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1153 StringRef SlotLabel;
1156 if (PushPop ==
"push")
1158 else if (PushPop ==
"pop")
1161 PP.
Diag(PragmaLocation,
1162 diag::warn_pragma_expected_section_push_pop_or_name)
1168 if (Tok.
is(tok::comma)) {
1174 if (Tok.
is(tok::comma))
1176 else if (Tok.
isNot(tok::r_paren)) {
1177 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc)
1182 }
else if (Tok.
isNot(tok::r_paren)) {
1183 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc) << PragmaName;
1190 if (Tok.
isNot(tok::r_paren)) {
1191 if (Tok.
isNot(tok::string_literal)) {
1193 diag::warn_pragma_expected_section_name :
1194 diag::warn_pragma_expected_section_label_or_name :
1195 diag::warn_pragma_expected_section_push_pop_or_name;
1196 PP.
Diag(PragmaLocation, DiagID) << PragmaName;
1202 SegmentName = cast<StringLiteral>(StringResult.
get());
1204 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1212 if (Tok.
isNot(tok::r_paren)) {
1213 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1217 if (Tok.
isNot(tok::eof)) {
1218 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1224 SegmentName, PragmaName);
1229bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
1231 if (
getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) {
1232 PP.
Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target);
1236 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1244 StringRef Section = llvm::StringSwitch<StringRef>(II->
getName())
1245 .Case(
"compiler",
"\".CRT$XCC\"")
1246 .Case(
"lib",
"\".CRT$XCL\"")
1247 .Case(
"user",
"\".CRT$XCU\"")
1250 if (!Section.empty()) {
1254 Toks[0].
setKind(tok::string_literal);
1262 }
else if (Tok.
is(tok::string_literal)) {
1266 SegmentName = cast<StringLiteral>(StringResult.
get());
1268 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1276 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName;
1280 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1282 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1293bool Parser::HandlePragmaMSStrictGuardStackCheck(
1295 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1300 if (Tok.
is(tok::identifier)) {
1302 if (PushPop ==
"push") {
1305 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_punc,
1308 }
else if (PushPop ==
"pop") {
1317 if (II && II->
isStr(
"off")) {
1320 }
else if (II && II->
isStr(
"on")) {
1331 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1335 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1343bool Parser::HandlePragmaMSAllocText(StringRef PragmaName,
1345 Token FirstTok = Tok;
1346 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1351 if (Tok.
is(tok::string_literal)) {
1357 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1362 }
else if (Tok.
is(tok::identifier)) {
1366 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1371 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
1377 if (Tok.
isNot(tok::identifier)) {
1387 if (Tok.
isNot(tok::comma))
1392 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1394 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1404 std::string ClangLoopStr(
"clang loop ");
1407 return std::string(llvm::StringSwitch<StringRef>(Str)
1408 .Case(
"loop", ClangLoopStr)
1409 .Case(
"unroll_and_jam", Str)
1410 .Case(
"unroll", Str)
1414bool Parser::HandlePragmaLoopHint(
LoopHint &Hint) {
1415 assert(Tok.
is(tok::annot_pragma_loop_hint));
1435 auto IsLoopHint = llvm::StringSwitch<bool>(PragmaNameInfo->
getName())
1436 .Cases(
"unroll",
"nounroll",
"unroll_and_jam",
1437 "nounroll_and_jam",
true)
1440 if (Toks.empty() && IsLoopHint) {
1441 ConsumeAnnotationToken();
1448 assert(!Toks.empty() &&
1449 "PragmaLoopHintInfo::Toks must contain at least one token.");
1452 bool OptionUnroll =
false;
1453 bool OptionUnrollAndJam =
false;
1454 bool OptionDistribute =
false;
1455 bool OptionPipelineDisabled =
false;
1456 bool StateOption =
false;
1458 OptionUnroll = OptionInfo->
isStr(
"unroll");
1459 OptionUnrollAndJam = OptionInfo->
isStr(
"unroll_and_jam");
1460 OptionDistribute = OptionInfo->
isStr(
"distribute");
1461 OptionPipelineDisabled = OptionInfo->
isStr(
"pipeline");
1462 StateOption = llvm::StringSwitch<bool>(OptionInfo->
getName())
1463 .Case(
"vectorize",
true)
1464 .Case(
"interleave",
true)
1465 .Case(
"vectorize_predicate",
true)
1467 OptionUnroll || OptionUnrollAndJam || OptionDistribute ||
1468 OptionPipelineDisabled;
1471 bool AssumeSafetyArg = !OptionUnroll && !OptionUnrollAndJam &&
1472 !OptionDistribute && !OptionPipelineDisabled;
1474 if (Toks[0].is(tok::eof)) {
1475 ConsumeAnnotationToken();
1476 Diag(Toks[0].getLocation(), diag::err_pragma_loop_missing_argument)
1478 << (OptionUnroll || OptionUnrollAndJam)
1485 ConsumeAnnotationToken();
1489 bool Valid = StateInfo &&
1490 llvm::StringSwitch<bool>(StateInfo->
getName())
1491 .Case(
"disable",
true)
1492 .Case(
"enable", !OptionPipelineDisabled)
1493 .Case(
"full", OptionUnroll || OptionUnrollAndJam)
1494 .Case(
"assume_safety", AssumeSafetyArg)
1497 if (OptionPipelineDisabled) {
1498 Diag(Toks[0].getLocation(), diag::err_pragma_pipeline_invalid_keyword);
1500 Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword)
1501 << (OptionUnroll || OptionUnrollAndJam)
1506 if (Toks.size() > 2)
1510 }
else if (OptionInfo && OptionInfo->
getName() ==
"vectorize_width") {
1511 PP.EnterTokenStream(Toks,
false,
1513 ConsumeAnnotationToken();
1517 StringRef IsScalableStr = StateInfo ? StateInfo->
getName() :
"";
1520 if (IsScalableStr ==
"scalable" || IsScalableStr ==
"fixed") {
1523 if (Toks.size() > 2) {
1526 while (Tok.
isNot(tok::eof))
1539 Diag(Toks[0].getLocation(),
1540 diag::note_pragma_loop_invalid_vectorize_option);
1542 bool Arg2Error =
false;
1543 if (Tok.
is(tok::comma)) {
1547 IsScalableStr = StateInfo->
getName();
1549 if (IsScalableStr !=
"scalable" && IsScalableStr !=
"fixed") {
1551 diag::err_pragma_loop_invalid_vectorize_option);
1562 if (Tok.
isNot(tok::eof)) {
1565 while (Tok.
isNot(tok::eof))
1581 PP.EnterTokenStream(Toks,
false,
1583 ConsumeAnnotationToken();
1588 if (Tok.
isNot(tok::eof)) {
1591 while (Tok.
isNot(tok::eof))
1607 Info->
Toks.back().getLocation());
1612struct PragmaAttributeInfo {
1613 enum ActionType { Push,
Pop, Attribute };
1619 PragmaAttributeInfo(
ParsedAttributes &Attributes) : Attributes(Attributes) {}
1622#include "clang/Parse/AttrSubMatchRulesParserStringSwitches.inc"
1627 if (Tok.
is(tok::identifier))
1636 using namespace attr;
1638#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract) \
1641#include "clang/Basic/AttrSubMatchRulesList.inc"
1643 llvm_unreachable(
"Invalid attribute subject match rule");
1651 PRef.
Diag(SubRuleLoc,
1652 diag::err_pragma_attribute_expected_subject_sub_identifier)
1654 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1665 PRef.
Diag(SubRuleLoc, diag::err_pragma_attribute_unknown_subject_sub_rule)
1666 << SubRuleName << PrimaryRuleName;
1667 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1673bool Parser::ParsePragmaAttributeSubjectMatchRuleSet(
1681 if (AnyParens.expectAndConsume())
1689 Diag(Tok, diag::err_pragma_attribute_expected_subject_identifier);
1692 std::pair<std::optional<attr::SubjectMatchRule>,
1693 std::optional<attr::SubjectMatchRule> (*)(StringRef,
bool)>
1694 Rule = isAttributeSubjectMatchRule(Name);
1696 Diag(Tok, diag::err_pragma_attribute_unknown_subject_rule) << Name;
1704 if (
Parens.expectAndConsume())
1706 }
else if (
Parens.consumeOpen()) {
1707 if (!SubjectMatchRules
1709 std::make_pair(PrimaryRule,
SourceRange(RuleLoc, RuleLoc)))
1711 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1714 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleLoc));
1715 LastMatchRuleEndLoc = RuleLoc;
1721 if (SubRuleName.empty()) {
1727 if (SubRuleName ==
"unless") {
1730 if (
Parens.expectAndConsume())
1733 if (SubRuleName.empty()) {
1738 auto SubRuleOrNone = Rule.second(SubRuleName,
true);
1739 if (!SubRuleOrNone) {
1740 std::string SubRuleUnlessName =
"unless(" + SubRuleName.str() +
")";
1742 SubRuleUnlessName, SubRuleLoc);
1745 SubRule = *SubRuleOrNone;
1747 if (
Parens.consumeClose())
1750 auto SubRuleOrNone = Rule.second(SubRuleName,
false);
1751 if (!SubRuleOrNone) {
1756 SubRule = *SubRuleOrNone;
1760 LastMatchRuleEndLoc = RuleEndLoc;
1761 if (
Parens.consumeClose())
1763 if (!SubjectMatchRules
1764 .insert(std::make_pair(SubRule,
SourceRange(RuleLoc, RuleEndLoc)))
1766 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1769 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleEndLoc));
1775 if (AnyParens.consumeClose())
1784enum class MissingAttributeSubjectRulesRecoveryPoint {
1792MissingAttributeSubjectRulesRecoveryPoint
1793getAttributeSubjectRulesRecoveryPointForToken(
const Token &Tok) {
1795 if (II->
isStr(
"apply_to"))
1796 return MissingAttributeSubjectRulesRecoveryPoint::ApplyTo;
1797 if (II->
isStr(
"any"))
1798 return MissingAttributeSubjectRulesRecoveryPoint::Any;
1800 if (Tok.
is(tok::equal))
1801 return MissingAttributeSubjectRulesRecoveryPoint::Equals;
1802 return MissingAttributeSubjectRulesRecoveryPoint::None;
1810 MissingAttributeSubjectRulesRecoveryPoint Point,
Parser &PRef) {
1816 MissingAttributeSubjectRulesRecoveryPoint EndPoint =
1817 getAttributeSubjectRulesRecoveryPointForToken(PRef.
getCurToken());
1818 if (Point == MissingAttributeSubjectRulesRecoveryPoint::Comma)
1820 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::ApplyTo &&
1821 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::ApplyTo)
1822 FixIt +=
"apply_to";
1823 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::Equals &&
1824 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::Equals)
1827 if (EndPoint == MissingAttributeSubjectRulesRecoveryPoint::None) {
1834 Attribute.getMatchRules(PRef.
getLangOpts(), MatchRules);
1836 for (
const auto &Rule : MatchRules) {
1841 IsSupported[Rule.first] =
true;
1843 IsMatchRuleAvailable &= IsSupported;
1845 if (IsMatchRuleAvailable.count() == 0) {
1851 bool NeedsComma =
false;
1853 if (!IsMatchRuleAvailable[I])
1867 if (FixItRange.getBegin() == FixItRange.getEnd())
1877void Parser::HandlePragmaAttribute() {
1878 assert(Tok.
is(tok::annot_pragma_attribute) &&
1879 "Expected #pragma attribute annotation token");
1882 if (Info->Action == PragmaAttributeInfo::Pop) {
1883 ConsumeAnnotationToken();
1888 assert((Info->Action == PragmaAttributeInfo::Push ||
1889 Info->Action == PragmaAttributeInfo::Attribute) &&
1890 "Unexpected #pragma attribute command");
1892 if (Info->Action == PragmaAttributeInfo::Push && Info->Tokens.empty()) {
1893 ConsumeAnnotationToken();
1898 PP.EnterTokenStream(Info->Tokens,
false,
1900 ConsumeAnnotationToken();
1905 auto SkipToEnd = [
this]() {
1910 if ((Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) ||
1913 ParseCXX11AttributeSpecifier(Attrs);
1914 }
else if (Tok.
is(tok::kw___attribute)) {
1916 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
1919 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"("))
1924 if (Tok.
is(tok::code_completion)) {
1933 if (Tok.
isNot(tok::identifier)) {
1934 Diag(Tok, diag::err_pragma_attribute_expected_attribute_name);
1941 if (Tok.
isNot(tok::l_paren))
1942 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1943 ParsedAttr::Form::GNU());
1945 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs,
nullptr,
1948 ParsedAttr::Form::GNU(),
1952 if (ExpectAndConsume(tok::r_paren))
1954 if (ExpectAndConsume(tok::r_paren))
1956 }
else if (Tok.
is(tok::kw___declspec)) {
1957 ParseMicrosoftDeclSpecs(Attrs);
1959 Diag(Tok, diag::err_pragma_attribute_expected_attribute_syntax);
1968 if (Tok.
is(tok::l_paren)) {
1971 if (Tok.
isNot(tok::r_paren))
1974 Diag(Tok, diag::note_pragma_attribute_use_attribute_kw)
1983 if (Attrs.
empty() || Attrs.
begin()->isInvalid()) {
1989 if (!Attribute.isSupportedByPragmaAttribute()) {
1990 Diag(PragmaLoc, diag::err_pragma_attribute_unsupported_attribute)
1999 createExpectedAttributeSubjectRulesTokenDiagnostic(
2000 diag::err_expected, Attrs,
2001 MissingAttributeSubjectRulesRecoveryPoint::Comma, *
this)
2007 if (Tok.
isNot(tok::identifier)) {
2008 createExpectedAttributeSubjectRulesTokenDiagnostic(
2009 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2010 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2015 if (!II->
isStr(
"apply_to")) {
2016 createExpectedAttributeSubjectRulesTokenDiagnostic(
2017 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2018 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2025 createExpectedAttributeSubjectRulesTokenDiagnostic(
2026 diag::err_expected, Attrs,
2027 MissingAttributeSubjectRulesRecoveryPoint::Equals, *
this)
2035 if (ParsePragmaAttributeSubjectMatchRuleSet(SubjectMatchRules, AnyLoc,
2036 LastMatchRuleEndLoc)) {
2043 if (Tok.
isNot(tok::eof)) {
2044 Diag(Tok, diag::err_pragma_attribute_extra_tokens_after_attribute);
2053 if (Info->Action == PragmaAttributeInfo::Push)
2065void PragmaGCCVisibilityHandler::HandlePragma(
Preprocessor &PP,
2076 if (PushPop && PushPop->
isStr(
"pop")) {
2078 }
else if (PushPop && PushPop->
isStr(
"push")) {
2080 if (Tok.
isNot(tok::l_paren)) {
2093 if (Tok.
isNot(tok::r_paren)) {
2105 if (Tok.
isNot(tok::eod)) {
2111 auto Toks = std::make_unique<Token[]>(1);
2112 Toks[0].startToken();
2113 Toks[0].setKind(tok::annot_pragma_vis);
2114 Toks[0].setLocation(VisLoc);
2115 Toks[0].setAnnotationEndLoc(EndLoc);
2116 Toks[0].setAnnotationValue(
2117 const_cast<void *
>(
static_cast<const void *
>(VisType)));
2118 PP.EnterTokenStream(std::move(Toks), 1,
true,
2133 if (Tok.
isNot(tok::l_paren)) {
2134 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"pack";
2139 StringRef SlotLabel;
2143 if (Tok.
is(tok::numeric_constant)) {
2154 }
else if (Tok.
is(tok::identifier)) {
2156 if (II->
isStr(
"show")) {
2160 if (II->
isStr(
"push")) {
2162 }
else if (II->
isStr(
"pop")) {
2165 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_invalid_action) <<
"pack";
2170 if (Tok.
is(tok::comma)) {
2173 if (Tok.
is(tok::numeric_constant)) {
2178 }
else if (Tok.
is(tok::identifier)) {
2182 if (Tok.
is(tok::comma)) {
2185 if (Tok.
isNot(tok::numeric_constant)) {
2210 if (Tok.
isNot(tok::r_paren)) {
2211 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"pack";
2217 if (Tok.
isNot(tok::eod)) {
2218 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"pack";
2230 Toks[0].startToken();
2231 Toks[0].setKind(tok::annot_pragma_pack);
2232 Toks[0].setLocation(PackLoc);
2233 Toks[0].setAnnotationEndLoc(RParenLoc);
2234 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2235 PP.EnterTokenStream(Toks,
true,
2241void PragmaMSStructHandler::HandlePragma(
Preprocessor &PP,
2243 Token &MSStructTok) {
2248 if (Tok.
isNot(tok::identifier)) {
2254 if (II->
isStr(
"on")) {
2258 else if (II->
isStr(
"off") || II->
isStr(
"reset"))
2265 if (Tok.
isNot(tok::eod)) {
2273 Toks[0].startToken();
2274 Toks[0].setKind(tok::annot_pragma_msstruct);
2276 Toks[0].setAnnotationEndLoc(EndLoc);
2277 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2279 PP.EnterTokenStream(Toks,
true,
2284void PragmaClangSectionHandler::HandlePragma(
Preprocessor &PP,
2286 Token &FirstToken) {
2292 while (Tok.
isNot(tok::eod)) {
2293 if (Tok.
isNot(tok::identifier)) {
2294 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2299 if (SecType->
isStr(
"bss"))
2301 else if (SecType->
isStr(
"data"))
2303 else if (SecType->
isStr(
"rodata"))
2305 else if (SecType->
isStr(
"relro"))
2307 else if (SecType->
isStr(
"text"))
2310 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2316 if (Tok.
isNot(tok::equal)) {
2317 PP.
Diag(Tok.
getLocation(), diag::err_pragma_clang_section_expected_equal) << SecKind;
2321 std::string SecName;
2325 Actions.ActOnPragmaClangSection(
2342 if (Tok.
isNot(tok::identifier) ||
2351 if (Tok.
isNot(tok::l_paren)) {
2352 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"align";
2355 }
else if (Tok.
isNot(tok::equal)) {
2362 if (Tok.
isNot(tok::identifier)) {
2364 << (IsOptions ?
"options" :
"align");
2370 if (II->
isStr(
"native"))
2372 else if (II->
isStr(
"natural"))
2374 else if (II->
isStr(
"packed"))
2376 else if (II->
isStr(
"power"))
2378 else if (II->
isStr(
"mac68k"))
2380 else if (II->
isStr(
"reset"))
2390 if (Tok.
isNot(tok::r_paren)) {
2391 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"align";
2398 if (Tok.
isNot(tok::eod)) {
2400 << (IsOptions ?
"options" :
"align");
2406 Toks[0].startToken();
2407 Toks[0].setKind(tok::annot_pragma_align);
2409 Toks[0].setAnnotationEndLoc(EndLoc);
2410 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2412 PP.EnterTokenStream(Toks,
true,
2422void PragmaOptionsHandler::HandlePragma(
Preprocessor &PP,
2424 Token &OptionsTok) {
2429void PragmaUnusedHandler::HandlePragma(
Preprocessor &PP,
2438 if (Tok.
isNot(tok::l_paren)) {
2439 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"unused";
2452 if (Tok.
is(tok::identifier)) {
2453 Identifiers.push_back(Tok);
2464 if (Tok.
is(tok::comma)) {
2469 if (Tok.
is(tok::r_paren)) {
2475 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_punc) <<
"unused";
2480 if (Tok.
isNot(tok::eod)) {
2487 assert(RParenLoc.
isValid() &&
"Valid '#pragma unused' must have ')'");
2488 assert(!Identifiers.empty() &&
"Valid '#pragma unused' must have arguments");
2497 2 * Identifiers.size());
2498 for (
unsigned i=0; i != Identifiers.size(); i++) {
2499 Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
2501 pragmaUnusedTok.
setKind(tok::annot_pragma_unused);
2503 idTok = Identifiers[i];
2505 PP.EnterTokenStream(Toks,
true,
2518 if (Tok.
isNot(tok::identifier)) {
2519 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_identifier) <<
"weak";
2523 Token WeakName = Tok;
2524 bool HasAlias =
false;
2528 if (Tok.
is(tok::equal)) {
2531 if (Tok.
isNot(tok::identifier)) {
2540 if (Tok.
isNot(tok::eod)) {
2541 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"weak";
2548 Token &pragmaUnusedTok = Toks[0];
2550 pragmaUnusedTok.
setKind(tok::annot_pragma_weakalias);
2554 Toks[2] = AliasName;
2555 PP.EnterTokenStream(Toks,
true,
2560 Token &pragmaUnusedTok = Toks[0];
2562 pragmaUnusedTok.
setKind(tok::annot_pragma_weak);
2566 PP.EnterTokenStream(Toks,
true,
2572void PragmaRedefineExtnameHandler::HandlePragma(
Preprocessor &PP,
2574 Token &RedefToken) {
2579 if (Tok.
isNot(tok::identifier)) {
2585 Token RedefName = Tok;
2588 if (Tok.
isNot(tok::identifier)) {
2590 <<
"redefine_extname";
2594 Token AliasName = Tok;
2597 if (Tok.
isNot(tok::eod)) {
2605 Token &pragmaRedefTok = Toks[0];
2607 pragmaRedefTok.
setKind(tok::annot_pragma_redefine_extname);
2610 Toks[1] = RedefName;
2611 Toks[2] = AliasName;
2612 PP.EnterTokenStream(Toks,
true,
2616void PragmaFPContractHandler::HandlePragma(
Preprocessor &PP,
2625 Toks[0].startToken();
2626 Toks[0].setKind(tok::annot_pragma_fp_contract);
2629 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2631 PP.EnterTokenStream(Toks,
true,
2635void PragmaOpenCLExtensionHandler::HandlePragma(
Preprocessor &PP,
2639 if (Tok.
isNot(tok::identifier)) {
2648 if (Tok.
isNot(tok::colon)) {
2654 if (Tok.
isNot(tok::identifier)) {
2655 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_predicate) << 0;
2660 OpenCLExtState State;
2661 if (Pred->
isStr(
"enable")) {
2663 }
else if (Pred->
isStr(
"disable")) {
2665 }
else if (Pred->
isStr(
"begin"))
2667 else if (Pred->
isStr(
"end"))
2671 << Ext->
isStr(
"all");
2677 if (Tok.
isNot(tok::eod)) {
2685 Info->second = State;
2688 Toks[0].startToken();
2689 Toks[0].setKind(tok::annot_pragma_opencl_extension);
2690 Toks[0].setLocation(NameLoc);
2691 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2692 Toks[0].setAnnotationEndLoc(StateLoc);
2693 PP.EnterTokenStream(Toks,
true,
2703template <diag::kind IgnoredDiag>
2704void PragmaNoSupportHandler<IgnoredDiag>::HandlePragma(
2707 PP.
Diag(FirstTok, IgnoredDiag);
2718void PragmaSupportHandler<StartTok, EndTok, UnexpectedDiag>::HandlePragma(
2726 while (Tok.
isNot(tok::eod) && Tok.
isNot(tok::eof)) {
2727 Pragma.push_back(Tok);
2729 if (Tok.
is(StartTok)) {
2730 PP.
Diag(Tok, UnexpectedDiag) << 0;
2731 unsigned InnerPragmaCnt = 1;
2732 while (InnerPragmaCnt != 0) {
2734 if (Tok.
is(StartTok))
2736 else if (Tok.
is(EndTok))
2746 Pragma.push_back(Tok);
2748 auto Toks = std::make_unique<Token[]>(Pragma.size());
2749 std::copy(Pragma.begin(), Pragma.end(), Toks.get());
2750 PP.EnterTokenStream(std::move(Toks), Pragma.size(),
2762void PragmaMSPointersToMembers::HandlePragma(
Preprocessor &PP,
2767 if (Tok.
isNot(tok::l_paren)) {
2768 PP.
Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen)
2769 <<
"pointers_to_members";
2776 <<
"pointers_to_members";
2782 if (Arg->
isStr(
"best_case")) {
2785 if (Arg->
isStr(
"full_generality")) {
2786 if (Tok.
is(tok::comma)) {
2792 diag::err_pragma_pointers_to_members_unknown_kind)
2797 }
else if (Tok.
is(tok::r_paren)) {
2804 <<
"full_generality";
2810 if (Arg->
isStr(
"single_inheritance")) {
2811 RepresentationMethod =
2813 }
else if (Arg->
isStr(
"multiple_inheritance")) {
2814 RepresentationMethod =
2816 }
else if (Arg->
isStr(
"virtual_inheritance")) {
2817 RepresentationMethod =
2821 diag::err_pragma_pointers_to_members_unknown_kind)
2828 if (Tok.
isNot(tok::r_paren)) {
2830 << (Arg ? Arg->
getName() :
"full_generality");
2836 if (Tok.
isNot(tok::eod)) {
2838 <<
"pointers_to_members";
2844 AnnotTok.
setKind(tok::annot_pragma_ms_pointers_to_members);
2848 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RepresentationMethod)));
2864 if (Tok.
isNot(tok::l_paren)) {
2865 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) <<
"vtordisp";
2873 if (II->
isStr(
"push")) {
2876 if (Tok.
isNot(tok::comma)) {
2877 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_punc) <<
"vtordisp";
2883 }
else if (II->
isStr(
"pop")) {
2890 if (Tok.
is(tok::r_paren)) {
2900 if (II && II->
isStr(
"off")) {
2903 }
else if (II && II->
isStr(
"on")) {
2906 }
else if (Tok.
is(tok::numeric_constant) &&
2910 << 0 << 2 <<
"vtordisp";
2921 if (Tok.
isNot(tok::r_paren)) {
2922 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) <<
"vtordisp";
2927 if (Tok.
isNot(tok::eod)) {
2936 AnnotTok.
setKind(tok::annot_pragma_ms_vtordisp);
2948 Token EoF, AnnotTok;
2952 AnnotTok.
setKind(tok::annot_pragma_ms_pragma);
2957 for (; Tok.
isNot(tok::eod); PP.
Lex(Tok)) {
2958 TokenVector.push_back(Tok);
2962 TokenVector.push_back(EoF);
2965 markAsReinjectedForRelexing(TokenVector);
2966 auto TokenArray = std::make_unique<Token[]>(TokenVector.size());
2967 std::copy(TokenVector.begin(), TokenVector.end(), TokenArray.get());
2969 std::pair<std::unique_ptr<
Token[]>,
size_t>(std::move(TokenArray),
2970 TokenVector.size());
2986void PragmaFloatControlHandler::HandlePragma(
Preprocessor &PP,
2991 Token PragmaName = Tok;
2998 if (Tok.
isNot(tok::l_paren)) {
2999 PP.
Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
3005 if (Tok.
isNot(tok::identifier)) {
3013 llvm::StringSwitch<PragmaFloatControlKind>(II->
getName())
3024 if (Tok.
isNot(tok::r_paren)) {
3031 if (Tok.
is(tok::r_paren))
3034 else if (Tok.
isNot(tok::comma)) {
3044 if (PushOnOff ==
"on")
3047 else if (PushOnOff ==
"off") {
3052 }
else if (PushOnOff ==
"push") {
3059 if (Tok.
is(tok::comma)) {
3066 if (ExpectedPush ==
"push") {
3074 if (Tok.
isNot(tok::r_paren)) {
3082 if (Tok.
isNot(tok::eod)) {
3091 auto TokenArray = std::make_unique<Token[]>(1);
3092 TokenArray[0].startToken();
3093 TokenArray[0].setKind(tok::annot_pragma_float_control);
3094 TokenArray[0].setLocation(FloatControlLoc);
3095 TokenArray[0].setAnnotationEndLoc(EndLoc);
3098 TokenArray[0].setAnnotationValue(
reinterpret_cast<void *
>(
3099 static_cast<uintptr_t>((Action << 16) | (Kind & 0xFFFF))));
3100 PP.EnterTokenStream(std::move(TokenArray), 1,
3114void PragmaDetectMismatchHandler::HandlePragma(
Preprocessor &PP,
3119 if (Tok.
isNot(tok::l_paren)) {
3120 PP.
Diag(DetectMismatchLoc, diag::err_expected) << tok::l_paren;
3125 std::string NameString;
3127 "pragma detect_mismatch",
3132 std::string ValueString;
3133 if (Tok.
isNot(tok::comma)) {
3134 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3142 if (Tok.
isNot(tok::r_paren)) {
3148 if (Tok.
isNot(tok::eod)) {
3149 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3158 Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString);
3170void PragmaCommentHandler::HandlePragma(
Preprocessor &PP,
3175 if (Tok.
isNot(tok::l_paren)) {
3176 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3182 if (Tok.
isNot(tok::identifier)) {
3183 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3190 llvm::StringSwitch<PragmaMSCommentKind>(II->
getName())
3210 std::string ArgumentString;
3223 if (Tok.
isNot(tok::r_paren)) {
3229 if (Tok.
isNot(tok::eod)) {
3238 Actions.ActOnPragmaMSComment(CommentLoc, Kind, ArgumentString);
3243void PragmaOptimizeHandler::HandlePragma(
Preprocessor &PP,
3245 Token &FirstToken) {
3248 if (Tok.
is(tok::eod)) {
3250 <<
"clang optimize" <<
true <<
"'on' or 'off'";
3253 if (Tok.
isNot(tok::identifier)) {
3254 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3261 if (II->
isStr(
"on")) {
3263 }
else if (!II->
isStr(
"off")) {
3264 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3270 if (Tok.
isNot(tok::eod)) {
3276 Actions.ActOnPragmaOptimize(IsOn, FirstToken.
getLocation());
3281struct TokFPAnnotValue {
3282 enum FlagValues { On, Off, Fast };
3284 std::optional<LangOptions::FPModeKind> ContractValue;
3285 std::optional<LangOptions::FPModeKind> ReassociateValue;
3286 std::optional<LangOptions::FPModeKind> ReciprocalValue;
3287 std::optional<LangOptions::FPExceptionModeKind> ExceptionsValue;
3288 std::optional<LangOptions::FPEvalMethodKind> EvalMethodValue;
3295 Token PragmaName = Tok;
3299 if (Tok.
isNot(tok::identifier)) {
3306 while (Tok.
is(tok::identifier)) {
3310 llvm::StringSwitch<std::optional<PragmaFPKind>>(OptionInfo->
getName())
3316 .Default(std::nullopt);
3319 <<
false << OptionInfo;
3325 if (Tok.
isNot(tok::l_paren)) {
3330 bool isEvalMethodDouble =
3334 if (Tok.
isNot(tok::identifier) && !isEvalMethodDouble) {
3337 <<
static_cast<int>(*FlagKind);
3343 AnnotValue->ContractValue =
3344 llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3349 .Default(std::nullopt);
3350 if (!AnnotValue->ContractValue) {
3357 : AnnotValue->ReciprocalValue;
3358 Value = llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3362 .Default(std::nullopt);
3369 AnnotValue->ExceptionsValue =
3370 llvm::StringSwitch<std::optional<LangOptions::FPExceptionModeKind>>(
3375 .Default(std::nullopt);
3376 if (!AnnotValue->ExceptionsValue) {
3382 AnnotValue->EvalMethodValue =
3383 llvm::StringSwitch<std::optional<LangOptions::FPEvalMethodKind>>(
3388 .Default(std::nullopt);
3389 if (!AnnotValue->EvalMethodValue) {
3398 if (Tok.
isNot(tok::r_paren)) {
3405 if (Tok.
isNot(tok::eod)) {
3413 FPTok.
setKind(tok::annot_pragma_fp);
3417 TokenList.push_back(FPTok);
3419 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3420 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3422 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3426void PragmaSTDC_FENV_ROUNDHandler::HandlePragma(
Preprocessor &PP,
3429 Token PragmaName = Tok;
3438 if (Tok.
isNot(tok::identifier)) {
3446 llvm::StringSwitch<llvm::RoundingMode>(II->
getName())
3447 .Case(
"FE_TOWARDZERO", llvm::RoundingMode::TowardZero)
3448 .Case(
"FE_TONEAREST", llvm::RoundingMode::NearestTiesToEven)
3449 .Case(
"FE_UPWARD", llvm::RoundingMode::TowardPositive)
3450 .Case(
"FE_DOWNWARD", llvm::RoundingMode::TowardNegative)
3451 .Case(
"FE_TONEARESTFROMZERO", llvm::RoundingMode::NearestTiesToAway)
3452 .Case(
"FE_DYNAMIC", llvm::RoundingMode::Dynamic)
3453 .Default(llvm::RoundingMode::Invalid);
3454 if (RM == llvm::RoundingMode::Invalid) {
3460 if (Tok.
isNot(tok::eod)) {
3462 <<
"STDC FENV_ROUND";
3471 Toks[0].startToken();
3472 Toks[0].setKind(tok::annot_pragma_fenv_round);
3475 Toks[0].setAnnotationValue(
3476 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RM)));
3477 PP.EnterTokenStream(Toks,
true,
3481void Parser::HandlePragmaFP() {
3482 assert(Tok.
is(tok::annot_pragma_fp));
3486 if (AnnotValue->ReassociateValue)
3491 if (AnnotValue->ReciprocalValue)
3496 if (AnnotValue->ContractValue)
3498 *AnnotValue->ContractValue);
3499 if (AnnotValue->ExceptionsValue)
3501 *AnnotValue->ExceptionsValue);
3502 if (AnnotValue->EvalMethodValue)
3504 *AnnotValue->EvalMethodValue);
3505 ConsumeAnnotationToken();
3510 Token Option,
bool ValueInParens,
3513 int OpenParens = ValueInParens ? 1 : 0;
3515 while (Tok.
isNot(tok::eod)) {
3516 if (Tok.
is(tok::l_paren))
3518 else if (Tok.
is(tok::r_paren)) {
3520 if (OpenParens == 0 && ValueInParens)
3528 if (ValueInParens) {
3530 if (Tok.
isNot(tok::r_paren)) {
3599void PragmaLoopHintHandler::HandlePragma(
Preprocessor &PP,
3603 Token PragmaName = Tok;
3608 if (Tok.
isNot(tok::identifier)) {
3614 while (Tok.
is(tok::identifier)) {
3618 bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->
getName())
3619 .Case(
"vectorize",
true)
3620 .Case(
"interleave",
true)
3621 .Case(
"unroll",
true)
3622 .Case(
"distribute",
true)
3623 .Case(
"vectorize_predicate",
true)
3624 .Case(
"vectorize_width",
true)
3625 .Case(
"interleave_count",
true)
3626 .Case(
"unroll_count",
true)
3627 .Case(
"pipeline",
true)
3628 .Case(
"pipeline_initiation_interval",
true)
3632 <<
false << OptionInfo;
3638 if (Tok.
isNot(tok::l_paren)) {
3652 LoopHintTok.
setKind(tok::annot_pragma_loop_hint);
3656 TokenList.push_back(LoopHintTok);
3659 if (Tok.
isNot(tok::eod)) {
3665 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3666 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3668 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3693void PragmaUnrollHintHandler::HandlePragma(
Preprocessor &PP,
3698 Token PragmaName = Tok;
3701 if (Tok.
is(tok::eod)) {
3703 Info->PragmaName = PragmaName;
3704 Info->Option.startToken();
3714 bool ValueInParens = Tok.
is(tok::l_paren);
3726 PP.
Diag(Info->Toks[0].getLocation(),
3727 diag::warn_pragma_unroll_cuda_value_in_parens);
3729 if (Tok.
isNot(tok::eod)) {
3737 auto TokenArray = std::make_unique<Token[]>(1);
3738 TokenArray[0].startToken();
3739 TokenArray[0].setKind(tok::annot_pragma_loop_hint);
3740 TokenArray[0].setLocation(Introducer.
Loc);
3741 TokenArray[0].setAnnotationEndLoc(PragmaName.
getLocation());
3742 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
3743 PP.EnterTokenStream(std::move(TokenArray), 1,
3759void PragmaMSIntrinsicHandler::HandlePragma(
Preprocessor &PP,
3764 if (Tok.
isNot(tok::l_paren)) {
3773 while (Tok.
is(tok::identifier)) {
3777 << II << SuggestIntrinH;
3780 if (Tok.
isNot(tok::comma))
3785 if (Tok.
isNot(tok::r_paren)) {
3792 if (Tok.
isNot(tok::eod))
3797bool Parser::HandlePragmaMSFunction(StringRef PragmaName,
3799 Token FirstTok = Tok;
3801 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3808 while (Tok.
is(tok::identifier)) {
3812 << II << SuggestIntrinH;
3814 NoBuiltins.emplace_back(II->
getName());
3817 if (Tok.
isNot(tok::comma))
3822 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3824 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3833bool Parser::HandlePragmaMSOptimize(StringRef PragmaName,
3835 Token FirstTok = Tok;
3836 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3840 if (Tok.
isNot(tok::string_literal)) {
3841 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_string) << PragmaName;
3849 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
3854 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
3858 if (Tok.
is(tok::eof) || Tok.
is(tok::r_paren)) {
3859 PP.
Diag(PragmaLocation, diag::warn_pragma_missing_argument)
3860 << PragmaName <<
true <<
"'on' or 'off'";
3864 if (!II || (!II->
isStr(
"on") && !II->
isStr(
"off"))) {
3865 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3870 bool IsOn = II->
isStr(
"on");
3873 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3878 if (!OptimizationList->
getString().empty()) {
3879 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3880 << OptimizationList->
getString() << PragmaName <<
true
3885 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3893void PragmaForceCUDAHostDeviceHandler::HandlePragma(
3895 Token FirstTok = Tok;
3899 if (!Info || (!Info->
isStr(
"begin") && !Info->
isStr(
"end"))) {
3901 diag::warn_pragma_force_cuda_host_device_bad_arg);
3905 if (Info->
isStr(
"begin"))
3906 Actions.CUDA().PushForceHostDevice();
3907 else if (!Actions.CUDA().PopForceHostDevice())
3909 diag::err_pragma_cannot_end_force_cuda_host_device);
3912 if (!Tok.
is(tok::eod))
3914 diag::warn_pragma_force_cuda_host_device_bad_arg);
3944void PragmaAttributeHandler::HandlePragma(
Preprocessor &PP,
3946 Token &FirstToken) {
3950 PragmaAttributeInfo(AttributesForPragmaAttribute);
3953 if (Tok.
is(tok::identifier)) {
3955 if (!II->
isStr(
"push") && !II->
isStr(
"pop")) {
3956 Info->Namespace = II;
3959 if (!Tok.
is(tok::period)) {
3960 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_period)
3968 if (!Tok.
isOneOf(tok::identifier, tok::l_paren)) {
3970 diag::err_pragma_attribute_expected_push_pop_paren);
3975 if (Tok.
is(tok::l_paren)) {
3976 if (Info->Namespace) {
3978 diag::err_pragma_attribute_namespace_on_attribute);
3980 diag::note_pragma_attribute_namespace_on_attribute);
3983 Info->Action = PragmaAttributeInfo::Attribute;
3986 if (II->
isStr(
"push"))
3987 Info->Action = PragmaAttributeInfo::Push;
3989 Info->Action = PragmaAttributeInfo::Pop;
3991 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_invalid_argument)
4000 if ((Info->Action == PragmaAttributeInfo::Push && Tok.
isNot(tok::eod)) ||
4001 Info->Action == PragmaAttributeInfo::Attribute) {
4002 if (Tok.
isNot(tok::l_paren)) {
4011 while (Tok.
isNot(tok::eod)) {
4012 if (Tok.
is(tok::l_paren))
4014 else if (Tok.
is(tok::r_paren)) {
4016 if (OpenParens == 0)
4020 AttributeTokens.push_back(Tok);
4024 if (AttributeTokens.empty()) {
4025 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_attribute);
4028 if (Tok.
isNot(tok::r_paren)) {
4040 AttributeTokens.push_back(EOFTok);
4042 markAsReinjectedForRelexing(AttributeTokens);
4047 if (Tok.
isNot(tok::eod))
4049 <<
"clang attribute";
4052 auto TokenArray = std::make_unique<Token[]>(1);
4053 TokenArray[0].startToken();
4054 TokenArray[0].setKind(tok::annot_pragma_attribute);
4055 TokenArray[0].setLocation(FirstToken.
getLocation());
4056 TokenArray[0].setAnnotationEndLoc(FirstToken.
getLocation());
4057 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
4058 PP.EnterTokenStream(std::move(TokenArray), 1,
4063void PragmaMaxTokensHereHandler::HandlePragma(
Preprocessor &PP,
4067 if (Tok.
is(tok::eod)) {
4069 <<
"clang max_tokens_here" <<
true <<
"integer";
4075 if (Tok.
isNot(tok::numeric_constant) ||
4078 <<
"clang max_tokens_here";
4082 if (Tok.
isNot(tok::eod)) {
4084 <<
"clang max_tokens_here";
4089 PP.
Diag(Loc, diag::warn_max_tokens)
4095void PragmaMaxTokensTotalHandler::HandlePragma(
Preprocessor &PP,
4099 if (Tok.
is(tok::eod)) {
4101 <<
"clang max_tokens_total" <<
true <<
"integer";
4107 if (Tok.
isNot(tok::numeric_constant) ||
4110 <<
"clang max_tokens_total";
4114 if (Tok.
isNot(tok::eod)) {
4116 <<
"clang max_tokens_total";
4127 Token &FirstToken) {
4132 if (!II || !II->
isStr(
"intrinsic")) {
4134 << PP.
getSpelling(Tok) <<
"riscv" <<
true <<
"'intrinsic'";
4140 if (!II || !(II->
isStr(
"vector") || II->
isStr(
"sifive_vector"))) {
4143 <<
"'vector' or 'sifive_vector'";
4148 if (Tok.
isNot(tok::eod)) {
4150 <<
"clang riscv intrinsic";
4154 if (II->
isStr(
"vector"))
4155 Actions.DeclareRISCVVBuiltins =
true;
4156 else if (II->
isStr(
"sifive_vector"))
4157 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
This file declares semantic analysis for CUDA constructs.
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.
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.
@ 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)
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 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....
@ 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.
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...
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