23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/StringSwitch.h"
33 Token &FirstToken)
override;
37 explicit PragmaGCCVisibilityHandler() :
PragmaHandler(
"visibility") {}
39 Token &FirstToken)
override;
45 Token &FirstToken)
override;
51 Token &FirstToken)
override;
55 explicit PragmaClangSectionHandler(
Sema &S)
58 Token &FirstToken)
override;
65 explicit PragmaMSStructHandler() :
PragmaHandler(
"ms_struct") {}
67 Token &FirstToken)
override;
73 Token &FirstToken)
override;
79 Token &FirstToken)
override;
83 explicit PragmaRedefineExtnameHandler() :
PragmaHandler(
"redefine_extname") {}
85 Token &FirstToken)
override;
89 PragmaOpenCLExtensionHandler() :
PragmaHandler(
"EXTENSION") {}
91 Token &FirstToken)
override;
98 Token &FirstToken)
override;
105 PragmaSTDC_FENV_ACCESSHandler() :
PragmaHandler(
"FENV_ACCESS") {}
108 Token &Tok)
override {
109 Token PragmaName = Tok;
121 Toks[0].startToken();
122 Toks[0].setKind(tok::annot_pragma_fenv_access);
125 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
127 PP.EnterTokenStream(Toks,
true,
133struct PragmaSTDC_CX_LIMITED_RANGEHandler :
public PragmaHandler {
134 PragmaSTDC_CX_LIMITED_RANGEHandler() :
PragmaHandler(
"CX_LIMITED_RANGE") {}
137 Token &Tok)
override {
145 PragmaSTDC_FENV_ROUNDHandler() :
PragmaHandler(
"FENV_ROUND") {}
148 Token &Tok)
override;
153 PragmaSTDC_UnknownHandler() =
default;
156 Token &UnknownTok)
override {
158 PP.
Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
165 Token &FirstToken)
override;
171 Token &FirstToken)
override;
177 Token &FirstToken)
override;
182 PragmaCommentHandler(
Sema &Actions)
185 Token &FirstToken)
override;
192 PragmaDetectMismatchHandler(
Sema &Actions)
195 Token &FirstToken)
override;
202 PragmaFloatControlHandler(
Sema &Actions)
205 Token &FirstToken)
override;
209 explicit PragmaMSPointersToMembers() :
PragmaHandler(
"pointers_to_members") {}
211 Token &FirstToken)
override;
217 Token &FirstToken)
override;
223 Token &FirstToken)
override;
228 PragmaOptimizeHandler(
Sema &S)
231 Token &FirstToken)
override;
240 Token &FirstToken)
override;
246 Token &FirstToken)
override;
256 Token &FirstToken)
override;
261 PragmaMSFenvAccessHandler() :
PragmaHandler(
"fenv_access") {}
263 Token &FirstToken)
override {
273 if (Tok.
isNot(tok::l_paren)) {
279 if (Tok.
isNot(tok::identifier)) {
285 if (II->
isStr(
"on")) {
288 }
else if (II->
isStr(
"off")) {
295 if (Tok.
isNot(tok::r_paren)) {
302 if (Tok.
isNot(tok::eod)) {
310 Toks[0].startToken();
311 Toks[0].setKind(tok::annot_pragma_fenv_access_ms);
314 Toks[0].setAnnotationValue(
315 reinterpret_cast<void*
>(
static_cast<uintptr_t>(OOS)));
316 PP.EnterTokenStream(Toks,
true,
321struct PragmaForceCUDAHostDeviceHandler :
public PragmaHandler {
322 PragmaForceCUDAHostDeviceHandler(
Sema &Actions)
323 :
PragmaHandler(
"force_cuda_host_device"), Actions(Actions) {}
325 Token &FirstToken)
override;
334 :
PragmaHandler(
"attribute"), AttributesForPragmaAttribute(AttrFactory) {}
336 Token &FirstToken)
override;
343 PragmaMaxTokensHereHandler() :
PragmaHandler(
"max_tokens_here") {}
345 Token &FirstToken)
override;
349 PragmaMaxTokensTotalHandler() :
PragmaHandler(
"max_tokens_total") {}
351 Token &FirstToken)
override;
355 PragmaRISCVHandler(
Sema &Actions)
358 Token &FirstToken)
override;
370void Parser::initializePragmaHandlers() {
371 AlignHandler = std::make_unique<PragmaAlignHandler>();
374 GCCVisibilityHandler = std::make_unique<PragmaGCCVisibilityHandler>();
377 OptionsHandler = std::make_unique<PragmaOptionsHandler>();
380 PackHandler = std::make_unique<PragmaPackHandler>();
383 MSStructHandler = std::make_unique<PragmaMSStructHandler>();
386 UnusedHandler = std::make_unique<PragmaUnusedHandler>();
389 WeakHandler = std::make_unique<PragmaWeakHandler>();
392 RedefineExtnameHandler = std::make_unique<PragmaRedefineExtnameHandler>();
395 FPContractHandler = std::make_unique<PragmaFPContractHandler>();
398 STDCFenvAccessHandler = std::make_unique<PragmaSTDC_FENV_ACCESSHandler>();
401 STDCFenvRoundHandler = std::make_unique<PragmaSTDC_FENV_ROUNDHandler>();
404 STDCCXLIMITHandler = std::make_unique<PragmaSTDC_CX_LIMITED_RANGEHandler>();
407 STDCUnknownHandler = std::make_unique<PragmaSTDC_UnknownHandler>();
410 PCSectionHandler = std::make_unique<PragmaClangSectionHandler>(Actions);
414 OpenCLExtensionHandler = std::make_unique<PragmaOpenCLExtensionHandler>();
420 OpenMPHandler = std::make_unique<PragmaOpenMPHandler>();
422 OpenMPHandler = std::make_unique<PragmaNoOpenMPHandler>();
427 MSCommentHandler = std::make_unique<PragmaCommentHandler>(Actions);
431 FloatControlHandler = std::make_unique<PragmaFloatControlHandler>(Actions);
434 MSDetectMismatchHandler =
435 std::make_unique<PragmaDetectMismatchHandler>(Actions);
437 MSPointersToMembers = std::make_unique<PragmaMSPointersToMembers>();
439 MSVtorDisp = std::make_unique<PragmaMSVtorDisp>();
441 MSInitSeg = std::make_unique<PragmaMSPragma>(
"init_seg");
443 MSDataSeg = std::make_unique<PragmaMSPragma>(
"data_seg");
445 MSBSSSeg = std::make_unique<PragmaMSPragma>(
"bss_seg");
447 MSConstSeg = std::make_unique<PragmaMSPragma>(
"const_seg");
449 MSCodeSeg = std::make_unique<PragmaMSPragma>(
"code_seg");
451 MSSection = std::make_unique<PragmaMSPragma>(
"section");
453 MSStrictGuardStackCheck =
454 std::make_unique<PragmaMSPragma>(
"strict_gs_check");
456 MSFunction = std::make_unique<PragmaMSPragma>(
"function");
458 MSAllocText = std::make_unique<PragmaMSPragma>(
"alloc_text");
460 MSOptimize = std::make_unique<PragmaMSPragma>(
"optimize");
462 MSRuntimeChecks = std::make_unique<PragmaMSRuntimeChecksHandler>();
464 MSIntrinsic = std::make_unique<PragmaMSIntrinsicHandler>();
466 MSFenvAccess = std::make_unique<PragmaMSFenvAccessHandler>();
471 CUDAForceHostDeviceHandler =
472 std::make_unique<PragmaForceCUDAHostDeviceHandler>(Actions);
476 OptimizeHandler = std::make_unique<PragmaOptimizeHandler>(Actions);
479 LoopHintHandler = std::make_unique<PragmaLoopHintHandler>();
482 UnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"unroll");
486 NoUnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"nounroll");
490 UnrollAndJamHintHandler =
491 std::make_unique<PragmaUnrollHintHandler>(
"unroll_and_jam");
494 NoUnrollAndJamHintHandler =
495 std::make_unique<PragmaUnrollHintHandler>(
"nounroll_and_jam");
498 FPHandler = std::make_unique<PragmaFPHandler>();
501 AttributePragmaHandler =
502 std::make_unique<PragmaAttributeHandler>(AttrFactory);
505 MaxTokensHerePragmaHandler = std::make_unique<PragmaMaxTokensHereHandler>();
508 MaxTokensTotalPragmaHandler = std::make_unique<PragmaMaxTokensTotalHandler>();
512 RISCVPragmaHandler = std::make_unique<PragmaRISCVHandler>(Actions);
517void Parser::resetPragmaHandlers() {
520 AlignHandler.reset();
522 GCCVisibilityHandler.reset();
524 OptionsHandler.reset();
528 MSStructHandler.reset();
530 UnusedHandler.reset();
534 RedefineExtnameHandler.reset();
538 OpenCLExtensionHandler.reset();
542 OpenMPHandler.reset();
547 MSCommentHandler.reset();
551 PCSectionHandler.reset();
554 FloatControlHandler.reset();
557 MSDetectMismatchHandler.reset();
559 MSPointersToMembers.reset();
575 MSStrictGuardStackCheck.reset();
581 MSRuntimeChecks.reset();
587 MSFenvAccess.reset();
592 CUDAForceHostDeviceHandler.reset();
596 FPContractHandler.reset();
599 STDCFenvAccessHandler.reset();
602 STDCFenvRoundHandler.reset();
605 STDCCXLIMITHandler.reset();
608 STDCUnknownHandler.reset();
611 OptimizeHandler.reset();
614 LoopHintHandler.reset();
618 UnrollHintHandler.reset();
622 NoUnrollHintHandler.reset();
625 UnrollAndJamHintHandler.reset();
628 NoUnrollAndJamHintHandler.reset();
634 AttributePragmaHandler.reset();
637 MaxTokensHerePragmaHandler.reset();
640 MaxTokensTotalPragmaHandler.reset();
644 RISCVPragmaHandler.reset();
653void Parser::HandlePragmaUnused() {
654 assert(Tok.
is(tok::annot_pragma_unused));
660void Parser::HandlePragmaVisibility() {
661 assert(Tok.
is(tok::annot_pragma_vis));
668void Parser::HandlePragmaPack() {
669 assert(Tok.
is(tok::annot_pragma_pack));
677 ConsumeAnnotationToken();
685 ConsumeAnnotationToken();
688void Parser::HandlePragmaMSStruct() {
689 assert(Tok.
is(tok::annot_pragma_msstruct));
693 ConsumeAnnotationToken();
696void Parser::HandlePragmaAlign() {
697 assert(Tok.
is(tok::annot_pragma_align));
704 ConsumeAnnotationToken();
707void Parser::HandlePragmaDump() {
708 assert(Tok.
is(tok::annot_pragma_dump));
712 ConsumeAnnotationToken();
715void Parser::HandlePragmaWeak() {
716 assert(Tok.
is(tok::annot_pragma_weak));
723void Parser::HandlePragmaWeakAlias() {
724 assert(Tok.
is(tok::annot_pragma_weakalias));
733 WeakNameLoc, AliasNameLoc);
737void Parser::HandlePragmaRedefineExtname() {
738 assert(Tok.
is(tok::annot_pragma_redefine_extname));
747 RedefNameLoc, AliasNameLoc);
750void Parser::HandlePragmaFPContract() {
751 assert(Tok.
is(tok::annot_pragma_fp_contract));
773void Parser::HandlePragmaFloatControl() {
774 assert(Tok.
is(tok::annot_pragma_float_control));
789void Parser::HandlePragmaFEnvAccess() {
790 assert(Tok.
is(tok::annot_pragma_fenv_access) ||
791 Tok.
is(tok::annot_pragma_fenv_access_ms));
813void Parser::HandlePragmaFEnvRound() {
814 assert(Tok.
is(tok::annot_pragma_fenv_round));
815 auto RM =
static_cast<llvm::RoundingMode
>(
824 assert(Tok.
is(tok::annot_pragma_captured));
825 ConsumeAnnotationToken();
827 if (Tok.
isNot(tok::l_brace)) {
828 PP.
Diag(Tok, diag::err_expected) << tok::l_brace;
840 CapturedRegionScope.Exit();
851 enum OpenCLExtState :
char {
852 Disable, Enable,
Begin, End
854 typedef std::pair<const IdentifierInfo *, OpenCLExtState> OpenCLExtData;
857void Parser::HandlePragmaOpenCLExtension() {
858 assert(Tok.
is(tok::annot_pragma_opencl_extension));
860 auto State =
Data->second;
861 auto Ident =
Data->first;
863 ConsumeAnnotationToken();
866 auto Name = Ident->getName();
871 if (State == Disable)
874 PP.
Diag(NameLoc, diag::warn_pragma_expected_predicate) << 1;
875 }
else if (State ==
Begin) {
876 if (!Opt.isKnown(Name) || !Opt.isSupported(Name,
getLangOpts())) {
880 Opt.acceptsPragma(Name);
882 }
else if (State == End) {
885 }
else if (!Opt.isKnown(Name) || !Opt.isWithPragma(Name))
886 PP.
Diag(NameLoc, diag::warn_pragma_unknown_extension) << Ident;
887 else if (Opt.isSupportedExtension(Name,
getLangOpts()))
888 Opt.enable(Name, State == Enable);
889 else if (Opt.isSupportedCoreOrOptionalCore(Name,
getLangOpts()))
890 PP.
Diag(NameLoc, diag::warn_pragma_extension_is_core) << Ident;
892 PP.
Diag(NameLoc, diag::warn_pragma_unsupported_extension) << Ident;
895void Parser::HandlePragmaMSPointersToMembers() {
896 assert(Tok.
is(tok::annot_pragma_ms_pointers_to_members));
904void Parser::HandlePragmaMSVtorDisp() {
905 assert(Tok.
is(tok::annot_pragma_ms_vtordisp));
914void Parser::HandlePragmaMSPragma() {
915 assert(Tok.
is(tok::annot_pragma_ms_pragma));
919 PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second,
true,
930 llvm::StringSwitch<PragmaHandler>(PragmaName)
931 .Case(
"data_seg", &Parser::HandlePragmaMSSegment)
932 .Case(
"bss_seg", &Parser::HandlePragmaMSSegment)
933 .Case(
"const_seg", &Parser::HandlePragmaMSSegment)
934 .Case(
"code_seg", &Parser::HandlePragmaMSSegment)
935 .Case(
"section", &Parser::HandlePragmaMSSection)
936 .Case(
"init_seg", &Parser::HandlePragmaMSInitSeg)
937 .Case(
"strict_gs_check", &Parser::HandlePragmaMSStrictGuardStackCheck)
938 .Case(
"function", &Parser::HandlePragmaMSFunction)
939 .Case(
"alloc_text", &Parser::HandlePragmaMSAllocText)
940 .Case(
"optimize", &Parser::HandlePragmaMSOptimize);
942 if (!(this->*Handler)(PragmaName, PragmaLocation)) {
945 while (Tok.
isNot(tok::eof))
951bool Parser::HandlePragmaMSSection(StringRef PragmaName,
953 if (Tok.
isNot(tok::l_paren)) {
954 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
959 if (Tok.
isNot(tok::string_literal)) {
960 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
969 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
974 bool SectionFlagsAreDefault =
true;
975 while (Tok.
is(tok::comma)) {
980 if (Tok.
is(tok::kw_long) || Tok.
is(tok::kw_short)) {
986 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren)
991 llvm::StringSwitch<ASTContext::PragmaSectionFlag>(
1004 ? diag::warn_pragma_invalid_specific_action
1005 : diag::warn_pragma_unsupported_action)
1009 SectionFlags |= Flag;
1010 SectionFlagsAreDefault =
false;
1015 if (SectionFlagsAreDefault)
1017 if (Tok.
isNot(tok::r_paren)) {
1018 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1022 if (Tok.
isNot(tok::eof)) {
1023 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1032bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
1034 if (Tok.
isNot(tok::l_paren)) {
1035 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1040 StringRef SlotLabel;
1043 if (PushPop ==
"push")
1045 else if (PushPop ==
"pop")
1048 PP.
Diag(PragmaLocation,
1049 diag::warn_pragma_expected_section_push_pop_or_name)
1055 if (Tok.
is(tok::comma)) {
1061 if (Tok.
is(tok::comma))
1063 else if (Tok.
isNot(tok::r_paren)) {
1064 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc)
1069 }
else if (Tok.
isNot(tok::r_paren)) {
1070 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc) << PragmaName;
1077 if (Tok.
isNot(tok::r_paren)) {
1078 if (Tok.
isNot(tok::string_literal)) {
1080 diag::warn_pragma_expected_section_name :
1081 diag::warn_pragma_expected_section_label_or_name :
1082 diag::warn_pragma_expected_section_push_pop_or_name;
1083 PP.
Diag(PragmaLocation, DiagID) << PragmaName;
1089 SegmentName = cast<StringLiteral>(StringResult.
get());
1091 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1099 if (Tok.
isNot(tok::r_paren)) {
1100 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1104 if (Tok.
isNot(tok::eof)) {
1105 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1111 SegmentName, PragmaName);
1116bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
1118 if (
getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) {
1119 PP.
Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target);
1123 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1131 StringRef Section = llvm::StringSwitch<StringRef>(II->
getName())
1132 .Case(
"compiler",
"\".CRT$XCC\"")
1133 .Case(
"lib",
"\".CRT$XCL\"")
1134 .Case(
"user",
"\".CRT$XCU\"")
1137 if (!Section.empty()) {
1141 Toks[0].
setKind(tok::string_literal);
1149 }
else if (Tok.
is(tok::string_literal)) {
1153 SegmentName = cast<StringLiteral>(StringResult.
get());
1155 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1163 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName;
1167 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1169 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1180bool Parser::HandlePragmaMSStrictGuardStackCheck(
1182 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1187 if (Tok.
is(tok::identifier)) {
1189 if (PushPop ==
"push") {
1192 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_punc,
1195 }
else if (PushPop ==
"pop") {
1204 if (II && II->
isStr(
"off")) {
1207 }
else if (II && II->
isStr(
"on")) {
1218 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1222 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1230bool Parser::HandlePragmaMSAllocText(StringRef PragmaName,
1232 Token FirstTok = Tok;
1233 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1238 if (Tok.
is(tok::string_literal)) {
1244 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1249 }
else if (Tok.
is(tok::identifier)) {
1253 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1258 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
1264 if (Tok.
isNot(tok::identifier)) {
1274 if (Tok.
isNot(tok::comma))
1279 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1281 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1291 std::string ClangLoopStr(
"clang loop ");
1294 return std::string(llvm::StringSwitch<StringRef>(Str)
1295 .Case(
"loop", ClangLoopStr)
1296 .Case(
"unroll_and_jam", Str)
1297 .Case(
"unroll", Str)
1301bool Parser::HandlePragmaLoopHint(
LoopHint &Hint) {
1302 assert(Tok.
is(tok::annot_pragma_loop_hint));
1322 auto IsLoopHint = llvm::StringSwitch<bool>(PragmaNameInfo->
getName())
1323 .Cases(
"unroll",
"nounroll",
"unroll_and_jam",
1324 "nounroll_and_jam",
true)
1327 if (Toks.empty() && IsLoopHint) {
1328 ConsumeAnnotationToken();
1335 assert(!Toks.empty() &&
1336 "PragmaLoopHintInfo::Toks must contain at least one token.");
1339 bool OptionUnroll =
false;
1340 bool OptionUnrollAndJam =
false;
1341 bool OptionDistribute =
false;
1342 bool OptionPipelineDisabled =
false;
1343 bool StateOption =
false;
1345 OptionUnroll = OptionInfo->
isStr(
"unroll");
1346 OptionUnrollAndJam = OptionInfo->
isStr(
"unroll_and_jam");
1347 OptionDistribute = OptionInfo->
isStr(
"distribute");
1348 OptionPipelineDisabled = OptionInfo->
isStr(
"pipeline");
1349 StateOption = llvm::StringSwitch<bool>(OptionInfo->
getName())
1350 .Case(
"vectorize",
true)
1351 .Case(
"interleave",
true)
1352 .Case(
"vectorize_predicate",
true)
1354 OptionUnroll || OptionUnrollAndJam || OptionDistribute ||
1355 OptionPipelineDisabled;
1358 bool AssumeSafetyArg = !OptionUnroll && !OptionUnrollAndJam &&
1359 !OptionDistribute && !OptionPipelineDisabled;
1361 if (Toks[0].is(tok::eof)) {
1362 ConsumeAnnotationToken();
1363 Diag(Toks[0].getLocation(), diag::err_pragma_loop_missing_argument)
1365 << (OptionUnroll || OptionUnrollAndJam)
1372 ConsumeAnnotationToken();
1376 bool Valid = StateInfo &&
1377 llvm::StringSwitch<bool>(StateInfo->
getName())
1378 .Case(
"disable",
true)
1379 .Case(
"enable", !OptionPipelineDisabled)
1380 .Case(
"full", OptionUnroll || OptionUnrollAndJam)
1381 .Case(
"assume_safety", AssumeSafetyArg)
1384 if (OptionPipelineDisabled) {
1385 Diag(Toks[0].getLocation(), diag::err_pragma_pipeline_invalid_keyword);
1387 Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword)
1388 << (OptionUnroll || OptionUnrollAndJam)
1393 if (Toks.size() > 2)
1397 }
else if (OptionInfo && OptionInfo->
getName() ==
"vectorize_width") {
1398 PP.EnterTokenStream(Toks,
false,
1400 ConsumeAnnotationToken();
1404 StringRef IsScalableStr = StateInfo ? StateInfo->
getName() :
"";
1407 if (IsScalableStr ==
"scalable" || IsScalableStr ==
"fixed") {
1410 if (Toks.size() > 2) {
1413 while (Tok.
isNot(tok::eof))
1426 Diag(Toks[0].getLocation(),
1427 diag::note_pragma_loop_invalid_vectorize_option);
1429 bool Arg2Error =
false;
1430 if (Tok.
is(tok::comma)) {
1434 IsScalableStr = StateInfo->
getName();
1436 if (IsScalableStr !=
"scalable" && IsScalableStr !=
"fixed") {
1438 diag::err_pragma_loop_invalid_vectorize_option);
1449 if (Tok.
isNot(tok::eof)) {
1452 while (Tok.
isNot(tok::eof))
1467 PP.EnterTokenStream(Toks,
false,
1469 ConsumeAnnotationToken();
1474 if (Tok.
isNot(tok::eof)) {
1477 while (Tok.
isNot(tok::eof))
1492 Info->
Toks.back().getLocation());
1497struct PragmaAttributeInfo {
1498 enum ActionType { Push,
Pop, Attribute };
1504 PragmaAttributeInfo(
ParsedAttributes &Attributes) : Attributes(Attributes) {}
1507#include "clang/Parse/AttrSubMatchRulesParserStringSwitches.inc"
1512 if (Tok.
is(tok::identifier))
1521 using namespace attr;
1523#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract) \
1526#include "clang/Basic/AttrSubMatchRulesList.inc"
1528 llvm_unreachable(
"Invalid attribute subject match rule");
1536 PRef.
Diag(SubRuleLoc,
1537 diag::err_pragma_attribute_expected_subject_sub_identifier)
1539 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1550 PRef.
Diag(SubRuleLoc, diag::err_pragma_attribute_unknown_subject_sub_rule)
1551 << SubRuleName << PrimaryRuleName;
1552 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1558bool Parser::ParsePragmaAttributeSubjectMatchRuleSet(
1566 if (AnyParens.expectAndConsume())
1574 Diag(Tok, diag::err_pragma_attribute_expected_subject_identifier);
1577 std::pair<std::optional<attr::SubjectMatchRule>,
1578 std::optional<attr::SubjectMatchRule> (*)(StringRef,
bool)>
1579 Rule = isAttributeSubjectMatchRule(Name);
1581 Diag(Tok, diag::err_pragma_attribute_unknown_subject_rule) << Name;
1589 if (Parens.expectAndConsume())
1591 }
else if (Parens.consumeOpen()) {
1592 if (!SubjectMatchRules
1594 std::make_pair(PrimaryRule,
SourceRange(RuleLoc, RuleLoc)))
1596 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1599 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleLoc));
1600 LastMatchRuleEndLoc = RuleLoc;
1606 if (SubRuleName.empty()) {
1612 if (SubRuleName ==
"unless") {
1615 if (Parens.expectAndConsume())
1618 if (SubRuleName.empty()) {
1623 auto SubRuleOrNone = Rule.second(SubRuleName,
true);
1624 if (!SubRuleOrNone) {
1625 std::string SubRuleUnlessName =
"unless(" + SubRuleName.str() +
")";
1627 SubRuleUnlessName, SubRuleLoc);
1630 SubRule = *SubRuleOrNone;
1632 if (Parens.consumeClose())
1635 auto SubRuleOrNone = Rule.second(SubRuleName,
false);
1636 if (!SubRuleOrNone) {
1641 SubRule = *SubRuleOrNone;
1645 LastMatchRuleEndLoc = RuleEndLoc;
1646 if (Parens.consumeClose())
1648 if (!SubjectMatchRules
1649 .insert(std::make_pair(SubRule,
SourceRange(RuleLoc, RuleEndLoc)))
1651 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1654 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleEndLoc));
1660 if (AnyParens.consumeClose())
1669enum class MissingAttributeSubjectRulesRecoveryPoint {
1677MissingAttributeSubjectRulesRecoveryPoint
1678getAttributeSubjectRulesRecoveryPointForToken(
const Token &Tok) {
1680 if (II->
isStr(
"apply_to"))
1681 return MissingAttributeSubjectRulesRecoveryPoint::ApplyTo;
1682 if (II->
isStr(
"any"))
1683 return MissingAttributeSubjectRulesRecoveryPoint::Any;
1685 if (Tok.
is(tok::equal))
1686 return MissingAttributeSubjectRulesRecoveryPoint::Equals;
1687 return MissingAttributeSubjectRulesRecoveryPoint::None;
1695 MissingAttributeSubjectRulesRecoveryPoint Point,
Parser &PRef) {
1701 MissingAttributeSubjectRulesRecoveryPoint EndPoint =
1702 getAttributeSubjectRulesRecoveryPointForToken(PRef.
getCurToken());
1703 if (Point == MissingAttributeSubjectRulesRecoveryPoint::Comma)
1705 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::ApplyTo &&
1706 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::ApplyTo)
1707 FixIt +=
"apply_to";
1708 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::Equals &&
1709 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::Equals)
1712 if (EndPoint == MissingAttributeSubjectRulesRecoveryPoint::None) {
1719 Attribute.getMatchRules(PRef.
getLangOpts(), MatchRules);
1721 for (
const auto &Rule : MatchRules) {
1726 IsSupported[Rule.first] =
true;
1728 IsMatchRuleAvailable &= IsSupported;
1730 if (IsMatchRuleAvailable.count() == 0) {
1736 bool NeedsComma =
false;
1738 if (!IsMatchRuleAvailable[I])
1752 if (FixItRange.getBegin() == FixItRange.getEnd())
1762void Parser::HandlePragmaAttribute() {
1763 assert(Tok.
is(tok::annot_pragma_attribute) &&
1764 "Expected #pragma attribute annotation token");
1767 if (Info->Action == PragmaAttributeInfo::Pop) {
1768 ConsumeAnnotationToken();
1773 assert((Info->Action == PragmaAttributeInfo::Push ||
1774 Info->Action == PragmaAttributeInfo::Attribute) &&
1775 "Unexpected #pragma attribute command");
1777 if (Info->Action == PragmaAttributeInfo::Push && Info->Tokens.empty()) {
1778 ConsumeAnnotationToken();
1783 PP.EnterTokenStream(Info->Tokens,
false,
1785 ConsumeAnnotationToken();
1790 auto SkipToEnd = [
this]() {
1795 if (Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) {
1797 ParseCXX11AttributeSpecifier(Attrs);
1798 }
else if (Tok.
is(tok::kw___attribute)) {
1800 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
1803 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"("))
1808 if (Tok.
is(tok::code_completion)) {
1817 if (Tok.
isNot(tok::identifier)) {
1818 Diag(Tok, diag::err_pragma_attribute_expected_attribute_name);
1825 if (Tok.
isNot(tok::l_paren))
1826 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1829 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs,
nullptr,
1835 if (ExpectAndConsume(tok::r_paren))
1837 if (ExpectAndConsume(tok::r_paren))
1839 }
else if (Tok.
is(tok::kw___declspec)) {
1840 ParseMicrosoftDeclSpecs(Attrs);
1842 Diag(Tok, diag::err_pragma_attribute_expected_attribute_syntax);
1851 if (Tok.
is(tok::l_paren)) {
1854 if (Tok.
isNot(tok::r_paren))
1857 Diag(Tok, diag::note_pragma_attribute_use_attribute_kw)
1866 if (Attrs.
empty() || Attrs.
begin()->isInvalid()) {
1872 if (!Attribute.isSupportedByPragmaAttribute()) {
1873 Diag(PragmaLoc, diag::err_pragma_attribute_unsupported_attribute)
1882 createExpectedAttributeSubjectRulesTokenDiagnostic(
1883 diag::err_expected, Attrs,
1884 MissingAttributeSubjectRulesRecoveryPoint::Comma, *
this)
1890 if (Tok.
isNot(tok::identifier)) {
1891 createExpectedAttributeSubjectRulesTokenDiagnostic(
1892 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
1893 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
1898 if (!II->
isStr(
"apply_to")) {
1899 createExpectedAttributeSubjectRulesTokenDiagnostic(
1900 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
1901 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
1908 createExpectedAttributeSubjectRulesTokenDiagnostic(
1909 diag::err_expected, Attrs,
1910 MissingAttributeSubjectRulesRecoveryPoint::Equals, *
this)
1918 if (ParsePragmaAttributeSubjectMatchRuleSet(SubjectMatchRules, AnyLoc,
1919 LastMatchRuleEndLoc)) {
1926 if (Tok.
isNot(tok::eof)) {
1927 Diag(Tok, diag::err_pragma_attribute_extra_tokens_after_attribute);
1936 if (Info->Action == PragmaAttributeInfo::Push)
1948void PragmaGCCVisibilityHandler::HandlePragma(
Preprocessor &PP,
1959 if (PushPop && PushPop->
isStr(
"pop")) {
1961 }
else if (PushPop && PushPop->
isStr(
"push")) {
1963 if (Tok.
isNot(tok::l_paren)) {
1976 if (Tok.
isNot(tok::r_paren)) {
1988 if (Tok.
isNot(tok::eod)) {
1994 auto Toks = std::make_unique<Token[]>(1);
1995 Toks[0].startToken();
1996 Toks[0].setKind(tok::annot_pragma_vis);
1997 Toks[0].setLocation(VisLoc);
1998 Toks[0].setAnnotationEndLoc(EndLoc);
1999 Toks[0].setAnnotationValue(
2000 const_cast<void *
>(
static_cast<const void *
>(VisType)));
2001 PP.EnterTokenStream(std::move(Toks), 1,
true,
2016 if (Tok.
isNot(tok::l_paren)) {
2017 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"pack";
2022 StringRef SlotLabel;
2026 if (Tok.
is(tok::numeric_constant)) {
2037 }
else if (Tok.
is(tok::identifier)) {
2039 if (II->
isStr(
"show")) {
2043 if (II->
isStr(
"push")) {
2045 }
else if (II->
isStr(
"pop")) {
2048 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_invalid_action) <<
"pack";
2053 if (Tok.
is(tok::comma)) {
2056 if (Tok.
is(tok::numeric_constant)) {
2061 }
else if (Tok.
is(tok::identifier)) {
2065 if (Tok.
is(tok::comma)) {
2068 if (Tok.
isNot(tok::numeric_constant)) {
2093 if (Tok.
isNot(tok::r_paren)) {
2094 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"pack";
2100 if (Tok.
isNot(tok::eod)) {
2101 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"pack";
2113 Toks[0].startToken();
2114 Toks[0].setKind(tok::annot_pragma_pack);
2115 Toks[0].setLocation(PackLoc);
2116 Toks[0].setAnnotationEndLoc(RParenLoc);
2117 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2118 PP.EnterTokenStream(Toks,
true,
2124void PragmaMSStructHandler::HandlePragma(
Preprocessor &PP,
2126 Token &MSStructTok) {
2131 if (Tok.
isNot(tok::identifier)) {
2137 if (II->
isStr(
"on")) {
2141 else if (II->
isStr(
"off") || II->
isStr(
"reset"))
2148 if (Tok.
isNot(tok::eod)) {
2156 Toks[0].startToken();
2157 Toks[0].setKind(tok::annot_pragma_msstruct);
2159 Toks[0].setAnnotationEndLoc(EndLoc);
2160 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2162 PP.EnterTokenStream(Toks,
true,
2167void PragmaClangSectionHandler::HandlePragma(
Preprocessor &PP,
2169 Token &FirstToken) {
2175 while (Tok.
isNot(tok::eod)) {
2176 if (Tok.
isNot(tok::identifier)) {
2177 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2182 if (SecType->
isStr(
"bss"))
2184 else if (SecType->
isStr(
"data"))
2186 else if (SecType->
isStr(
"rodata"))
2188 else if (SecType->
isStr(
"relro"))
2190 else if (SecType->
isStr(
"text"))
2193 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2199 if (Tok.
isNot(tok::equal)) {
2200 PP.
Diag(Tok.
getLocation(), diag::err_pragma_clang_section_expected_equal) << SecKind;
2204 std::string SecName;
2208 Actions.ActOnPragmaClangSection(
2225 if (Tok.
isNot(tok::identifier) ||
2234 if (Tok.
isNot(tok::l_paren)) {
2235 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"align";
2238 }
else if (Tok.
isNot(tok::equal)) {
2245 if (Tok.
isNot(tok::identifier)) {
2247 << (IsOptions ?
"options" :
"align");
2253 if (II->
isStr(
"native"))
2255 else if (II->
isStr(
"natural"))
2257 else if (II->
isStr(
"packed"))
2259 else if (II->
isStr(
"power"))
2261 else if (II->
isStr(
"mac68k"))
2263 else if (II->
isStr(
"reset"))
2273 if (Tok.
isNot(tok::r_paren)) {
2274 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"align";
2281 if (Tok.
isNot(tok::eod)) {
2283 << (IsOptions ?
"options" :
"align");
2289 Toks[0].startToken();
2290 Toks[0].setKind(tok::annot_pragma_align);
2292 Toks[0].setAnnotationEndLoc(EndLoc);
2293 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2295 PP.EnterTokenStream(Toks,
true,
2305void PragmaOptionsHandler::HandlePragma(
Preprocessor &PP,
2307 Token &OptionsTok) {
2312void PragmaUnusedHandler::HandlePragma(
Preprocessor &PP,
2321 if (Tok.
isNot(tok::l_paren)) {
2322 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"unused";
2335 if (Tok.
is(tok::identifier)) {
2336 Identifiers.push_back(Tok);
2347 if (Tok.
is(tok::comma)) {
2352 if (Tok.
is(tok::r_paren)) {
2358 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_punc) <<
"unused";
2363 if (Tok.
isNot(tok::eod)) {
2370 assert(RParenLoc.
isValid() &&
"Valid '#pragma unused' must have ')'");
2371 assert(!Identifiers.empty() &&
"Valid '#pragma unused' must have arguments");
2380 2 * Identifiers.size());
2381 for (
unsigned i=0; i != Identifiers.size(); i++) {
2382 Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
2384 pragmaUnusedTok.
setKind(tok::annot_pragma_unused);
2386 idTok = Identifiers[i];
2388 PP.EnterTokenStream(Toks,
true,
2401 if (Tok.
isNot(tok::identifier)) {
2402 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_identifier) <<
"weak";
2406 Token WeakName = Tok;
2407 bool HasAlias =
false;
2411 if (Tok.
is(tok::equal)) {
2414 if (Tok.
isNot(tok::identifier)) {
2423 if (Tok.
isNot(tok::eod)) {
2424 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"weak";
2431 Token &pragmaUnusedTok = Toks[0];
2433 pragmaUnusedTok.
setKind(tok::annot_pragma_weakalias);
2437 Toks[2] = AliasName;
2438 PP.EnterTokenStream(Toks,
true,
2443 Token &pragmaUnusedTok = Toks[0];
2445 pragmaUnusedTok.
setKind(tok::annot_pragma_weak);
2449 PP.EnterTokenStream(Toks,
true,
2455void PragmaRedefineExtnameHandler::HandlePragma(
Preprocessor &PP,
2457 Token &RedefToken) {
2462 if (Tok.
isNot(tok::identifier)) {
2468 Token RedefName = Tok;
2471 if (Tok.
isNot(tok::identifier)) {
2473 <<
"redefine_extname";
2477 Token AliasName = Tok;
2480 if (Tok.
isNot(tok::eod)) {
2488 Token &pragmaRedefTok = Toks[0];
2490 pragmaRedefTok.
setKind(tok::annot_pragma_redefine_extname);
2493 Toks[1] = RedefName;
2494 Toks[2] = AliasName;
2495 PP.EnterTokenStream(Toks,
true,
2499void PragmaFPContractHandler::HandlePragma(
Preprocessor &PP,
2508 Toks[0].startToken();
2509 Toks[0].setKind(tok::annot_pragma_fp_contract);
2512 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2514 PP.EnterTokenStream(Toks,
true,
2518void PragmaOpenCLExtensionHandler::HandlePragma(
Preprocessor &PP,
2522 if (Tok.
isNot(tok::identifier)) {
2531 if (Tok.
isNot(tok::colon)) {
2537 if (Tok.
isNot(tok::identifier)) {
2538 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_predicate) << 0;
2543 OpenCLExtState State;
2544 if (Pred->
isStr(
"enable")) {
2546 }
else if (Pred->
isStr(
"disable")) {
2548 }
else if (Pred->
isStr(
"begin"))
2550 else if (Pred->
isStr(
"end"))
2554 << Ext->
isStr(
"all");
2560 if (Tok.
isNot(tok::eod)) {
2568 Info->second = State;
2571 Toks[0].startToken();
2572 Toks[0].setKind(tok::annot_pragma_opencl_extension);
2573 Toks[0].setLocation(NameLoc);
2574 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2575 Toks[0].setAnnotationEndLoc(StateLoc);
2576 PP.EnterTokenStream(Toks,
true,
2586void PragmaNoOpenMPHandler::HandlePragma(
Preprocessor &PP,
2591 PP.
Diag(FirstTok, diag::warn_pragma_omp_ignored);
2600void PragmaOpenMPHandler::HandlePragma(
Preprocessor &PP,
2606 Tok.
setKind(tok::annot_pragma_openmp);
2609 while (Tok.
isNot(tok::eod) && Tok.
isNot(tok::eof)) {
2610 Pragma.push_back(Tok);
2612 if (Tok.
is(tok::annot_pragma_openmp)) {
2613 PP.
Diag(Tok, diag::err_omp_unexpected_directive) << 0;
2614 unsigned InnerPragmaCnt = 1;
2615 while (InnerPragmaCnt != 0) {
2617 if (Tok.
is(tok::annot_pragma_openmp))
2619 else if (Tok.
is(tok::annot_pragma_openmp_end))
2627 Tok.
setKind(tok::annot_pragma_openmp_end);
2629 Pragma.push_back(Tok);
2631 auto Toks = std::make_unique<Token[]>(Pragma.size());
2632 std::copy(Pragma.begin(), Pragma.end(), Toks.get());
2633 PP.EnterTokenStream(std::move(Toks), Pragma.size(),
2645void PragmaMSPointersToMembers::HandlePragma(
Preprocessor &PP,
2650 if (Tok.
isNot(tok::l_paren)) {
2651 PP.
Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen)
2652 <<
"pointers_to_members";
2659 <<
"pointers_to_members";
2665 if (Arg->
isStr(
"best_case")) {
2668 if (Arg->
isStr(
"full_generality")) {
2669 if (Tok.
is(tok::comma)) {
2675 diag::err_pragma_pointers_to_members_unknown_kind)
2680 }
else if (Tok.
is(tok::r_paren)) {
2687 <<
"full_generality";
2693 if (Arg->
isStr(
"single_inheritance")) {
2694 RepresentationMethod =
2696 }
else if (Arg->
isStr(
"multiple_inheritance")) {
2697 RepresentationMethod =
2699 }
else if (Arg->
isStr(
"virtual_inheritance")) {
2700 RepresentationMethod =
2704 diag::err_pragma_pointers_to_members_unknown_kind)
2711 if (Tok.
isNot(tok::r_paren)) {
2713 << (Arg ? Arg->
getName() :
"full_generality");
2719 if (Tok.
isNot(tok::eod)) {
2721 <<
"pointers_to_members";
2727 AnnotTok.
setKind(tok::annot_pragma_ms_pointers_to_members);
2731 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RepresentationMethod)));
2747 if (Tok.
isNot(tok::l_paren)) {
2748 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) <<
"vtordisp";
2756 if (II->
isStr(
"push")) {
2759 if (Tok.
isNot(tok::comma)) {
2760 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_punc) <<
"vtordisp";
2766 }
else if (II->
isStr(
"pop")) {
2773 if (Tok.
is(tok::r_paren)) {
2783 if (II && II->
isStr(
"off")) {
2786 }
else if (II && II->
isStr(
"on")) {
2789 }
else if (Tok.
is(tok::numeric_constant) &&
2793 << 0 << 2 <<
"vtordisp";
2804 if (Tok.
isNot(tok::r_paren)) {
2805 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) <<
"vtordisp";
2810 if (Tok.
isNot(tok::eod)) {
2819 AnnotTok.
setKind(tok::annot_pragma_ms_vtordisp);
2831 Token EoF, AnnotTok;
2835 AnnotTok.
setKind(tok::annot_pragma_ms_pragma);
2840 for (; Tok.
isNot(tok::eod); PP.
Lex(Tok)) {
2841 TokenVector.push_back(Tok);
2845 TokenVector.push_back(EoF);
2848 markAsReinjectedForRelexing(TokenVector);
2849 auto TokenArray = std::make_unique<Token[]>(TokenVector.size());
2850 std::copy(TokenVector.begin(), TokenVector.end(), TokenArray.get());
2852 std::pair<std::unique_ptr<
Token[]>,
size_t>(std::move(TokenArray),
2853 TokenVector.size());
2869void PragmaFloatControlHandler::HandlePragma(
Preprocessor &PP,
2874 Token PragmaName = Tok;
2881 if (Tok.
isNot(tok::l_paren)) {
2882 PP.
Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
2888 if (Tok.
isNot(tok::identifier)) {
2896 llvm::StringSwitch<PragmaFloatControlKind>(II->
getName())
2907 if (Tok.
isNot(tok::r_paren)) {
2914 if (Tok.
is(tok::r_paren))
2917 else if (Tok.
isNot(tok::comma)) {
2927 if (PushOnOff ==
"on")
2930 else if (PushOnOff ==
"off") {
2935 }
else if (PushOnOff ==
"push") {
2942 if (Tok.
is(tok::comma)) {
2949 if (ExpectedPush ==
"push") {
2957 if (Tok.
isNot(tok::r_paren)) {
2965 if (Tok.
isNot(tok::eod)) {
2974 auto TokenArray = std::make_unique<Token[]>(1);
2975 TokenArray[0].startToken();
2976 TokenArray[0].setKind(tok::annot_pragma_float_control);
2977 TokenArray[0].setLocation(FloatControlLoc);
2978 TokenArray[0].setAnnotationEndLoc(EndLoc);
2981 TokenArray[0].setAnnotationValue(
reinterpret_cast<void *
>(
2982 static_cast<uintptr_t>((Action << 16) | (Kind & 0xFFFF))));
2983 PP.EnterTokenStream(std::move(TokenArray), 1,
2997void PragmaDetectMismatchHandler::HandlePragma(
Preprocessor &PP,
3002 if (Tok.
isNot(tok::l_paren)) {
3003 PP.
Diag(DetectMismatchLoc, diag::err_expected) << tok::l_paren;
3008 std::string NameString;
3010 "pragma detect_mismatch",
3015 std::string ValueString;
3016 if (Tok.
isNot(tok::comma)) {
3017 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3025 if (Tok.
isNot(tok::r_paren)) {
3031 if (Tok.
isNot(tok::eod)) {
3032 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3041 Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString);
3053void PragmaCommentHandler::HandlePragma(
Preprocessor &PP,
3058 if (Tok.
isNot(tok::l_paren)) {
3059 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3065 if (Tok.
isNot(tok::identifier)) {
3066 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3073 llvm::StringSwitch<PragmaMSCommentKind>(II->
getName())
3093 std::string ArgumentString;
3106 if (Tok.
isNot(tok::r_paren)) {
3112 if (Tok.
isNot(tok::eod)) {
3121 Actions.ActOnPragmaMSComment(CommentLoc, Kind, ArgumentString);
3126void PragmaOptimizeHandler::HandlePragma(
Preprocessor &PP,
3128 Token &FirstToken) {
3131 if (Tok.
is(tok::eod)) {
3133 <<
"clang optimize" <<
true <<
"'on' or 'off'";
3136 if (Tok.
isNot(tok::identifier)) {
3137 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3144 if (II->
isStr(
"on")) {
3146 }
else if (!II->
isStr(
"off")) {
3147 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3153 if (Tok.
isNot(tok::eod)) {
3159 Actions.ActOnPragmaOptimize(IsOn, FirstToken.
getLocation());
3164struct TokFPAnnotValue {
3165 enum FlagKinds { Contract, Reassociate, Exceptions, EvalMethod };
3166 enum FlagValues { On, Off, Fast };
3168 std::optional<LangOptions::FPModeKind> ContractValue;
3169 std::optional<LangOptions::FPModeKind> ReassociateValue;
3170 std::optional<LangOptions::FPExceptionModeKind> ExceptionsValue;
3171 std::optional<LangOptions::FPEvalMethodKind> EvalMethodValue;
3178 Token PragmaName = Tok;
3182 if (Tok.
isNot(tok::identifier)) {
3189 while (Tok.
is(tok::identifier)) {
3193 llvm::StringSwitch<std::optional<TokFPAnnotValue::FlagKinds>>(
3195 .Case(
"contract", TokFPAnnotValue::Contract)
3196 .Case(
"reassociate", TokFPAnnotValue::Reassociate)
3197 .Case(
"exceptions", TokFPAnnotValue::Exceptions)
3198 .Case(
"eval_method", TokFPAnnotValue::EvalMethod)
3199 .Default(std::nullopt);
3202 <<
false << OptionInfo;
3208 if (Tok.
isNot(tok::l_paren)) {
3213 bool isEvalMethodDouble =
3214 Tok.
is(tok::kw_double) && FlagKind == TokFPAnnotValue::EvalMethod;
3217 if (Tok.
isNot(tok::identifier) && !isEvalMethodDouble) {
3220 <<
static_cast<int>(*FlagKind);
3225 if (FlagKind == TokFPAnnotValue::Contract) {
3226 AnnotValue->ContractValue =
3227 llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3232 .Default(std::nullopt);
3233 if (!AnnotValue->ContractValue) {
3238 }
else if (FlagKind == TokFPAnnotValue::Reassociate) {
3239 AnnotValue->ReassociateValue =
3240 llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3244 .Default(std::nullopt);
3245 if (!AnnotValue->ReassociateValue) {
3250 }
else if (FlagKind == TokFPAnnotValue::Exceptions) {
3251 AnnotValue->ExceptionsValue =
3252 llvm::StringSwitch<std::optional<LangOptions::FPExceptionModeKind>>(
3257 .Default(std::nullopt);
3258 if (!AnnotValue->ExceptionsValue) {
3263 }
else if (FlagKind == TokFPAnnotValue::EvalMethod) {
3264 AnnotValue->EvalMethodValue =
3265 llvm::StringSwitch<std::optional<LangOptions::FPEvalMethodKind>>(
3270 .Default(std::nullopt);
3271 if (!AnnotValue->EvalMethodValue) {
3280 if (Tok.
isNot(tok::r_paren)) {
3287 if (Tok.
isNot(tok::eod)) {
3295 FPTok.
setKind(tok::annot_pragma_fp);
3299 TokenList.push_back(FPTok);
3301 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3302 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3304 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3308void PragmaSTDC_FENV_ROUNDHandler::HandlePragma(
Preprocessor &PP,
3311 Token PragmaName = Tok;
3320 if (Tok.
isNot(tok::identifier)) {
3328 llvm::StringSwitch<llvm::RoundingMode>(II->
getName())
3329 .Case(
"FE_TOWARDZERO", llvm::RoundingMode::TowardZero)
3330 .Case(
"FE_TONEAREST", llvm::RoundingMode::NearestTiesToEven)
3331 .Case(
"FE_UPWARD", llvm::RoundingMode::TowardPositive)
3332 .Case(
"FE_DOWNWARD", llvm::RoundingMode::TowardNegative)
3333 .Case(
"FE_TONEARESTFROMZERO", llvm::RoundingMode::NearestTiesToAway)
3334 .Case(
"FE_DYNAMIC", llvm::RoundingMode::Dynamic)
3335 .Default(llvm::RoundingMode::Invalid);
3336 if (RM == llvm::RoundingMode::Invalid) {
3342 if (Tok.
isNot(tok::eod)) {
3344 <<
"STDC FENV_ROUND";
3353 Toks[0].startToken();
3354 Toks[0].setKind(tok::annot_pragma_fenv_round);
3357 Toks[0].setAnnotationValue(
3358 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RM)));
3359 PP.EnterTokenStream(Toks,
true,
3363void Parser::HandlePragmaFP() {
3364 assert(Tok.
is(tok::annot_pragma_fp));
3368 if (AnnotValue->ReassociateValue)
3370 *AnnotValue->ReassociateValue ==
3372 if (AnnotValue->ContractValue)
3374 *AnnotValue->ContractValue);
3375 if (AnnotValue->ExceptionsValue)
3377 *AnnotValue->ExceptionsValue);
3378 if (AnnotValue->EvalMethodValue)
3380 *AnnotValue->EvalMethodValue);
3381 ConsumeAnnotationToken();
3386 Token Option,
bool ValueInParens,
3389 int OpenParens = ValueInParens ? 1 : 0;
3391 while (Tok.
isNot(tok::eod)) {
3392 if (Tok.
is(tok::l_paren))
3394 else if (Tok.
is(tok::r_paren)) {
3396 if (OpenParens == 0 && ValueInParens)
3404 if (ValueInParens) {
3406 if (Tok.
isNot(tok::r_paren)) {
3475void PragmaLoopHintHandler::HandlePragma(
Preprocessor &PP,
3479 Token PragmaName = Tok;
3484 if (Tok.
isNot(tok::identifier)) {
3490 while (Tok.
is(tok::identifier)) {
3494 bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->
getName())
3495 .Case(
"vectorize",
true)
3496 .Case(
"interleave",
true)
3497 .Case(
"unroll",
true)
3498 .Case(
"distribute",
true)
3499 .Case(
"vectorize_predicate",
true)
3500 .Case(
"vectorize_width",
true)
3501 .Case(
"interleave_count",
true)
3502 .Case(
"unroll_count",
true)
3503 .Case(
"pipeline",
true)
3504 .Case(
"pipeline_initiation_interval",
true)
3508 <<
false << OptionInfo;
3514 if (Tok.
isNot(tok::l_paren)) {
3528 LoopHintTok.
setKind(tok::annot_pragma_loop_hint);
3532 TokenList.push_back(LoopHintTok);
3535 if (Tok.
isNot(tok::eod)) {
3541 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3542 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3544 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3569void PragmaUnrollHintHandler::HandlePragma(
Preprocessor &PP,
3574 Token PragmaName = Tok;
3577 if (Tok.
is(tok::eod)) {
3579 Info->PragmaName = PragmaName;
3580 Info->Option.startToken();
3590 bool ValueInParens = Tok.
is(tok::l_paren);
3602 PP.
Diag(Info->Toks[0].getLocation(),
3603 diag::warn_pragma_unroll_cuda_value_in_parens);
3605 if (Tok.
isNot(tok::eod)) {
3613 auto TokenArray = std::make_unique<Token[]>(1);
3614 TokenArray[0].startToken();
3615 TokenArray[0].setKind(tok::annot_pragma_loop_hint);
3616 TokenArray[0].setLocation(Introducer.
Loc);
3617 TokenArray[0].setAnnotationEndLoc(PragmaName.
getLocation());
3618 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
3619 PP.EnterTokenStream(std::move(TokenArray), 1,
3635void PragmaMSIntrinsicHandler::HandlePragma(
Preprocessor &PP,
3640 if (Tok.
isNot(tok::l_paren)) {
3649 while (Tok.
is(tok::identifier)) {
3653 << II << SuggestIntrinH;
3656 if (Tok.
isNot(tok::comma))
3661 if (Tok.
isNot(tok::r_paren)) {
3668 if (Tok.
isNot(tok::eod))
3673bool Parser::HandlePragmaMSFunction(StringRef PragmaName,
3675 Token FirstTok = Tok;
3677 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3684 while (Tok.
is(tok::identifier)) {
3688 << II << SuggestIntrinH;
3690 NoBuiltins.emplace_back(II->
getName());
3693 if (Tok.
isNot(tok::comma))
3698 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3700 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3709bool Parser::HandlePragmaMSOptimize(StringRef PragmaName,
3711 Token FirstTok = Tok;
3712 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3716 if (Tok.
isNot(tok::string_literal)) {
3717 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_string) << PragmaName;
3725 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
3730 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
3734 if (Tok.
is(tok::eof) || Tok.
is(tok::r_paren)) {
3735 PP.
Diag(PragmaLocation, diag::warn_pragma_missing_argument)
3736 << PragmaName <<
true <<
"'on' or 'off'";
3740 if (!II || (!II->
isStr(
"on") && !II->
isStr(
"off"))) {
3741 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3746 bool IsOn = II->
isStr(
"on");
3749 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3754 if (!OptimizationList->
getString().empty()) {
3755 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3756 << OptimizationList->
getString() << PragmaName <<
true
3761 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3769void PragmaForceCUDAHostDeviceHandler::HandlePragma(
3771 Token FirstTok = Tok;
3775 if (!Info || (!Info->
isStr(
"begin") && !Info->
isStr(
"end"))) {
3777 diag::warn_pragma_force_cuda_host_device_bad_arg);
3781 if (Info->
isStr(
"begin"))
3782 Actions.PushForceCUDAHostDevice();
3783 else if (!Actions.PopForceCUDAHostDevice())
3785 diag::err_pragma_cannot_end_force_cuda_host_device);
3788 if (!Tok.
is(tok::eod))
3790 diag::warn_pragma_force_cuda_host_device_bad_arg);
3820void PragmaAttributeHandler::HandlePragma(
Preprocessor &PP,
3822 Token &FirstToken) {
3826 PragmaAttributeInfo(AttributesForPragmaAttribute);
3829 if (Tok.
is(tok::identifier)) {
3831 if (!II->
isStr(
"push") && !II->
isStr(
"pop")) {
3832 Info->Namespace = II;
3835 if (!Tok.
is(tok::period)) {
3836 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_period)
3844 if (!Tok.
isOneOf(tok::identifier, tok::l_paren)) {
3846 diag::err_pragma_attribute_expected_push_pop_paren);
3851 if (Tok.
is(tok::l_paren)) {
3852 if (Info->Namespace) {
3854 diag::err_pragma_attribute_namespace_on_attribute);
3856 diag::note_pragma_attribute_namespace_on_attribute);
3859 Info->Action = PragmaAttributeInfo::Attribute;
3862 if (II->
isStr(
"push"))
3863 Info->Action = PragmaAttributeInfo::Push;
3865 Info->Action = PragmaAttributeInfo::Pop;
3867 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_invalid_argument)
3876 if ((Info->Action == PragmaAttributeInfo::Push && Tok.
isNot(tok::eod)) ||
3877 Info->Action == PragmaAttributeInfo::Attribute) {
3878 if (Tok.
isNot(tok::l_paren)) {
3887 while (Tok.
isNot(tok::eod)) {
3888 if (Tok.
is(tok::l_paren))
3890 else if (Tok.
is(tok::r_paren)) {
3892 if (OpenParens == 0)
3896 AttributeTokens.push_back(Tok);
3900 if (AttributeTokens.empty()) {
3901 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_attribute);
3904 if (Tok.
isNot(tok::r_paren)) {
3916 AttributeTokens.push_back(EOFTok);
3918 markAsReinjectedForRelexing(AttributeTokens);
3923 if (Tok.
isNot(tok::eod))
3925 <<
"clang attribute";
3928 auto TokenArray = std::make_unique<Token[]>(1);
3929 TokenArray[0].startToken();
3930 TokenArray[0].setKind(tok::annot_pragma_attribute);
3931 TokenArray[0].setLocation(FirstToken.
getLocation());
3932 TokenArray[0].setAnnotationEndLoc(FirstToken.
getLocation());
3933 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
3934 PP.EnterTokenStream(std::move(TokenArray), 1,
3939void PragmaMaxTokensHereHandler::HandlePragma(
Preprocessor &PP,
3943 if (Tok.
is(tok::eod)) {
3945 <<
"clang max_tokens_here" <<
true <<
"integer";
3951 if (Tok.
isNot(tok::numeric_constant) ||
3954 <<
"clang max_tokens_here";
3958 if (Tok.
isNot(tok::eod)) {
3960 <<
"clang max_tokens_here";
3965 PP.
Diag(Loc, diag::warn_max_tokens)
3971void PragmaMaxTokensTotalHandler::HandlePragma(
Preprocessor &PP,
3975 if (Tok.
is(tok::eod)) {
3977 <<
"clang max_tokens_total" <<
true <<
"integer";
3983 if (Tok.
isNot(tok::numeric_constant) ||
3986 <<
"clang max_tokens_total";
3990 if (Tok.
isNot(tok::eod)) {
3992 <<
"clang max_tokens_total";
4002 Token &FirstToken) {
4007 if (!II || !II->
isStr(
"intrinsic")) {
4009 << PP.
getSpelling(Tok) <<
"riscv" <<
true <<
"'intrinsic'";
4015 if (!II || !II->
isStr(
"vector")) {
4017 << PP.
getSpelling(Tok) <<
"riscv" <<
true <<
"'vector'";
4022 if (Tok.
isNot(tok::eod)) {
4024 <<
"clang riscv intrinsic";
4028 Actions.DeclareRISCVVBuiltins =
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...
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.
@ FPE_Ignore
Assume that floating-point exceptions are masked.
@ FPE_MayTrap
Transformations do not cause new exceptions but may hide some.
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
@ FEM_Source
Use the declared type for fp arithmetic.
@ FEM_Double
Use the type double for fp arithmetic.
@ FEM_Extended
Use extended type for fp arithmetic.
PragmaMSPointersToMembersKind
@ PPTMK_FullGeneralityMultipleInheritance
@ PPTMK_FullGeneralityVirtualInheritance
@ PPTMK_FullGeneralitySingleInheritance
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::Syntax syntax, 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
@ 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 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 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)
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.
void ActOnPragmaFPReassociate(SourceLocation Loc, bool IsEnabled)
Called on well formed #pragma clang fp reassociate.
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
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'...
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
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.
__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