@@ -300,12 +300,6 @@ struct PragmaMSRuntimeChecksHandler : public EmptyPragmaHandler {
300
300
PragmaMSRuntimeChecksHandler () : EmptyPragmaHandler(" runtime_checks" ) {}
301
301
};
302
302
303
- struct PragmaMSIntrinsicHandler : public PragmaHandler {
304
- PragmaMSIntrinsicHandler () : PragmaHandler(" intrinsic" ) {}
305
- void HandlePragma (Preprocessor &PP, PragmaIntroducer Introducer,
306
- Token &FirstToken) override ;
307
- };
308
-
309
303
// "\#pragma fenv_access (on)".
310
304
struct PragmaMSFenvAccessHandler : public PragmaHandler {
311
305
PragmaMSFenvAccessHandler () : PragmaHandler(" fenv_access" ) {}
@@ -517,7 +511,7 @@ void Parser::initializePragmaHandlers() {
517
511
PP.AddPragmaHandler (MSOptimize.get ());
518
512
MSRuntimeChecks = std::make_unique<PragmaMSRuntimeChecksHandler>();
519
513
PP.AddPragmaHandler (MSRuntimeChecks.get ());
520
- MSIntrinsic = std::make_unique<PragmaMSIntrinsicHandler>( );
514
+ MSIntrinsic = std::make_unique<PragmaMSPragma>( " intrinsic " );
521
515
PP.AddPragmaHandler (MSIntrinsic.get ());
522
516
MSFenvAccess = std::make_unique<PragmaMSFenvAccessHandler>();
523
517
PP.AddPragmaHandler (MSFenvAccess.get ());
@@ -1046,7 +1040,8 @@ void Parser::HandlePragmaMSPragma() {
1046
1040
.Case (" strict_gs_check" , &Parser::HandlePragmaMSStrictGuardStackCheck)
1047
1041
.Case (" function" , &Parser::HandlePragmaMSFunction)
1048
1042
.Case (" alloc_text" , &Parser::HandlePragmaMSAllocText)
1049
- .Case (" optimize" , &Parser::HandlePragmaMSOptimize);
1043
+ .Case (" optimize" , &Parser::HandlePragmaMSOptimize)
1044
+ .Case (" intrinsic" , &Parser::HandlePragmaMSIntrinsic);
1050
1045
1051
1046
if (!(this ->*Handler)(PragmaName, PragmaLocation)) {
1052
1047
// Pragma handling failed, and has been diagnosed. Slurp up the tokens
@@ -3762,56 +3757,6 @@ void PragmaUnrollHintHandler::HandlePragma(Preprocessor &PP,
3762
3757
/* DisableMacroExpansion=*/ false , /* IsReinject=*/ false );
3763
3758
}
3764
3759
3765
- // / Handle the Microsoft \#pragma intrinsic extension.
3766
- // /
3767
- // / The syntax is:
3768
- // / \code
3769
- // / #pragma intrinsic(memset)
3770
- // / #pragma intrinsic(strlen, memcpy)
3771
- // / \endcode
3772
- // /
3773
- // / Pragma intrisic tells the compiler to use a builtin version of the
3774
- // / function. Clang does it anyway, so the pragma doesn't really do anything.
3775
- // / Anyway, we emit a warning if the function specified in \#pragma intrinsic
3776
- // / isn't an intrinsic in clang and suggest to include intrin.h.
3777
- void PragmaMSIntrinsicHandler::HandlePragma (Preprocessor &PP,
3778
- PragmaIntroducer Introducer,
3779
- Token &Tok) {
3780
- PP.Lex (Tok);
3781
-
3782
- if (Tok.isNot (tok::l_paren)) {
3783
- PP.Diag (Tok.getLocation (), diag::warn_pragma_expected_lparen)
3784
- << " intrinsic" ;
3785
- return ;
3786
- }
3787
- PP.Lex (Tok);
3788
-
3789
- bool SuggestIntrinH = !PP.isMacroDefined (" __INTRIN_H" );
3790
-
3791
- while (Tok.is (tok::identifier)) {
3792
- IdentifierInfo *II = Tok.getIdentifierInfo ();
3793
- if (!II->getBuiltinID ())
3794
- PP.Diag (Tok.getLocation (), diag::warn_pragma_intrinsic_builtin)
3795
- << II << SuggestIntrinH;
3796
-
3797
- PP.Lex (Tok);
3798
- if (Tok.isNot (tok::comma))
3799
- break ;
3800
- PP.Lex (Tok);
3801
- }
3802
-
3803
- if (Tok.isNot (tok::r_paren)) {
3804
- PP.Diag (Tok.getLocation (), diag::warn_pragma_expected_rparen)
3805
- << " intrinsic" ;
3806
- return ;
3807
- }
3808
- PP.Lex (Tok);
3809
-
3810
- if (Tok.isNot (tok::eod))
3811
- PP.Diag (Tok.getLocation (), diag::warn_pragma_extra_tokens_at_eol)
3812
- << " intrinsic" ;
3813
- }
3814
-
3815
3760
bool Parser::HandlePragmaMSFunction (StringRef PragmaName,
3816
3761
SourceLocation PragmaLocation) {
3817
3762
Token FirstTok = Tok;
@@ -3907,6 +3852,56 @@ bool Parser::HandlePragmaMSOptimize(StringRef PragmaName,
3907
3852
return true ;
3908
3853
}
3909
3854
3855
+ // / Handle the Microsoft \#pragma intrinsic extension.
3856
+ // /
3857
+ // / The syntax is:
3858
+ // / \code
3859
+ // / #pragma intrinsic(memset)
3860
+ // / #pragma intrinsic(strlen, memcpy)
3861
+ // / \endcode
3862
+ // /
3863
+ // / Pragma intrisic tells the compiler to use a builtin version of the
3864
+ // / function. Clang does it anyway, so the pragma doesn't really do anything.
3865
+ // / Anyway, we emit a warning if the function specified in \#pragma intrinsic
3866
+ // / isn't an intrinsic in clang and suggest to include intrin.h, as well as
3867
+ // / declare the builtin if it has not been declared.
3868
+ bool Parser::HandlePragmaMSIntrinsic (StringRef PragmaName,
3869
+ SourceLocation PragmaLocation) {
3870
+ if (ExpectAndConsume (tok::l_paren, diag::warn_pragma_expected_lparen,
3871
+ PragmaName))
3872
+ return false ;
3873
+
3874
+ bool SuggestIntrinH = !PP.isMacroDefined (" __INTRIN_H" );
3875
+
3876
+ while (Tok.is (tok::identifier)) {
3877
+ IdentifierInfo *II = Tok.getIdentifierInfo ();
3878
+ if (!II->getBuiltinID ())
3879
+ PP.Diag (Tok.getLocation (), diag::warn_pragma_intrinsic_builtin)
3880
+ << II << SuggestIntrinH;
3881
+ // If the builtin hasn't already been declared, declare it now.
3882
+ DeclarationNameInfo NameInfo (II, Tok.getLocation ());
3883
+ LookupResult Previous (Actions, NameInfo, Sema::LookupOrdinaryName,
3884
+ RedeclarationKind::NotForRedeclaration);
3885
+ Actions.LookupName (Previous, Actions.getCurScope (),
3886
+ /* CreateBuiltins*/ false );
3887
+ if (Previous.empty ())
3888
+ Actions.LazilyCreateBuiltin (II, II->getBuiltinID (), Actions.getCurScope (),
3889
+ /* ForRedeclaration*/ true , Tok.getLocation ());
3890
+ PP.Lex (Tok);
3891
+ if (Tok.isNot (tok::comma))
3892
+ break ;
3893
+ PP.Lex (Tok);
3894
+ }
3895
+ if (ExpectAndConsume (tok::r_paren, diag::warn_pragma_expected_rparen,
3896
+ PragmaName))
3897
+ return false ;
3898
+
3899
+ if (ExpectAndConsume (tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3900
+ PragmaName))
3901
+ return false ;
3902
+ return true ;
3903
+ }
3904
+
3910
3905
void PragmaForceCUDAHostDeviceHandler::HandlePragma (
3911
3906
Preprocessor &PP, PragmaIntroducer Introducer, Token &Tok) {
3912
3907
Token FirstTok = Tok;
0 commit comments