Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 1 | //===--- ParsePragma.cpp - Language specific pragma parsing ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the language specific #pragma handlers. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 14 | #include "RAIIObjectsForParser.h" |
Hans Wennborg | 899ded9 | 2014-10-16 20:52:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
David Majnemer | ad2986e | 2014-08-14 06:35:08 +0000 | [diff] [blame] | 16 | #include "clang/Basic/TargetInfo.h" |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 17 | #include "clang/Lex/Preprocessor.h" |
| 18 | #include "clang/Parse/ParseDiagnostic.h" |
| 19 | #include "clang/Parse/Parser.h" |
| 20 | #include "clang/Sema/LoopHint.h" |
| 21 | #include "clang/Sema/Scope.h" |
| 22 | #include "llvm/ADT/StringSwitch.h" |
| 23 | using namespace clang; |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 24 | |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 25 | namespace { |
| 26 | |
| 27 | struct PragmaAlignHandler : public PragmaHandler { |
| 28 | explicit PragmaAlignHandler() : PragmaHandler("align") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 29 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 30 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | struct PragmaGCCVisibilityHandler : public PragmaHandler { |
| 34 | explicit PragmaGCCVisibilityHandler() : PragmaHandler("visibility") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 35 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 36 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | struct PragmaOptionsHandler : public PragmaHandler { |
| 40 | explicit PragmaOptionsHandler() : PragmaHandler("options") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 41 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 42 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | struct PragmaPackHandler : public PragmaHandler { |
| 46 | explicit PragmaPackHandler() : PragmaHandler("pack") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 47 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 48 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | struct PragmaMSStructHandler : public PragmaHandler { |
| 52 | explicit PragmaMSStructHandler() : PragmaHandler("ms_struct") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 53 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 54 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | struct PragmaUnusedHandler : public PragmaHandler { |
| 58 | PragmaUnusedHandler() : PragmaHandler("unused") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 59 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 60 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | struct PragmaWeakHandler : public PragmaHandler { |
| 64 | explicit PragmaWeakHandler() : PragmaHandler("weak") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 65 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 66 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | struct PragmaRedefineExtnameHandler : public PragmaHandler { |
| 70 | explicit PragmaRedefineExtnameHandler() : PragmaHandler("redefine_extname") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 71 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 72 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | struct PragmaOpenCLExtensionHandler : public PragmaHandler { |
| 76 | PragmaOpenCLExtensionHandler() : PragmaHandler("EXTENSION") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 77 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 78 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | |
| 82 | struct PragmaFPContractHandler : public PragmaHandler { |
| 83 | PragmaFPContractHandler() : PragmaHandler("FP_CONTRACT") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 84 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 85 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | struct PragmaNoOpenMPHandler : public PragmaHandler { |
| 89 | PragmaNoOpenMPHandler() : PragmaHandler("omp") { } |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 90 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 91 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | struct PragmaOpenMPHandler : public PragmaHandler { |
| 95 | PragmaOpenMPHandler() : PragmaHandler("omp") { } |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 96 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 97 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | /// PragmaCommentHandler - "\#pragma comment ...". |
| 101 | struct PragmaCommentHandler : public PragmaHandler { |
| 102 | PragmaCommentHandler(Sema &Actions) |
| 103 | : PragmaHandler("comment"), Actions(Actions) {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 104 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 105 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 106 | private: |
| 107 | Sema &Actions; |
| 108 | }; |
| 109 | |
| 110 | struct PragmaDetectMismatchHandler : public PragmaHandler { |
| 111 | PragmaDetectMismatchHandler(Sema &Actions) |
| 112 | : PragmaHandler("detect_mismatch"), Actions(Actions) {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 113 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 114 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 115 | private: |
| 116 | Sema &Actions; |
| 117 | }; |
| 118 | |
| 119 | struct PragmaMSPointersToMembers : public PragmaHandler { |
| 120 | explicit PragmaMSPointersToMembers() : PragmaHandler("pointers_to_members") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 121 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 122 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | struct PragmaMSVtorDisp : public PragmaHandler { |
| 126 | explicit PragmaMSVtorDisp() : PragmaHandler("vtordisp") {} |
Craig Topper | 2b07f02 | 2014-03-12 05:09:18 +0000 | [diff] [blame] | 127 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 128 | Token &FirstToken) override; |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 131 | struct PragmaMSPragma : public PragmaHandler { |
| 132 | explicit PragmaMSPragma(const char *name) : PragmaHandler(name) {} |
Reid Kleckner | d3923aa | 2014-04-03 19:04:24 +0000 | [diff] [blame] | 133 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 134 | Token &FirstToken) override; |
| 135 | }; |
| 136 | |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 137 | /// PragmaOptimizeHandler - "\#pragma clang optimize on/off". |
| 138 | struct PragmaOptimizeHandler : public PragmaHandler { |
| 139 | PragmaOptimizeHandler(Sema &S) |
| 140 | : PragmaHandler("optimize"), Actions(S) {} |
| 141 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 142 | Token &FirstToken) override; |
| 143 | private: |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 144 | Sema &Actions; |
| 145 | }; |
| 146 | |
| 147 | struct PragmaLoopHintHandler : public PragmaHandler { |
| 148 | PragmaLoopHintHandler() : PragmaHandler("loop") {} |
| 149 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 150 | Token &FirstToken) override; |
| 151 | }; |
| 152 | |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 153 | struct PragmaUnrollHintHandler : public PragmaHandler { |
| 154 | PragmaUnrollHintHandler(const char *name) : PragmaHandler(name) {} |
| 155 | void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 156 | Token &FirstToken) override; |
| 157 | }; |
| 158 | |
Hans Wennborg | 7357bbc | 2015-10-12 20:47:58 +0000 | [diff] [blame^] | 159 | struct PragmaMSRuntimeChecksHandler : public EmptyPragmaHandler { |
| 160 | PragmaMSRuntimeChecksHandler() : EmptyPragmaHandler("runtime_checks") {} |
| 161 | }; |
| 162 | |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 163 | } // end namespace |
| 164 | |
| 165 | void Parser::initializePragmaHandlers() { |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 166 | AlignHandler.reset(new PragmaAlignHandler()); |
| 167 | PP.AddPragmaHandler(AlignHandler.get()); |
| 168 | |
| 169 | GCCVisibilityHandler.reset(new PragmaGCCVisibilityHandler()); |
| 170 | PP.AddPragmaHandler("GCC", GCCVisibilityHandler.get()); |
| 171 | |
| 172 | OptionsHandler.reset(new PragmaOptionsHandler()); |
| 173 | PP.AddPragmaHandler(OptionsHandler.get()); |
| 174 | |
| 175 | PackHandler.reset(new PragmaPackHandler()); |
| 176 | PP.AddPragmaHandler(PackHandler.get()); |
| 177 | |
| 178 | MSStructHandler.reset(new PragmaMSStructHandler()); |
| 179 | PP.AddPragmaHandler(MSStructHandler.get()); |
| 180 | |
| 181 | UnusedHandler.reset(new PragmaUnusedHandler()); |
| 182 | PP.AddPragmaHandler(UnusedHandler.get()); |
| 183 | |
| 184 | WeakHandler.reset(new PragmaWeakHandler()); |
| 185 | PP.AddPragmaHandler(WeakHandler.get()); |
| 186 | |
| 187 | RedefineExtnameHandler.reset(new PragmaRedefineExtnameHandler()); |
| 188 | PP.AddPragmaHandler(RedefineExtnameHandler.get()); |
| 189 | |
| 190 | FPContractHandler.reset(new PragmaFPContractHandler()); |
| 191 | PP.AddPragmaHandler("STDC", FPContractHandler.get()); |
| 192 | |
| 193 | if (getLangOpts().OpenCL) { |
| 194 | OpenCLExtensionHandler.reset(new PragmaOpenCLExtensionHandler()); |
| 195 | PP.AddPragmaHandler("OPENCL", OpenCLExtensionHandler.get()); |
| 196 | |
| 197 | PP.AddPragmaHandler("OPENCL", FPContractHandler.get()); |
| 198 | } |
| 199 | if (getLangOpts().OpenMP) |
| 200 | OpenMPHandler.reset(new PragmaOpenMPHandler()); |
| 201 | else |
| 202 | OpenMPHandler.reset(new PragmaNoOpenMPHandler()); |
| 203 | PP.AddPragmaHandler(OpenMPHandler.get()); |
| 204 | |
Yunzhong Gao | 99efc03 | 2015-03-23 20:41:42 +0000 | [diff] [blame] | 205 | if (getLangOpts().MicrosoftExt || getTargetInfo().getTriple().isPS4()) { |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 206 | MSCommentHandler.reset(new PragmaCommentHandler(Actions)); |
| 207 | PP.AddPragmaHandler(MSCommentHandler.get()); |
Yunzhong Gao | 99efc03 | 2015-03-23 20:41:42 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | if (getLangOpts().MicrosoftExt) { |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 211 | MSDetectMismatchHandler.reset(new PragmaDetectMismatchHandler(Actions)); |
| 212 | PP.AddPragmaHandler(MSDetectMismatchHandler.get()); |
| 213 | MSPointersToMembers.reset(new PragmaMSPointersToMembers()); |
| 214 | PP.AddPragmaHandler(MSPointersToMembers.get()); |
| 215 | MSVtorDisp.reset(new PragmaMSVtorDisp()); |
| 216 | PP.AddPragmaHandler(MSVtorDisp.get()); |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 217 | MSInitSeg.reset(new PragmaMSPragma("init_seg")); |
Reid Kleckner | d3923aa | 2014-04-03 19:04:24 +0000 | [diff] [blame] | 218 | PP.AddPragmaHandler(MSInitSeg.get()); |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 219 | MSDataSeg.reset(new PragmaMSPragma("data_seg")); |
| 220 | PP.AddPragmaHandler(MSDataSeg.get()); |
| 221 | MSBSSSeg.reset(new PragmaMSPragma("bss_seg")); |
| 222 | PP.AddPragmaHandler(MSBSSSeg.get()); |
| 223 | MSConstSeg.reset(new PragmaMSPragma("const_seg")); |
| 224 | PP.AddPragmaHandler(MSConstSeg.get()); |
| 225 | MSCodeSeg.reset(new PragmaMSPragma("code_seg")); |
| 226 | PP.AddPragmaHandler(MSCodeSeg.get()); |
| 227 | MSSection.reset(new PragmaMSPragma("section")); |
| 228 | PP.AddPragmaHandler(MSSection.get()); |
Hans Wennborg | 7357bbc | 2015-10-12 20:47:58 +0000 | [diff] [blame^] | 229 | MSRuntimeChecks.reset(new PragmaMSRuntimeChecksHandler()); |
| 230 | PP.AddPragmaHandler(MSRuntimeChecks.get()); |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 231 | } |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 232 | |
| 233 | OptimizeHandler.reset(new PragmaOptimizeHandler(Actions)); |
| 234 | PP.AddPragmaHandler("clang", OptimizeHandler.get()); |
| 235 | |
| 236 | LoopHintHandler.reset(new PragmaLoopHintHandler()); |
| 237 | PP.AddPragmaHandler("clang", LoopHintHandler.get()); |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 238 | |
| 239 | UnrollHintHandler.reset(new PragmaUnrollHintHandler("unroll")); |
| 240 | PP.AddPragmaHandler(UnrollHintHandler.get()); |
Mark Heffernan | c888e41 | 2014-07-24 18:09:38 +0000 | [diff] [blame] | 241 | |
| 242 | NoUnrollHintHandler.reset(new PragmaUnrollHintHandler("nounroll")); |
| 243 | PP.AddPragmaHandler(NoUnrollHintHandler.get()); |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void Parser::resetPragmaHandlers() { |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 247 | // Remove the pragma handlers we installed. |
| 248 | PP.RemovePragmaHandler(AlignHandler.get()); |
| 249 | AlignHandler.reset(); |
| 250 | PP.RemovePragmaHandler("GCC", GCCVisibilityHandler.get()); |
| 251 | GCCVisibilityHandler.reset(); |
| 252 | PP.RemovePragmaHandler(OptionsHandler.get()); |
| 253 | OptionsHandler.reset(); |
| 254 | PP.RemovePragmaHandler(PackHandler.get()); |
| 255 | PackHandler.reset(); |
| 256 | PP.RemovePragmaHandler(MSStructHandler.get()); |
| 257 | MSStructHandler.reset(); |
| 258 | PP.RemovePragmaHandler(UnusedHandler.get()); |
| 259 | UnusedHandler.reset(); |
| 260 | PP.RemovePragmaHandler(WeakHandler.get()); |
| 261 | WeakHandler.reset(); |
| 262 | PP.RemovePragmaHandler(RedefineExtnameHandler.get()); |
| 263 | RedefineExtnameHandler.reset(); |
| 264 | |
| 265 | if (getLangOpts().OpenCL) { |
| 266 | PP.RemovePragmaHandler("OPENCL", OpenCLExtensionHandler.get()); |
| 267 | OpenCLExtensionHandler.reset(); |
| 268 | PP.RemovePragmaHandler("OPENCL", FPContractHandler.get()); |
| 269 | } |
| 270 | PP.RemovePragmaHandler(OpenMPHandler.get()); |
| 271 | OpenMPHandler.reset(); |
| 272 | |
Yunzhong Gao | 99efc03 | 2015-03-23 20:41:42 +0000 | [diff] [blame] | 273 | if (getLangOpts().MicrosoftExt || getTargetInfo().getTriple().isPS4()) { |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 274 | PP.RemovePragmaHandler(MSCommentHandler.get()); |
| 275 | MSCommentHandler.reset(); |
Yunzhong Gao | 99efc03 | 2015-03-23 20:41:42 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | if (getLangOpts().MicrosoftExt) { |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 279 | PP.RemovePragmaHandler(MSDetectMismatchHandler.get()); |
| 280 | MSDetectMismatchHandler.reset(); |
| 281 | PP.RemovePragmaHandler(MSPointersToMembers.get()); |
| 282 | MSPointersToMembers.reset(); |
| 283 | PP.RemovePragmaHandler(MSVtorDisp.get()); |
| 284 | MSVtorDisp.reset(); |
Reid Kleckner | d3923aa | 2014-04-03 19:04:24 +0000 | [diff] [blame] | 285 | PP.RemovePragmaHandler(MSInitSeg.get()); |
| 286 | MSInitSeg.reset(); |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 287 | PP.RemovePragmaHandler(MSDataSeg.get()); |
| 288 | MSDataSeg.reset(); |
| 289 | PP.RemovePragmaHandler(MSBSSSeg.get()); |
| 290 | MSBSSSeg.reset(); |
| 291 | PP.RemovePragmaHandler(MSConstSeg.get()); |
| 292 | MSConstSeg.reset(); |
| 293 | PP.RemovePragmaHandler(MSCodeSeg.get()); |
| 294 | MSCodeSeg.reset(); |
| 295 | PP.RemovePragmaHandler(MSSection.get()); |
| 296 | MSSection.reset(); |
Hans Wennborg | 7357bbc | 2015-10-12 20:47:58 +0000 | [diff] [blame^] | 297 | PP.RemovePragmaHandler(MSRuntimeChecks.get()); |
| 298 | MSRuntimeChecks.reset(); |
Reid Kleckner | 5b08646 | 2014-02-20 22:52:09 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | PP.RemovePragmaHandler("STDC", FPContractHandler.get()); |
| 302 | FPContractHandler.reset(); |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 303 | |
| 304 | PP.RemovePragmaHandler("clang", OptimizeHandler.get()); |
| 305 | OptimizeHandler.reset(); |
| 306 | |
| 307 | PP.RemovePragmaHandler("clang", LoopHintHandler.get()); |
| 308 | LoopHintHandler.reset(); |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 309 | |
| 310 | PP.RemovePragmaHandler(UnrollHintHandler.get()); |
| 311 | UnrollHintHandler.reset(); |
Mark Heffernan | c888e41 | 2014-07-24 18:09:38 +0000 | [diff] [blame] | 312 | |
| 313 | PP.RemovePragmaHandler(NoUnrollHintHandler.get()); |
| 314 | NoUnrollHintHandler.reset(); |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /// \brief Handle the annotation token produced for #pragma unused(...) |
Argyrios Kyrtzidis | ee56962 | 2011-01-17 18:58:44 +0000 | [diff] [blame] | 318 | /// |
| 319 | /// Each annot_pragma_unused is followed by the argument token so e.g. |
| 320 | /// "#pragma unused(x,y)" becomes: |
| 321 | /// annot_pragma_unused 'x' annot_pragma_unused 'y' |
| 322 | void Parser::HandlePragmaUnused() { |
| 323 | assert(Tok.is(tok::annot_pragma_unused)); |
| 324 | SourceLocation UnusedLoc = ConsumeToken(); |
| 325 | Actions.ActOnPragmaUnused(Tok, getCurScope(), UnusedLoc); |
| 326 | ConsumeToken(); // The argument token. |
| 327 | } |
Eli Friedman | 570024a | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 328 | |
Rafael Espindola | 273fd77 | 2012-01-26 02:02:57 +0000 | [diff] [blame] | 329 | void Parser::HandlePragmaVisibility() { |
| 330 | assert(Tok.is(tok::annot_pragma_vis)); |
| 331 | const IdentifierInfo *VisType = |
| 332 | static_cast<IdentifierInfo *>(Tok.getAnnotationValue()); |
| 333 | SourceLocation VisLoc = ConsumeToken(); |
| 334 | Actions.ActOnPragmaVisibility(VisType, VisLoc); |
| 335 | } |
| 336 | |
Eli Friedman | ec52f92 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 337 | struct PragmaPackInfo { |
| 338 | Sema::PragmaPackKind Kind; |
| 339 | IdentifierInfo *Name; |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 340 | Token Alignment; |
Eli Friedman | ec52f92 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 341 | SourceLocation LParenLoc; |
| 342 | SourceLocation RParenLoc; |
| 343 | }; |
| 344 | |
| 345 | void Parser::HandlePragmaPack() { |
| 346 | assert(Tok.is(tok::annot_pragma_pack)); |
| 347 | PragmaPackInfo *Info = |
| 348 | static_cast<PragmaPackInfo *>(Tok.getAnnotationValue()); |
| 349 | SourceLocation PragmaLoc = ConsumeToken(); |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 350 | ExprResult Alignment; |
| 351 | if (Info->Alignment.is(tok::numeric_constant)) { |
| 352 | Alignment = Actions.ActOnNumericConstant(Info->Alignment); |
| 353 | if (Alignment.isInvalid()) |
| 354 | return; |
| 355 | } |
| 356 | Actions.ActOnPragmaPack(Info->Kind, Info->Name, Alignment.get(), PragmaLoc, |
Eli Friedman | ec52f92 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 357 | Info->LParenLoc, Info->RParenLoc); |
Eli Friedman | ec52f92 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 360 | void Parser::HandlePragmaMSStruct() { |
| 361 | assert(Tok.is(tok::annot_pragma_msstruct)); |
| 362 | Sema::PragmaMSStructKind Kind = |
| 363 | static_cast<Sema::PragmaMSStructKind>( |
| 364 | reinterpret_cast<uintptr_t>(Tok.getAnnotationValue())); |
| 365 | Actions.ActOnPragmaMSStruct(Kind); |
| 366 | ConsumeToken(); // The annotation token. |
| 367 | } |
| 368 | |
| 369 | void Parser::HandlePragmaAlign() { |
| 370 | assert(Tok.is(tok::annot_pragma_align)); |
| 371 | Sema::PragmaOptionsAlignKind Kind = |
| 372 | static_cast<Sema::PragmaOptionsAlignKind>( |
| 373 | reinterpret_cast<uintptr_t>(Tok.getAnnotationValue())); |
| 374 | SourceLocation PragmaLoc = ConsumeToken(); |
| 375 | Actions.ActOnPragmaOptionsAlign(Kind, PragmaLoc); |
| 376 | } |
| 377 | |
| 378 | void Parser::HandlePragmaWeak() { |
| 379 | assert(Tok.is(tok::annot_pragma_weak)); |
| 380 | SourceLocation PragmaLoc = ConsumeToken(); |
| 381 | Actions.ActOnPragmaWeakID(Tok.getIdentifierInfo(), PragmaLoc, |
| 382 | Tok.getLocation()); |
| 383 | ConsumeToken(); // The weak name. |
| 384 | } |
| 385 | |
| 386 | void Parser::HandlePragmaWeakAlias() { |
| 387 | assert(Tok.is(tok::annot_pragma_weakalias)); |
| 388 | SourceLocation PragmaLoc = ConsumeToken(); |
| 389 | IdentifierInfo *WeakName = Tok.getIdentifierInfo(); |
| 390 | SourceLocation WeakNameLoc = Tok.getLocation(); |
| 391 | ConsumeToken(); |
| 392 | IdentifierInfo *AliasName = Tok.getIdentifierInfo(); |
| 393 | SourceLocation AliasNameLoc = Tok.getLocation(); |
| 394 | ConsumeToken(); |
| 395 | Actions.ActOnPragmaWeakAlias(WeakName, AliasName, PragmaLoc, |
| 396 | WeakNameLoc, AliasNameLoc); |
| 397 | |
| 398 | } |
| 399 | |
| 400 | void Parser::HandlePragmaRedefineExtname() { |
| 401 | assert(Tok.is(tok::annot_pragma_redefine_extname)); |
| 402 | SourceLocation RedefLoc = ConsumeToken(); |
| 403 | IdentifierInfo *RedefName = Tok.getIdentifierInfo(); |
| 404 | SourceLocation RedefNameLoc = Tok.getLocation(); |
| 405 | ConsumeToken(); |
| 406 | IdentifierInfo *AliasName = Tok.getIdentifierInfo(); |
| 407 | SourceLocation AliasNameLoc = Tok.getLocation(); |
| 408 | ConsumeToken(); |
| 409 | Actions.ActOnPragmaRedefineExtname(RedefName, AliasName, RedefLoc, |
| 410 | RedefNameLoc, AliasNameLoc); |
| 411 | } |
| 412 | |
| 413 | void Parser::HandlePragmaFPContract() { |
| 414 | assert(Tok.is(tok::annot_pragma_fp_contract)); |
| 415 | tok::OnOffSwitch OOS = |
| 416 | static_cast<tok::OnOffSwitch>( |
| 417 | reinterpret_cast<uintptr_t>(Tok.getAnnotationValue())); |
| 418 | Actions.ActOnPragmaFPContract(OOS); |
| 419 | ConsumeToken(); // The annotation token. |
| 420 | } |
| 421 | |
Tareq A. Siraj | 0de0dd4 | 2013-04-16 18:41:26 +0000 | [diff] [blame] | 422 | StmtResult Parser::HandlePragmaCaptured() |
| 423 | { |
| 424 | assert(Tok.is(tok::annot_pragma_captured)); |
| 425 | ConsumeToken(); |
| 426 | |
| 427 | if (Tok.isNot(tok::l_brace)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 428 | PP.Diag(Tok, diag::err_expected) << tok::l_brace; |
Tareq A. Siraj | 0de0dd4 | 2013-04-16 18:41:26 +0000 | [diff] [blame] | 429 | return StmtError(); |
| 430 | } |
| 431 | |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 432 | SourceLocation Loc = Tok.getLocation(); |
| 433 | |
| 434 | ParseScope CapturedRegionScope(this, Scope::FnScope | Scope::DeclScope); |
Ben Langmuir | 37943a7 | 2013-05-03 19:00:33 +0000 | [diff] [blame] | 435 | Actions.ActOnCapturedRegionStart(Loc, getCurScope(), CR_Default, |
| 436 | /*NumParams=*/1); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 437 | |
| 438 | StmtResult R = ParseCompoundStatement(); |
| 439 | CapturedRegionScope.Exit(); |
| 440 | |
| 441 | if (R.isInvalid()) { |
| 442 | Actions.ActOnCapturedRegionError(); |
| 443 | return StmtError(); |
| 444 | } |
| 445 | |
| 446 | return Actions.ActOnCapturedRegionEnd(R.get()); |
Tareq A. Siraj | 0de0dd4 | 2013-04-16 18:41:26 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 449 | namespace { |
| 450 | typedef llvm::PointerIntPair<IdentifierInfo *, 1, bool> OpenCLExtData; |
| 451 | } |
| 452 | |
| 453 | void Parser::HandlePragmaOpenCLExtension() { |
| 454 | assert(Tok.is(tok::annot_pragma_opencl_extension)); |
| 455 | OpenCLExtData data = |
| 456 | OpenCLExtData::getFromOpaqueValue(Tok.getAnnotationValue()); |
| 457 | unsigned state = data.getInt(); |
| 458 | IdentifierInfo *ename = data.getPointer(); |
| 459 | SourceLocation NameLoc = Tok.getLocation(); |
| 460 | ConsumeToken(); // The annotation token. |
| 461 | |
| 462 | OpenCLOptions &f = Actions.getOpenCLOptions(); |
| 463 | // OpenCL 1.1 9.1: "The all variant sets the behavior for all extensions, |
| 464 | // overriding all previously issued extension directives, but only if the |
| 465 | // behavior is set to disable." |
| 466 | if (state == 0 && ename->isStr("all")) { |
| 467 | #define OPENCLEXT(nm) f.nm = 0; |
| 468 | #include "clang/Basic/OpenCLExtensions.def" |
| 469 | } |
| 470 | #define OPENCLEXT(nm) else if (ename->isStr(#nm)) { f.nm = state; } |
| 471 | #include "clang/Basic/OpenCLExtensions.def" |
| 472 | else { |
| 473 | PP.Diag(NameLoc, diag::warn_pragma_unknown_extension) << ename; |
| 474 | return; |
| 475 | } |
| 476 | } |
| 477 | |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 478 | void Parser::HandlePragmaMSPointersToMembers() { |
| 479 | assert(Tok.is(tok::annot_pragma_ms_pointers_to_members)); |
David Majnemer | 86c318f | 2014-02-11 21:05:00 +0000 | [diff] [blame] | 480 | LangOptions::PragmaMSPointersToMembersKind RepresentationMethod = |
| 481 | static_cast<LangOptions::PragmaMSPointersToMembersKind>( |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 482 | reinterpret_cast<uintptr_t>(Tok.getAnnotationValue())); |
| 483 | SourceLocation PragmaLoc = ConsumeToken(); // The annotation token. |
| 484 | Actions.ActOnPragmaMSPointersToMembers(RepresentationMethod, PragmaLoc); |
| 485 | } |
Tareq A. Siraj | 0de0dd4 | 2013-04-16 18:41:26 +0000 | [diff] [blame] | 486 | |
Reid Kleckner | c0dca6d | 2014-02-12 23:50:26 +0000 | [diff] [blame] | 487 | void Parser::HandlePragmaMSVtorDisp() { |
| 488 | assert(Tok.is(tok::annot_pragma_ms_vtordisp)); |
| 489 | uintptr_t Value = reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()); |
| 490 | Sema::PragmaVtorDispKind Kind = |
| 491 | static_cast<Sema::PragmaVtorDispKind>((Value >> 16) & 0xFFFF); |
| 492 | MSVtorDispAttr::Mode Mode = MSVtorDispAttr::Mode(Value & 0xFFFF); |
| 493 | SourceLocation PragmaLoc = ConsumeToken(); // The annotation token. |
| 494 | Actions.ActOnPragmaMSVtorDisp(Kind, PragmaLoc, Mode); |
| 495 | } |
Tareq A. Siraj | 0de0dd4 | 2013-04-16 18:41:26 +0000 | [diff] [blame] | 496 | |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 497 | void Parser::HandlePragmaMSPragma() { |
| 498 | assert(Tok.is(tok::annot_pragma_ms_pragma)); |
| 499 | // Grab the tokens out of the annotation and enter them into the stream. |
| 500 | auto TheTokens = (std::pair<Token*, size_t> *)Tok.getAnnotationValue(); |
| 501 | PP.EnterTokenStream(TheTokens->first, TheTokens->second, true, true); |
| 502 | SourceLocation PragmaLocation = ConsumeToken(); // The annotation token. |
| 503 | assert(Tok.isAnyIdentifier()); |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 504 | StringRef PragmaName = Tok.getIdentifierInfo()->getName(); |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 505 | PP.Lex(Tok); // pragma kind |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 506 | |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 507 | // Figure out which #pragma we're dealing with. The switch has no default |
| 508 | // because lex shouldn't emit the annotation token for unrecognized pragmas. |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 509 | typedef bool (Parser::*PragmaHandler)(StringRef, SourceLocation); |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 510 | PragmaHandler Handler = llvm::StringSwitch<PragmaHandler>(PragmaName) |
| 511 | .Case("data_seg", &Parser::HandlePragmaMSSegment) |
| 512 | .Case("bss_seg", &Parser::HandlePragmaMSSegment) |
| 513 | .Case("const_seg", &Parser::HandlePragmaMSSegment) |
| 514 | .Case("code_seg", &Parser::HandlePragmaMSSegment) |
| 515 | .Case("section", &Parser::HandlePragmaMSSection) |
| 516 | .Case("init_seg", &Parser::HandlePragmaMSInitSeg); |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 517 | |
| 518 | if (!(this->*Handler)(PragmaName, PragmaLocation)) { |
| 519 | // Pragma handling failed, and has been diagnosed. Slurp up the tokens |
| 520 | // until eof (really end of line) to prevent follow-on errors. |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 521 | while (Tok.isNot(tok::eof)) |
| 522 | PP.Lex(Tok); |
| 523 | PP.Lex(Tok); |
| 524 | } |
| 525 | } |
| 526 | |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 527 | bool Parser::HandlePragmaMSSection(StringRef PragmaName, |
| 528 | SourceLocation PragmaLocation) { |
| 529 | if (Tok.isNot(tok::l_paren)) { |
| 530 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName; |
| 531 | return false; |
| 532 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 533 | PP.Lex(Tok); // ( |
| 534 | // Parsing code for pragma section |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 535 | if (Tok.isNot(tok::string_literal)) { |
| 536 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_section_name) |
| 537 | << PragmaName; |
| 538 | return false; |
| 539 | } |
| 540 | ExprResult StringResult = ParseStringLiteralExpression(); |
| 541 | if (StringResult.isInvalid()) |
| 542 | return false; // Already diagnosed. |
| 543 | StringLiteral *SegmentName = cast<StringLiteral>(StringResult.get()); |
| 544 | if (SegmentName->getCharByteWidth() != 1) { |
| 545 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string) |
| 546 | << PragmaName; |
| 547 | return false; |
| 548 | } |
David Majnemer | 48c28fa | 2014-10-22 21:08:43 +0000 | [diff] [blame] | 549 | int SectionFlags = ASTContext::PSF_Read; |
| 550 | bool SectionFlagsAreDefault = true; |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 551 | while (Tok.is(tok::comma)) { |
| 552 | PP.Lex(Tok); // , |
David Majnemer | 48c28fa | 2014-10-22 21:08:43 +0000 | [diff] [blame] | 553 | // Ignore "long" and "short". |
| 554 | // They are undocumented, but widely used, section attributes which appear |
| 555 | // to do nothing. |
| 556 | if (Tok.is(tok::kw_long) || Tok.is(tok::kw_short)) { |
| 557 | PP.Lex(Tok); // long/short |
| 558 | continue; |
| 559 | } |
| 560 | |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 561 | if (!Tok.isAnyIdentifier()) { |
| 562 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren) |
| 563 | << PragmaName; |
| 564 | return false; |
| 565 | } |
Hans Wennborg | 899ded9 | 2014-10-16 20:52:46 +0000 | [diff] [blame] | 566 | ASTContext::PragmaSectionFlag Flag = |
| 567 | llvm::StringSwitch<ASTContext::PragmaSectionFlag>( |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 568 | Tok.getIdentifierInfo()->getName()) |
Hans Wennborg | 899ded9 | 2014-10-16 20:52:46 +0000 | [diff] [blame] | 569 | .Case("read", ASTContext::PSF_Read) |
| 570 | .Case("write", ASTContext::PSF_Write) |
| 571 | .Case("execute", ASTContext::PSF_Execute) |
| 572 | .Case("shared", ASTContext::PSF_Invalid) |
| 573 | .Case("nopage", ASTContext::PSF_Invalid) |
| 574 | .Case("nocache", ASTContext::PSF_Invalid) |
| 575 | .Case("discard", ASTContext::PSF_Invalid) |
| 576 | .Case("remove", ASTContext::PSF_Invalid) |
| 577 | .Default(ASTContext::PSF_None); |
| 578 | if (Flag == ASTContext::PSF_None || Flag == ASTContext::PSF_Invalid) { |
| 579 | PP.Diag(PragmaLocation, Flag == ASTContext::PSF_None |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 580 | ? diag::warn_pragma_invalid_specific_action |
| 581 | : diag::warn_pragma_unsupported_action) |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 582 | << PragmaName << Tok.getIdentifierInfo()->getName(); |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 583 | return false; |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 584 | } |
| 585 | SectionFlags |= Flag; |
David Majnemer | 48c28fa | 2014-10-22 21:08:43 +0000 | [diff] [blame] | 586 | SectionFlagsAreDefault = false; |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 587 | PP.Lex(Tok); // Identifier |
| 588 | } |
David Majnemer | 48c28fa | 2014-10-22 21:08:43 +0000 | [diff] [blame] | 589 | // If no section attributes are specified, the section will be marked as |
| 590 | // read/write. |
| 591 | if (SectionFlagsAreDefault) |
| 592 | SectionFlags |= ASTContext::PSF_Write; |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 593 | if (Tok.isNot(tok::r_paren)) { |
| 594 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName; |
| 595 | return false; |
| 596 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 597 | PP.Lex(Tok); // ) |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 598 | if (Tok.isNot(tok::eof)) { |
| 599 | PP.Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol) |
| 600 | << PragmaName; |
| 601 | return false; |
| 602 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 603 | PP.Lex(Tok); // eof |
| 604 | Actions.ActOnPragmaMSSection(PragmaLocation, SectionFlags, SegmentName); |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 605 | return true; |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 608 | bool Parser::HandlePragmaMSSegment(StringRef PragmaName, |
| 609 | SourceLocation PragmaLocation) { |
| 610 | if (Tok.isNot(tok::l_paren)) { |
| 611 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName; |
| 612 | return false; |
| 613 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 614 | PP.Lex(Tok); // ( |
| 615 | Sema::PragmaMsStackAction Action = Sema::PSK_Reset; |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 616 | StringRef SlotLabel; |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 617 | if (Tok.isAnyIdentifier()) { |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 618 | StringRef PushPop = Tok.getIdentifierInfo()->getName(); |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 619 | if (PushPop == "push") |
| 620 | Action = Sema::PSK_Push; |
| 621 | else if (PushPop == "pop") |
| 622 | Action = Sema::PSK_Pop; |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 623 | else { |
| 624 | PP.Diag(PragmaLocation, |
| 625 | diag::warn_pragma_expected_section_push_pop_or_name) |
| 626 | << PragmaName; |
| 627 | return false; |
| 628 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 629 | if (Action != Sema::PSK_Reset) { |
| 630 | PP.Lex(Tok); // push | pop |
| 631 | if (Tok.is(tok::comma)) { |
| 632 | PP.Lex(Tok); // , |
| 633 | // If we've got a comma, we either need a label or a string. |
| 634 | if (Tok.isAnyIdentifier()) { |
| 635 | SlotLabel = Tok.getIdentifierInfo()->getName(); |
| 636 | PP.Lex(Tok); // identifier |
| 637 | if (Tok.is(tok::comma)) |
| 638 | PP.Lex(Tok); |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 639 | else if (Tok.isNot(tok::r_paren)) { |
| 640 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_punc) |
| 641 | << PragmaName; |
| 642 | return false; |
| 643 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 644 | } |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 645 | } else if (Tok.isNot(tok::r_paren)) { |
| 646 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_punc) << PragmaName; |
| 647 | return false; |
| 648 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | // Grab the string literal for our section name. |
| 652 | StringLiteral *SegmentName = nullptr; |
| 653 | if (Tok.isNot(tok::r_paren)) { |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 654 | if (Tok.isNot(tok::string_literal)) { |
| 655 | unsigned DiagID = Action != Sema::PSK_Reset ? !SlotLabel.empty() ? |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 656 | diag::warn_pragma_expected_section_name : |
| 657 | diag::warn_pragma_expected_section_label_or_name : |
| 658 | diag::warn_pragma_expected_section_push_pop_or_name; |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 659 | PP.Diag(PragmaLocation, DiagID) << PragmaName; |
| 660 | return false; |
| 661 | } |
| 662 | ExprResult StringResult = ParseStringLiteralExpression(); |
| 663 | if (StringResult.isInvalid()) |
| 664 | return false; // Already diagnosed. |
| 665 | SegmentName = cast<StringLiteral>(StringResult.get()); |
| 666 | if (SegmentName->getCharByteWidth() != 1) { |
| 667 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string) |
| 668 | << PragmaName; |
| 669 | return false; |
| 670 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 671 | // Setting section "" has no effect |
| 672 | if (SegmentName->getLength()) |
| 673 | Action = (Sema::PragmaMsStackAction)(Action | Sema::PSK_Set); |
| 674 | } |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 675 | if (Tok.isNot(tok::r_paren)) { |
| 676 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName; |
| 677 | return false; |
| 678 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 679 | PP.Lex(Tok); // ) |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 680 | if (Tok.isNot(tok::eof)) { |
| 681 | PP.Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol) |
| 682 | << PragmaName; |
| 683 | return false; |
| 684 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 685 | PP.Lex(Tok); // eof |
| 686 | Actions.ActOnPragmaMSSeg(PragmaLocation, Action, SlotLabel, |
| 687 | SegmentName, PragmaName); |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 688 | return true; |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Reid Kleckner | 1a711b1 | 2014-07-22 00:53:05 +0000 | [diff] [blame] | 691 | // #pragma init_seg({ compiler | lib | user | "section-name" [, func-name]} ) |
Reid Kleckner | 722b1df | 2014-07-18 00:13:16 +0000 | [diff] [blame] | 692 | bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName, |
| 693 | SourceLocation PragmaLocation) { |
David Majnemer | ad2986e | 2014-08-14 06:35:08 +0000 | [diff] [blame] | 694 | if (getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) { |
| 695 | PP.Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target); |
| 696 | return false; |
| 697 | } |
| 698 | |
Reid Kleckner | 1a711b1 | 2014-07-22 00:53:05 +0000 | [diff] [blame] | 699 | if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen, |
| 700 | PragmaName)) |
| 701 | return false; |
| 702 | |
| 703 | // Parse either the known section names or the string section name. |
| 704 | StringLiteral *SegmentName = nullptr; |
| 705 | if (Tok.isAnyIdentifier()) { |
| 706 | auto *II = Tok.getIdentifierInfo(); |
| 707 | StringRef Section = llvm::StringSwitch<StringRef>(II->getName()) |
| 708 | .Case("compiler", "\".CRT$XCC\"") |
| 709 | .Case("lib", "\".CRT$XCL\"") |
| 710 | .Case("user", "\".CRT$XCU\"") |
| 711 | .Default(""); |
| 712 | |
| 713 | if (!Section.empty()) { |
| 714 | // Pretend the user wrote the appropriate string literal here. |
| 715 | Token Toks[1]; |
| 716 | Toks[0].startToken(); |
| 717 | Toks[0].setKind(tok::string_literal); |
| 718 | Toks[0].setLocation(Tok.getLocation()); |
| 719 | Toks[0].setLiteralData(Section.data()); |
| 720 | Toks[0].setLength(Section.size()); |
| 721 | SegmentName = |
| 722 | cast<StringLiteral>(Actions.ActOnStringLiteral(Toks, nullptr).get()); |
| 723 | PP.Lex(Tok); |
| 724 | } |
| 725 | } else if (Tok.is(tok::string_literal)) { |
| 726 | ExprResult StringResult = ParseStringLiteralExpression(); |
| 727 | if (StringResult.isInvalid()) |
| 728 | return false; |
| 729 | SegmentName = cast<StringLiteral>(StringResult.get()); |
| 730 | if (SegmentName->getCharByteWidth() != 1) { |
| 731 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string) |
| 732 | << PragmaName; |
| 733 | return false; |
| 734 | } |
| 735 | // FIXME: Add support for the '[, func-name]' part of the pragma. |
| 736 | } |
| 737 | |
| 738 | if (!SegmentName) { |
| 739 | PP.Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName; |
| 740 | return false; |
| 741 | } |
| 742 | |
| 743 | if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen, |
| 744 | PragmaName) || |
| 745 | ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol, |
| 746 | PragmaName)) |
| 747 | return false; |
| 748 | |
| 749 | Actions.ActOnPragmaMSInitSeg(PragmaLocation, SegmentName); |
| 750 | return true; |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | struct PragmaLoopHintInfo { |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 754 | Token PragmaName; |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 755 | Token Option; |
Benjamin Kramer | fa7f855 | 2015-08-05 09:39:57 +0000 | [diff] [blame] | 756 | ArrayRef<Token> Toks; |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 757 | }; |
| 758 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 759 | static std::string PragmaLoopHintString(Token PragmaName, Token Option) { |
| 760 | std::string PragmaString; |
| 761 | if (PragmaName.getIdentifierInfo()->getName() == "loop") { |
| 762 | PragmaString = "clang loop "; |
| 763 | PragmaString += Option.getIdentifierInfo()->getName(); |
| 764 | } else { |
| 765 | assert(PragmaName.getIdentifierInfo()->getName() == "unroll" && |
| 766 | "Unexpected pragma name"); |
| 767 | PragmaString = "unroll"; |
| 768 | } |
| 769 | return PragmaString; |
| 770 | } |
| 771 | |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 772 | bool Parser::HandlePragmaLoopHint(LoopHint &Hint) { |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 773 | assert(Tok.is(tok::annot_pragma_loop_hint)); |
| 774 | PragmaLoopHintInfo *Info = |
| 775 | static_cast<PragmaLoopHintInfo *>(Tok.getAnnotationValue()); |
| 776 | |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 777 | IdentifierInfo *PragmaNameInfo = Info->PragmaName.getIdentifierInfo(); |
| 778 | Hint.PragmaNameLoc = IdentifierLoc::create( |
| 779 | Actions.Context, Info->PragmaName.getLocation(), PragmaNameInfo); |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 780 | |
Aaron Ballman | ef940aa | 2014-07-31 21:24:32 +0000 | [diff] [blame] | 781 | // It is possible that the loop hint has no option identifier, such as |
| 782 | // #pragma unroll(4). |
| 783 | IdentifierInfo *OptionInfo = Info->Option.is(tok::identifier) |
| 784 | ? Info->Option.getIdentifierInfo() |
| 785 | : nullptr; |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 786 | Hint.OptionLoc = IdentifierLoc::create( |
| 787 | Actions.Context, Info->Option.getLocation(), OptionInfo); |
| 788 | |
Benjamin Kramer | fa7f855 | 2015-08-05 09:39:57 +0000 | [diff] [blame] | 789 | const Token *Toks = Info->Toks.data(); |
| 790 | size_t TokSize = Info->Toks.size(); |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 791 | |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 792 | // Return a valid hint if pragma unroll or nounroll were specified |
| 793 | // without an argument. |
| 794 | bool PragmaUnroll = PragmaNameInfo->getName() == "unroll"; |
| 795 | bool PragmaNoUnroll = PragmaNameInfo->getName() == "nounroll"; |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 796 | if (TokSize == 0 && (PragmaUnroll || PragmaNoUnroll)) { |
| 797 | ConsumeToken(); // The annotation token. |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 798 | Hint.Range = Info->PragmaName.getLocation(); |
| 799 | return true; |
| 800 | } |
| 801 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 802 | // The constant expression is always followed by an eof token, which increases |
| 803 | // the TokSize by 1. |
| 804 | assert(TokSize > 0 && |
| 805 | "PragmaLoopHintInfo::Toks must contain at least one token."); |
| 806 | |
| 807 | // If no option is specified the argument is assumed to be a constant expr. |
Tyler Nowicki | 24853c1 | 2015-06-08 23:13:43 +0000 | [diff] [blame] | 808 | bool OptionUnroll = false; |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 809 | bool StateOption = false; |
Tyler Nowicki | 24853c1 | 2015-06-08 23:13:43 +0000 | [diff] [blame] | 810 | if (OptionInfo) { // Pragma Unroll does not specify an option. |
| 811 | OptionUnroll = OptionInfo->isStr("unroll"); |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 812 | StateOption = llvm::StringSwitch<bool>(OptionInfo->getName()) |
| 813 | .Case("vectorize", true) |
| 814 | .Case("interleave", true) |
| 815 | .Case("unroll", true) |
| 816 | .Default(false); |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | // Verify loop hint has an argument. |
| 820 | if (Toks[0].is(tok::eof)) { |
| 821 | ConsumeToken(); // The annotation token. |
| 822 | Diag(Toks[0].getLocation(), diag::err_pragma_loop_missing_argument) |
Tyler Nowicki | 24853c1 | 2015-06-08 23:13:43 +0000 | [diff] [blame] | 823 | << /*StateArgument=*/StateOption << /*FullKeyword=*/OptionUnroll; |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 824 | return false; |
| 825 | } |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 826 | |
| 827 | // Validate the argument. |
| 828 | if (StateOption) { |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 829 | ConsumeToken(); // The annotation token. |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 830 | SourceLocation StateLoc = Toks[0].getLocation(); |
| 831 | IdentifierInfo *StateInfo = Toks[0].getIdentifierInfo(); |
Tyler Nowicki | 9d268e1 | 2015-06-11 23:23:17 +0000 | [diff] [blame] | 832 | if (!StateInfo || |
Mark Heffernan | 397a98d | 2015-08-10 17:29:39 +0000 | [diff] [blame] | 833 | (!StateInfo->isStr("enable") && !StateInfo->isStr("disable") && |
| 834 | ((OptionUnroll && !StateInfo->isStr("full")) || |
| 835 | (!OptionUnroll && !StateInfo->isStr("assume_safety"))))) { |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 836 | Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword) |
| 837 | << /*FullKeyword=*/OptionUnroll; |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 838 | return false; |
| 839 | } |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 840 | if (TokSize > 2) |
| 841 | Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
| 842 | << PragmaLoopHintString(Info->PragmaName, Info->Option); |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 843 | Hint.StateLoc = IdentifierLoc::create(Actions.Context, StateLoc, StateInfo); |
| 844 | } else { |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 845 | // Enter constant expression including eof terminator into token stream. |
| 846 | PP.EnterTokenStream(Toks, TokSize, /*DisableMacroExpansion=*/false, |
| 847 | /*OwnsTokens=*/false); |
| 848 | ConsumeToken(); // The annotation token. |
| 849 | |
| 850 | ExprResult R = ParseConstantExpression(); |
| 851 | |
| 852 | // Tokens following an error in an ill-formed constant expression will |
| 853 | // remain in the token stream and must be removed. |
| 854 | if (Tok.isNot(tok::eof)) { |
| 855 | Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
| 856 | << PragmaLoopHintString(Info->PragmaName, Info->Option); |
| 857 | while (Tok.isNot(tok::eof)) |
| 858 | ConsumeAnyToken(); |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 859 | } |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 860 | |
| 861 | ConsumeToken(); // Consume the constant expression eof terminator. |
| 862 | |
| 863 | if (R.isInvalid() || |
| 864 | Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation())) |
| 865 | return false; |
| 866 | |
| 867 | // Argument is a constant expression with an integer type. |
| 868 | Hint.ValueExpr = R.get(); |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 869 | } |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 870 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 871 | Hint.Range = SourceRange(Info->PragmaName.getLocation(), |
| 872 | Info->Toks[TokSize - 1].getLocation()); |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 873 | return true; |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | // #pragma GCC visibility comes in two variants: |
| 877 | // 'push' '(' [visibility] ')' |
| 878 | // 'pop' |
Douglas Gregor | c7d6576 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 879 | void PragmaGCCVisibilityHandler::HandlePragma(Preprocessor &PP, |
| 880 | PragmaIntroducerKind Introducer, |
| 881 | Token &VisTok) { |
Eli Friedman | 570024a | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 882 | SourceLocation VisLoc = VisTok.getLocation(); |
| 883 | |
| 884 | Token Tok; |
Joerg Sonnenberger | 869f0b7 | 2011-07-20 01:03:50 +0000 | [diff] [blame] | 885 | PP.LexUnexpandedToken(Tok); |
Eli Friedman | 570024a | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 886 | |
| 887 | const IdentifierInfo *PushPop = Tok.getIdentifierInfo(); |
| 888 | |
Eli Friedman | 570024a | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 889 | const IdentifierInfo *VisType; |
| 890 | if (PushPop && PushPop->isStr("pop")) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 891 | VisType = nullptr; |
Eli Friedman | 570024a | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 892 | } else if (PushPop && PushPop->isStr("push")) { |
Joerg Sonnenberger | 869f0b7 | 2011-07-20 01:03:50 +0000 | [diff] [blame] | 893 | PP.LexUnexpandedToken(Tok); |
Eli Friedman | 570024a | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 894 | if (Tok.isNot(tok::l_paren)) { |
| 895 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) |
| 896 | << "visibility"; |
| 897 | return; |
| 898 | } |
Joerg Sonnenberger | 869f0b7 | 2011-07-20 01:03:50 +0000 | [diff] [blame] | 899 | PP.LexUnexpandedToken(Tok); |
Eli Friedman | 570024a | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 900 | VisType = Tok.getIdentifierInfo(); |
| 901 | if (!VisType) { |
| 902 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) |
| 903 | << "visibility"; |
| 904 | return; |
| 905 | } |
Joerg Sonnenberger | 869f0b7 | 2011-07-20 01:03:50 +0000 | [diff] [blame] | 906 | PP.LexUnexpandedToken(Tok); |
Eli Friedman | 570024a | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 907 | if (Tok.isNot(tok::r_paren)) { |
| 908 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen) |
| 909 | << "visibility"; |
| 910 | return; |
| 911 | } |
| 912 | } else { |
| 913 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) |
| 914 | << "visibility"; |
| 915 | return; |
| 916 | } |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 917 | SourceLocation EndLoc = Tok.getLocation(); |
Joerg Sonnenberger | 869f0b7 | 2011-07-20 01:03:50 +0000 | [diff] [blame] | 918 | PP.LexUnexpandedToken(Tok); |
Peter Collingbourne | 2f1e36b | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 919 | if (Tok.isNot(tok::eod)) { |
Eli Friedman | 570024a | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 920 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
| 921 | << "visibility"; |
| 922 | return; |
| 923 | } |
| 924 | |
Rafael Espindola | 273fd77 | 2012-01-26 02:02:57 +0000 | [diff] [blame] | 925 | Token *Toks = new Token[1]; |
| 926 | Toks[0].startToken(); |
| 927 | Toks[0].setKind(tok::annot_pragma_vis); |
| 928 | Toks[0].setLocation(VisLoc); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 929 | Toks[0].setAnnotationEndLoc(EndLoc); |
Rafael Espindola | 273fd77 | 2012-01-26 02:02:57 +0000 | [diff] [blame] | 930 | Toks[0].setAnnotationValue( |
| 931 | const_cast<void*>(static_cast<const void*>(VisType))); |
| 932 | PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true, |
| 933 | /*OwnsTokens=*/true); |
Eli Friedman | 570024a | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 936 | // #pragma pack(...) comes in the following delicious flavors: |
| 937 | // pack '(' [integer] ')' |
| 938 | // pack '(' 'show' ')' |
| 939 | // pack '(' ('push' | 'pop') [',' identifier] [, integer] ')' |
Douglas Gregor | c7d6576 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 940 | void PragmaPackHandler::HandlePragma(Preprocessor &PP, |
| 941 | PragmaIntroducerKind Introducer, |
| 942 | Token &PackTok) { |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 943 | SourceLocation PackLoc = PackTok.getLocation(); |
| 944 | |
| 945 | Token Tok; |
| 946 | PP.Lex(Tok); |
| 947 | if (Tok.isNot(tok::l_paren)) { |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 948 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "pack"; |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 949 | return; |
| 950 | } |
| 951 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 952 | Sema::PragmaPackKind Kind = Sema::PPK_Default; |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 953 | IdentifierInfo *Name = nullptr; |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 954 | Token Alignment; |
| 955 | Alignment.startToken(); |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 956 | SourceLocation LParenLoc = Tok.getLocation(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 957 | PP.Lex(Tok); |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 958 | if (Tok.is(tok::numeric_constant)) { |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 959 | Alignment = Tok; |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 960 | |
| 961 | PP.Lex(Tok); |
Eli Friedman | 055c970 | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 962 | |
| 963 | // In MSVC/gcc, #pragma pack(4) sets the alignment without affecting |
| 964 | // the push/pop stack. |
| 965 | // In Apple gcc, #pragma pack(4) is equivalent to #pragma pack(push, 4) |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 966 | if (PP.getLangOpts().ApplePragmaPack) |
Eli Friedman | 055c970 | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 967 | Kind = Sema::PPK_Push; |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 968 | } else if (Tok.is(tok::identifier)) { |
| 969 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
Chris Lattner | e3d20d9 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 970 | if (II->isStr("show")) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 971 | Kind = Sema::PPK_Show; |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 972 | PP.Lex(Tok); |
| 973 | } else { |
Chris Lattner | e3d20d9 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 974 | if (II->isStr("push")) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 975 | Kind = Sema::PPK_Push; |
Chris Lattner | e3d20d9 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 976 | } else if (II->isStr("pop")) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 977 | Kind = Sema::PPK_Pop; |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 978 | } else { |
Reid Kleckner | c0dca6d | 2014-02-12 23:50:26 +0000 | [diff] [blame] | 979 | PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_action) << "pack"; |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 980 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | } |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 982 | PP.Lex(Tok); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 983 | |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 984 | if (Tok.is(tok::comma)) { |
| 985 | PP.Lex(Tok); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 | |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 987 | if (Tok.is(tok::numeric_constant)) { |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 988 | Alignment = Tok; |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 989 | |
| 990 | PP.Lex(Tok); |
| 991 | } else if (Tok.is(tok::identifier)) { |
| 992 | Name = Tok.getIdentifierInfo(); |
| 993 | PP.Lex(Tok); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 | |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 995 | if (Tok.is(tok::comma)) { |
| 996 | PP.Lex(Tok); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 997 | |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 998 | if (Tok.isNot(tok::numeric_constant)) { |
Chris Lattner | e3d20d9 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 999 | PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed); |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 1000 | return; |
| 1001 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1003 | Alignment = Tok; |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 1004 | |
| 1005 | PP.Lex(Tok); |
| 1006 | } |
| 1007 | } else { |
Chris Lattner | e3d20d9 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 1008 | PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed); |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 1009 | return; |
| 1010 | } |
| 1011 | } |
| 1012 | } |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1013 | } else if (PP.getLangOpts().ApplePragmaPack) { |
Eli Friedman | 055c970 | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 1014 | // In MSVC/gcc, #pragma pack() resets the alignment without affecting |
| 1015 | // the push/pop stack. |
| 1016 | // In Apple gcc #pragma pack() is equivalent to #pragma pack(pop). |
| 1017 | Kind = Sema::PPK_Pop; |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1018 | } |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 1019 | |
| 1020 | if (Tok.isNot(tok::r_paren)) { |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1021 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen) << "pack"; |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 1022 | return; |
| 1023 | } |
| 1024 | |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1025 | SourceLocation RParenLoc = Tok.getLocation(); |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1026 | PP.Lex(Tok); |
Peter Collingbourne | 2f1e36b | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 1027 | if (Tok.isNot(tok::eod)) { |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1028 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "pack"; |
| 1029 | return; |
| 1030 | } |
| 1031 | |
Daniel Dunbar | 340cf24 | 2012-02-29 01:38:22 +0000 | [diff] [blame] | 1032 | PragmaPackInfo *Info = |
| 1033 | (PragmaPackInfo*) PP.getPreprocessorAllocator().Allocate( |
| 1034 | sizeof(PragmaPackInfo), llvm::alignOf<PragmaPackInfo>()); |
| 1035 | new (Info) PragmaPackInfo(); |
Eli Friedman | ec52f92 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 1036 | Info->Kind = Kind; |
| 1037 | Info->Name = Name; |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1038 | Info->Alignment = Alignment; |
Eli Friedman | ec52f92 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 1039 | Info->LParenLoc = LParenLoc; |
| 1040 | Info->RParenLoc = RParenLoc; |
| 1041 | |
Daniel Dunbar | 340cf24 | 2012-02-29 01:38:22 +0000 | [diff] [blame] | 1042 | Token *Toks = |
| 1043 | (Token*) PP.getPreprocessorAllocator().Allocate( |
| 1044 | sizeof(Token) * 1, llvm::alignOf<Token>()); |
| 1045 | new (Toks) Token(); |
Eli Friedman | ec52f92 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 1046 | Toks[0].startToken(); |
| 1047 | Toks[0].setKind(tok::annot_pragma_pack); |
| 1048 | Toks[0].setLocation(PackLoc); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1049 | Toks[0].setAnnotationEndLoc(RParenLoc); |
Eli Friedman | ec52f92 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 1050 | Toks[0].setAnnotationValue(static_cast<void*>(Info)); |
| 1051 | PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true, |
Daniel Dunbar | 340cf24 | 2012-02-29 01:38:22 +0000 | [diff] [blame] | 1052 | /*OwnsTokens=*/false); |
Daniel Dunbar | 921b968 | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Fariborz Jahanian | 743dda4 | 2011-04-25 18:49:15 +0000 | [diff] [blame] | 1055 | // #pragma ms_struct on |
| 1056 | // #pragma ms_struct off |
| 1057 | void PragmaMSStructHandler::HandlePragma(Preprocessor &PP, |
| 1058 | PragmaIntroducerKind Introducer, |
| 1059 | Token &MSStructTok) { |
| 1060 | Sema::PragmaMSStructKind Kind = Sema::PMSST_OFF; |
| 1061 | |
| 1062 | Token Tok; |
| 1063 | PP.Lex(Tok); |
| 1064 | if (Tok.isNot(tok::identifier)) { |
| 1065 | PP.Diag(Tok.getLocation(), diag::warn_pragma_ms_struct); |
| 1066 | return; |
| 1067 | } |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1068 | SourceLocation EndLoc = Tok.getLocation(); |
Fariborz Jahanian | 743dda4 | 2011-04-25 18:49:15 +0000 | [diff] [blame] | 1069 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1070 | if (II->isStr("on")) { |
| 1071 | Kind = Sema::PMSST_ON; |
| 1072 | PP.Lex(Tok); |
| 1073 | } |
| 1074 | else if (II->isStr("off") || II->isStr("reset")) |
| 1075 | PP.Lex(Tok); |
| 1076 | else { |
| 1077 | PP.Diag(Tok.getLocation(), diag::warn_pragma_ms_struct); |
| 1078 | return; |
| 1079 | } |
| 1080 | |
| 1081 | if (Tok.isNot(tok::eod)) { |
Daniel Dunbar | 340cf24 | 2012-02-29 01:38:22 +0000 | [diff] [blame] | 1082 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
| 1083 | << "ms_struct"; |
Fariborz Jahanian | 743dda4 | 2011-04-25 18:49:15 +0000 | [diff] [blame] | 1084 | return; |
| 1085 | } |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1086 | |
| 1087 | Token *Toks = |
| 1088 | (Token*) PP.getPreprocessorAllocator().Allocate( |
| 1089 | sizeof(Token) * 1, llvm::alignOf<Token>()); |
| 1090 | new (Toks) Token(); |
| 1091 | Toks[0].startToken(); |
| 1092 | Toks[0].setKind(tok::annot_pragma_msstruct); |
| 1093 | Toks[0].setLocation(MSStructTok.getLocation()); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1094 | Toks[0].setAnnotationEndLoc(EndLoc); |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1095 | Toks[0].setAnnotationValue(reinterpret_cast<void*>( |
| 1096 | static_cast<uintptr_t>(Kind))); |
| 1097 | PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true, |
| 1098 | /*OwnsTokens=*/false); |
Fariborz Jahanian | 743dda4 | 2011-04-25 18:49:15 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
Daniel Dunbar | cb82acb | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 1101 | // #pragma 'align' '=' {'native','natural','mac68k','power','reset'} |
| 1102 | // #pragma 'options 'align' '=' {'native','natural','mac68k','power','reset'} |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1103 | static void ParseAlignPragma(Preprocessor &PP, Token &FirstTok, |
Daniel Dunbar | cb82acb | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 1104 | bool IsOptions) { |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1105 | Token Tok; |
Daniel Dunbar | cb82acb | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 1106 | |
| 1107 | if (IsOptions) { |
| 1108 | PP.Lex(Tok); |
| 1109 | if (Tok.isNot(tok::identifier) || |
| 1110 | !Tok.getIdentifierInfo()->isStr("align")) { |
| 1111 | PP.Diag(Tok.getLocation(), diag::warn_pragma_options_expected_align); |
| 1112 | return; |
| 1113 | } |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1114 | } |
Daniel Dunbar | 663e809 | 2010-05-27 18:42:09 +0000 | [diff] [blame] | 1115 | |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1116 | PP.Lex(Tok); |
| 1117 | if (Tok.isNot(tok::equal)) { |
Daniel Dunbar | cb82acb | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 1118 | PP.Diag(Tok.getLocation(), diag::warn_pragma_align_expected_equal) |
| 1119 | << IsOptions; |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1120 | return; |
| 1121 | } |
| 1122 | |
| 1123 | PP.Lex(Tok); |
| 1124 | if (Tok.isNot(tok::identifier)) { |
| 1125 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) |
Daniel Dunbar | cb82acb | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 1126 | << (IsOptions ? "options" : "align"); |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1127 | return; |
| 1128 | } |
| 1129 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1130 | Sema::PragmaOptionsAlignKind Kind = Sema::POAK_Natural; |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1131 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
Daniel Dunbar | 663e809 | 2010-05-27 18:42:09 +0000 | [diff] [blame] | 1132 | if (II->isStr("native")) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1133 | Kind = Sema::POAK_Native; |
Daniel Dunbar | 663e809 | 2010-05-27 18:42:09 +0000 | [diff] [blame] | 1134 | else if (II->isStr("natural")) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1135 | Kind = Sema::POAK_Natural; |
Daniel Dunbar | 9c84d4a | 2010-05-27 18:42:17 +0000 | [diff] [blame] | 1136 | else if (II->isStr("packed")) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1137 | Kind = Sema::POAK_Packed; |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1138 | else if (II->isStr("power")) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1139 | Kind = Sema::POAK_Power; |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1140 | else if (II->isStr("mac68k")) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1141 | Kind = Sema::POAK_Mac68k; |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1142 | else if (II->isStr("reset")) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1143 | Kind = Sema::POAK_Reset; |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1144 | else { |
Daniel Dunbar | cb82acb | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 1145 | PP.Diag(Tok.getLocation(), diag::warn_pragma_align_invalid_option) |
| 1146 | << IsOptions; |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1147 | return; |
| 1148 | } |
| 1149 | |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1150 | SourceLocation EndLoc = Tok.getLocation(); |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1151 | PP.Lex(Tok); |
Peter Collingbourne | 2f1e36b | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 1152 | if (Tok.isNot(tok::eod)) { |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1153 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
Daniel Dunbar | cb82acb | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 1154 | << (IsOptions ? "options" : "align"); |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1155 | return; |
| 1156 | } |
| 1157 | |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1158 | Token *Toks = |
| 1159 | (Token*) PP.getPreprocessorAllocator().Allocate( |
| 1160 | sizeof(Token) * 1, llvm::alignOf<Token>()); |
| 1161 | new (Toks) Token(); |
| 1162 | Toks[0].startToken(); |
| 1163 | Toks[0].setKind(tok::annot_pragma_align); |
| 1164 | Toks[0].setLocation(FirstTok.getLocation()); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1165 | Toks[0].setAnnotationEndLoc(EndLoc); |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1166 | Toks[0].setAnnotationValue(reinterpret_cast<void*>( |
| 1167 | static_cast<uintptr_t>(Kind))); |
| 1168 | PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true, |
| 1169 | /*OwnsTokens=*/false); |
Daniel Dunbar | cb82acb | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
Douglas Gregor | c7d6576 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 1172 | void PragmaAlignHandler::HandlePragma(Preprocessor &PP, |
| 1173 | PragmaIntroducerKind Introducer, |
| 1174 | Token &AlignTok) { |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1175 | ParseAlignPragma(PP, AlignTok, /*IsOptions=*/false); |
Daniel Dunbar | cb82acb | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
Douglas Gregor | c7d6576 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 1178 | void PragmaOptionsHandler::HandlePragma(Preprocessor &PP, |
| 1179 | PragmaIntroducerKind Introducer, |
| 1180 | Token &OptionsTok) { |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1181 | ParseAlignPragma(PP, OptionsTok, /*IsOptions=*/true); |
Daniel Dunbar | 75c9be7 | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1184 | // #pragma unused(identifier) |
Douglas Gregor | c7d6576 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 1185 | void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, |
| 1186 | PragmaIntroducerKind Introducer, |
| 1187 | Token &UnusedTok) { |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1188 | // FIXME: Should we be expanding macros here? My guess is no. |
| 1189 | SourceLocation UnusedLoc = UnusedTok.getLocation(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1190 | |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1191 | // Lex the left '('. |
| 1192 | Token Tok; |
| 1193 | PP.Lex(Tok); |
| 1194 | if (Tok.isNot(tok::l_paren)) { |
| 1195 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "unused"; |
| 1196 | return; |
| 1197 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1198 | |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1199 | // Lex the declaration reference(s). |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1200 | SmallVector<Token, 5> Identifiers; |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1201 | SourceLocation RParenLoc; |
| 1202 | bool LexID = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1203 | |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1204 | while (true) { |
| 1205 | PP.Lex(Tok); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1206 | |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1207 | if (LexID) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1208 | if (Tok.is(tok::identifier)) { |
Ted Kremenek | fb50bf5 | 2009-08-03 23:24:57 +0000 | [diff] [blame] | 1209 | Identifiers.push_back(Tok); |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1210 | LexID = false; |
| 1211 | continue; |
| 1212 | } |
| 1213 | |
Ted Kremenek | fb50bf5 | 2009-08-03 23:24:57 +0000 | [diff] [blame] | 1214 | // Illegal token! |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1215 | PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_var); |
| 1216 | return; |
| 1217 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1218 | |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1219 | // We are execting a ')' or a ','. |
| 1220 | if (Tok.is(tok::comma)) { |
| 1221 | LexID = true; |
| 1222 | continue; |
| 1223 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1225 | if (Tok.is(tok::r_paren)) { |
| 1226 | RParenLoc = Tok.getLocation(); |
| 1227 | break; |
| 1228 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | |
Ted Kremenek | fb50bf5 | 2009-08-03 23:24:57 +0000 | [diff] [blame] | 1230 | // Illegal token! |
David Majnemer | 8896981 | 2014-02-10 19:06:37 +0000 | [diff] [blame] | 1231 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_punc) << "unused"; |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1232 | return; |
| 1233 | } |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1234 | |
| 1235 | PP.Lex(Tok); |
Peter Collingbourne | 2f1e36b | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 1236 | if (Tok.isNot(tok::eod)) { |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1237 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << |
| 1238 | "unused"; |
| 1239 | return; |
| 1240 | } |
| 1241 | |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1242 | // Verify that we have a location for the right parenthesis. |
| 1243 | assert(RParenLoc.isValid() && "Valid '#pragma unused' must have ')'"); |
Ted Kremenek | fb50bf5 | 2009-08-03 23:24:57 +0000 | [diff] [blame] | 1244 | assert(!Identifiers.empty() && "Valid '#pragma unused' must have arguments"); |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1245 | |
Argyrios Kyrtzidis | ee56962 | 2011-01-17 18:58:44 +0000 | [diff] [blame] | 1246 | // For each identifier token, insert into the token stream a |
| 1247 | // annot_pragma_unused token followed by the identifier token. |
| 1248 | // This allows us to cache a "#pragma unused" that occurs inside an inline |
| 1249 | // C++ member function. |
| 1250 | |
Daniel Dunbar | 340cf24 | 2012-02-29 01:38:22 +0000 | [diff] [blame] | 1251 | Token *Toks = |
| 1252 | (Token*) PP.getPreprocessorAllocator().Allocate( |
| 1253 | sizeof(Token) * 2 * Identifiers.size(), llvm::alignOf<Token>()); |
Argyrios Kyrtzidis | ee56962 | 2011-01-17 18:58:44 +0000 | [diff] [blame] | 1254 | for (unsigned i=0; i != Identifiers.size(); i++) { |
| 1255 | Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1]; |
| 1256 | pragmaUnusedTok.startToken(); |
| 1257 | pragmaUnusedTok.setKind(tok::annot_pragma_unused); |
| 1258 | pragmaUnusedTok.setLocation(UnusedLoc); |
| 1259 | idTok = Identifiers[i]; |
| 1260 | } |
Daniel Dunbar | 340cf24 | 2012-02-29 01:38:22 +0000 | [diff] [blame] | 1261 | PP.EnterTokenStream(Toks, 2*Identifiers.size(), |
| 1262 | /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false); |
Ted Kremenek | fd14fad | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 1263 | } |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1264 | |
| 1265 | // #pragma weak identifier |
| 1266 | // #pragma weak identifier '=' identifier |
Douglas Gregor | c7d6576 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 1267 | void PragmaWeakHandler::HandlePragma(Preprocessor &PP, |
| 1268 | PragmaIntroducerKind Introducer, |
| 1269 | Token &WeakTok) { |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1270 | SourceLocation WeakLoc = WeakTok.getLocation(); |
| 1271 | |
| 1272 | Token Tok; |
| 1273 | PP.Lex(Tok); |
| 1274 | if (Tok.isNot(tok::identifier)) { |
| 1275 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) << "weak"; |
| 1276 | return; |
| 1277 | } |
| 1278 | |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1279 | Token WeakName = Tok; |
| 1280 | bool HasAlias = false; |
| 1281 | Token AliasName; |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1282 | |
| 1283 | PP.Lex(Tok); |
| 1284 | if (Tok.is(tok::equal)) { |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1285 | HasAlias = true; |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1286 | PP.Lex(Tok); |
| 1287 | if (Tok.isNot(tok::identifier)) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1288 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1289 | << "weak"; |
| 1290 | return; |
| 1291 | } |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1292 | AliasName = Tok; |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1293 | PP.Lex(Tok); |
| 1294 | } |
| 1295 | |
Peter Collingbourne | 2f1e36b | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 1296 | if (Tok.isNot(tok::eod)) { |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1297 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "weak"; |
| 1298 | return; |
| 1299 | } |
| 1300 | |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1301 | if (HasAlias) { |
| 1302 | Token *Toks = |
| 1303 | (Token*) PP.getPreprocessorAllocator().Allocate( |
| 1304 | sizeof(Token) * 3, llvm::alignOf<Token>()); |
| 1305 | Token &pragmaUnusedTok = Toks[0]; |
| 1306 | pragmaUnusedTok.startToken(); |
| 1307 | pragmaUnusedTok.setKind(tok::annot_pragma_weakalias); |
| 1308 | pragmaUnusedTok.setLocation(WeakLoc); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1309 | pragmaUnusedTok.setAnnotationEndLoc(AliasName.getLocation()); |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1310 | Toks[1] = WeakName; |
| 1311 | Toks[2] = AliasName; |
| 1312 | PP.EnterTokenStream(Toks, 3, |
| 1313 | /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false); |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1314 | } else { |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1315 | Token *Toks = |
| 1316 | (Token*) PP.getPreprocessorAllocator().Allocate( |
| 1317 | sizeof(Token) * 2, llvm::alignOf<Token>()); |
| 1318 | Token &pragmaUnusedTok = Toks[0]; |
| 1319 | pragmaUnusedTok.startToken(); |
| 1320 | pragmaUnusedTok.setKind(tok::annot_pragma_weak); |
| 1321 | pragmaUnusedTok.setLocation(WeakLoc); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1322 | pragmaUnusedTok.setAnnotationEndLoc(WeakLoc); |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1323 | Toks[1] = WeakName; |
| 1324 | PP.EnterTokenStream(Toks, 2, |
| 1325 | /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false); |
Eli Friedman | f5867dd | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 1326 | } |
| 1327 | } |
Peter Collingbourne | 564c0fa | 2011-02-14 01:42:35 +0000 | [diff] [blame] | 1328 | |
David Chisnall | 0867d9c | 2012-02-18 16:12:34 +0000 | [diff] [blame] | 1329 | // #pragma redefine_extname identifier identifier |
| 1330 | void PragmaRedefineExtnameHandler::HandlePragma(Preprocessor &PP, |
| 1331 | PragmaIntroducerKind Introducer, |
| 1332 | Token &RedefToken) { |
| 1333 | SourceLocation RedefLoc = RedefToken.getLocation(); |
| 1334 | |
| 1335 | Token Tok; |
| 1336 | PP.Lex(Tok); |
| 1337 | if (Tok.isNot(tok::identifier)) { |
| 1338 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) << |
| 1339 | "redefine_extname"; |
| 1340 | return; |
| 1341 | } |
| 1342 | |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1343 | Token RedefName = Tok; |
David Chisnall | 0867d9c | 2012-02-18 16:12:34 +0000 | [diff] [blame] | 1344 | PP.Lex(Tok); |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1345 | |
David Chisnall | 0867d9c | 2012-02-18 16:12:34 +0000 | [diff] [blame] | 1346 | if (Tok.isNot(tok::identifier)) { |
| 1347 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) |
| 1348 | << "redefine_extname"; |
| 1349 | return; |
| 1350 | } |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1351 | |
| 1352 | Token AliasName = Tok; |
David Chisnall | 0867d9c | 2012-02-18 16:12:34 +0000 | [diff] [blame] | 1353 | PP.Lex(Tok); |
| 1354 | |
| 1355 | if (Tok.isNot(tok::eod)) { |
| 1356 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << |
| 1357 | "redefine_extname"; |
| 1358 | return; |
| 1359 | } |
| 1360 | |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1361 | Token *Toks = |
| 1362 | (Token*) PP.getPreprocessorAllocator().Allocate( |
| 1363 | sizeof(Token) * 3, llvm::alignOf<Token>()); |
| 1364 | Token &pragmaRedefTok = Toks[0]; |
| 1365 | pragmaRedefTok.startToken(); |
| 1366 | pragmaRedefTok.setKind(tok::annot_pragma_redefine_extname); |
| 1367 | pragmaRedefTok.setLocation(RedefLoc); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1368 | pragmaRedefTok.setAnnotationEndLoc(AliasName.getLocation()); |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1369 | Toks[1] = RedefName; |
| 1370 | Toks[2] = AliasName; |
| 1371 | PP.EnterTokenStream(Toks, 3, |
| 1372 | /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false); |
David Chisnall | 0867d9c | 2012-02-18 16:12:34 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | |
Peter Collingbourne | 564c0fa | 2011-02-14 01:42:35 +0000 | [diff] [blame] | 1376 | void |
| 1377 | PragmaFPContractHandler::HandlePragma(Preprocessor &PP, |
| 1378 | PragmaIntroducerKind Introducer, |
| 1379 | Token &Tok) { |
| 1380 | tok::OnOffSwitch OOS; |
| 1381 | if (PP.LexOnOffSwitch(OOS)) |
| 1382 | return; |
| 1383 | |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1384 | Token *Toks = |
| 1385 | (Token*) PP.getPreprocessorAllocator().Allocate( |
| 1386 | sizeof(Token) * 1, llvm::alignOf<Token>()); |
| 1387 | new (Toks) Token(); |
| 1388 | Toks[0].startToken(); |
| 1389 | Toks[0].setKind(tok::annot_pragma_fp_contract); |
| 1390 | Toks[0].setLocation(Tok.getLocation()); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1391 | Toks[0].setAnnotationEndLoc(Tok.getLocation()); |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1392 | Toks[0].setAnnotationValue(reinterpret_cast<void*>( |
| 1393 | static_cast<uintptr_t>(OOS))); |
| 1394 | PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true, |
| 1395 | /*OwnsTokens=*/false); |
Peter Collingbourne | 564c0fa | 2011-02-14 01:42:35 +0000 | [diff] [blame] | 1396 | } |
Peter Collingbourne | 7ce13fc | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 1397 | |
| 1398 | void |
| 1399 | PragmaOpenCLExtensionHandler::HandlePragma(Preprocessor &PP, |
| 1400 | PragmaIntroducerKind Introducer, |
| 1401 | Token &Tok) { |
Tanya Lattner | ee840b8 | 2011-04-14 23:35:31 +0000 | [diff] [blame] | 1402 | PP.LexUnexpandedToken(Tok); |
Peter Collingbourne | 7ce13fc | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 1403 | if (Tok.isNot(tok::identifier)) { |
| 1404 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) << |
| 1405 | "OPENCL"; |
| 1406 | return; |
| 1407 | } |
| 1408 | IdentifierInfo *ename = Tok.getIdentifierInfo(); |
| 1409 | SourceLocation NameLoc = Tok.getLocation(); |
| 1410 | |
| 1411 | PP.Lex(Tok); |
| 1412 | if (Tok.isNot(tok::colon)) { |
| 1413 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_colon) << ename; |
| 1414 | return; |
| 1415 | } |
| 1416 | |
| 1417 | PP.Lex(Tok); |
| 1418 | if (Tok.isNot(tok::identifier)) { |
| 1419 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_enable_disable); |
| 1420 | return; |
| 1421 | } |
| 1422 | IdentifierInfo *op = Tok.getIdentifierInfo(); |
| 1423 | |
| 1424 | unsigned state; |
| 1425 | if (op->isStr("enable")) { |
| 1426 | state = 1; |
| 1427 | } else if (op->isStr("disable")) { |
| 1428 | state = 0; |
| 1429 | } else { |
| 1430 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_enable_disable); |
| 1431 | return; |
| 1432 | } |
Pekka Jaaskelainen | 1db1da2 | 2013-10-12 09:29:48 +0000 | [diff] [blame] | 1433 | SourceLocation StateLoc = Tok.getLocation(); |
Peter Collingbourne | 7ce13fc | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 1434 | |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1435 | PP.Lex(Tok); |
| 1436 | if (Tok.isNot(tok::eod)) { |
| 1437 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << |
| 1438 | "OPENCL EXTENSION"; |
Peter Collingbourne | 7ce13fc | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 1439 | return; |
| 1440 | } |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1441 | |
| 1442 | OpenCLExtData data(ename, state); |
| 1443 | Token *Toks = |
| 1444 | (Token*) PP.getPreprocessorAllocator().Allocate( |
| 1445 | sizeof(Token) * 1, llvm::alignOf<Token>()); |
| 1446 | new (Toks) Token(); |
| 1447 | Toks[0].startToken(); |
| 1448 | Toks[0].setKind(tok::annot_pragma_opencl_extension); |
| 1449 | Toks[0].setLocation(NameLoc); |
| 1450 | Toks[0].setAnnotationValue(data.getOpaqueValue()); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1451 | Toks[0].setAnnotationEndLoc(StateLoc); |
Eli Friedman | 68be164 | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 1452 | PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true, |
| 1453 | /*OwnsTokens=*/false); |
Pekka Jaaskelainen | 1db1da2 | 2013-10-12 09:29:48 +0000 | [diff] [blame] | 1454 | |
| 1455 | if (PP.getPPCallbacks()) |
| 1456 | PP.getPPCallbacks()->PragmaOpenCLExtension(NameLoc, ename, |
| 1457 | StateLoc, state); |
Peter Collingbourne | 7ce13fc | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1460 | /// \brief Handle '#pragma omp ...' when OpenMP is disabled. |
| 1461 | /// |
| 1462 | void |
| 1463 | PragmaNoOpenMPHandler::HandlePragma(Preprocessor &PP, |
| 1464 | PragmaIntroducerKind Introducer, |
| 1465 | Token &FirstTok) { |
Alp Toker | d4a3f0e | 2014-06-15 23:30:39 +0000 | [diff] [blame] | 1466 | if (!PP.getDiagnostics().isIgnored(diag::warn_pragma_omp_ignored, |
| 1467 | FirstTok.getLocation())) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1468 | PP.Diag(FirstTok, diag::warn_pragma_omp_ignored); |
Alp Toker | d576e00 | 2014-06-12 11:13:52 +0000 | [diff] [blame] | 1469 | PP.getDiagnostics().setSeverity(diag::warn_pragma_omp_ignored, |
| 1470 | diag::Severity::Ignored, SourceLocation()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1471 | } |
| 1472 | PP.DiscardUntilEndOfDirective(); |
| 1473 | } |
| 1474 | |
| 1475 | /// \brief Handle '#pragma omp ...' when OpenMP is enabled. |
| 1476 | /// |
| 1477 | void |
| 1478 | PragmaOpenMPHandler::HandlePragma(Preprocessor &PP, |
| 1479 | PragmaIntroducerKind Introducer, |
| 1480 | Token &FirstTok) { |
| 1481 | SmallVector<Token, 16> Pragma; |
| 1482 | Token Tok; |
| 1483 | Tok.startToken(); |
| 1484 | Tok.setKind(tok::annot_pragma_openmp); |
| 1485 | Tok.setLocation(FirstTok.getLocation()); |
| 1486 | |
| 1487 | while (Tok.isNot(tok::eod)) { |
| 1488 | Pragma.push_back(Tok); |
| 1489 | PP.Lex(Tok); |
| 1490 | } |
| 1491 | SourceLocation EodLoc = Tok.getLocation(); |
| 1492 | Tok.startToken(); |
| 1493 | Tok.setKind(tok::annot_pragma_openmp_end); |
| 1494 | Tok.setLocation(EodLoc); |
| 1495 | Pragma.push_back(Tok); |
| 1496 | |
| 1497 | Token *Toks = new Token[Pragma.size()]; |
| 1498 | std::copy(Pragma.begin(), Pragma.end(), Toks); |
| 1499 | PP.EnterTokenStream(Toks, Pragma.size(), |
Alexey Bataev | c895679 | 2015-05-05 09:53:25 +0000 | [diff] [blame] | 1500 | /*DisableMacroExpansion=*/false, /*OwnsTokens=*/true); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1501 | } |
Reid Kleckner | 002562a | 2013-05-06 21:02:12 +0000 | [diff] [blame] | 1502 | |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 1503 | /// \brief Handle '#pragma pointers_to_members' |
| 1504 | // The grammar for this pragma is as follows: |
| 1505 | // |
| 1506 | // <inheritance model> ::= ('single' | 'multiple' | 'virtual') '_inheritance' |
| 1507 | // |
| 1508 | // #pragma pointers_to_members '(' 'best_case' ')' |
| 1509 | // #pragma pointers_to_members '(' 'full_generality' [',' inheritance-model] ')' |
| 1510 | // #pragma pointers_to_members '(' inheritance-model ')' |
| 1511 | void PragmaMSPointersToMembers::HandlePragma(Preprocessor &PP, |
| 1512 | PragmaIntroducerKind Introducer, |
| 1513 | Token &Tok) { |
| 1514 | SourceLocation PointersToMembersLoc = Tok.getLocation(); |
| 1515 | PP.Lex(Tok); |
| 1516 | if (Tok.isNot(tok::l_paren)) { |
| 1517 | PP.Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen) |
| 1518 | << "pointers_to_members"; |
| 1519 | return; |
| 1520 | } |
| 1521 | PP.Lex(Tok); |
| 1522 | const IdentifierInfo *Arg = Tok.getIdentifierInfo(); |
| 1523 | if (!Arg) { |
| 1524 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) |
| 1525 | << "pointers_to_members"; |
| 1526 | return; |
| 1527 | } |
| 1528 | PP.Lex(Tok); |
| 1529 | |
David Majnemer | 86c318f | 2014-02-11 21:05:00 +0000 | [diff] [blame] | 1530 | LangOptions::PragmaMSPointersToMembersKind RepresentationMethod; |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 1531 | if (Arg->isStr("best_case")) { |
David Majnemer | 86c318f | 2014-02-11 21:05:00 +0000 | [diff] [blame] | 1532 | RepresentationMethod = LangOptions::PPTMK_BestCase; |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 1533 | } else { |
| 1534 | if (Arg->isStr("full_generality")) { |
| 1535 | if (Tok.is(tok::comma)) { |
| 1536 | PP.Lex(Tok); |
| 1537 | |
| 1538 | Arg = Tok.getIdentifierInfo(); |
| 1539 | if (!Arg) { |
| 1540 | PP.Diag(Tok.getLocation(), |
| 1541 | diag::err_pragma_pointers_to_members_unknown_kind) |
| 1542 | << Tok.getKind() << /*OnlyInheritanceModels*/ 0; |
| 1543 | return; |
| 1544 | } |
| 1545 | PP.Lex(Tok); |
| 1546 | } else if (Tok.is(tok::r_paren)) { |
| 1547 | // #pragma pointers_to_members(full_generality) implicitly specifies |
| 1548 | // virtual_inheritance. |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1549 | Arg = nullptr; |
David Majnemer | 86c318f | 2014-02-11 21:05:00 +0000 | [diff] [blame] | 1550 | RepresentationMethod = LangOptions::PPTMK_FullGeneralityVirtualInheritance; |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 1551 | } else { |
| 1552 | PP.Diag(Tok.getLocation(), diag::err_expected_punc) |
| 1553 | << "full_generality"; |
| 1554 | return; |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | if (Arg) { |
| 1559 | if (Arg->isStr("single_inheritance")) { |
David Majnemer | 86c318f | 2014-02-11 21:05:00 +0000 | [diff] [blame] | 1560 | RepresentationMethod = |
| 1561 | LangOptions::PPTMK_FullGeneralitySingleInheritance; |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 1562 | } else if (Arg->isStr("multiple_inheritance")) { |
David Majnemer | 86c318f | 2014-02-11 21:05:00 +0000 | [diff] [blame] | 1563 | RepresentationMethod = |
| 1564 | LangOptions::PPTMK_FullGeneralityMultipleInheritance; |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 1565 | } else if (Arg->isStr("virtual_inheritance")) { |
David Majnemer | 86c318f | 2014-02-11 21:05:00 +0000 | [diff] [blame] | 1566 | RepresentationMethod = |
| 1567 | LangOptions::PPTMK_FullGeneralityVirtualInheritance; |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 1568 | } else { |
| 1569 | PP.Diag(Tok.getLocation(), |
| 1570 | diag::err_pragma_pointers_to_members_unknown_kind) |
| 1571 | << Arg << /*HasPointerDeclaration*/ 1; |
| 1572 | return; |
| 1573 | } |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | if (Tok.isNot(tok::r_paren)) { |
| 1578 | PP.Diag(Tok.getLocation(), diag::err_expected_rparen_after) |
| 1579 | << (Arg ? Arg->getName() : "full_generality"); |
| 1580 | return; |
| 1581 | } |
| 1582 | |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1583 | SourceLocation EndLoc = Tok.getLocation(); |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 1584 | PP.Lex(Tok); |
| 1585 | if (Tok.isNot(tok::eod)) { |
| 1586 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
| 1587 | << "pointers_to_members"; |
| 1588 | return; |
| 1589 | } |
| 1590 | |
| 1591 | Token AnnotTok; |
| 1592 | AnnotTok.startToken(); |
| 1593 | AnnotTok.setKind(tok::annot_pragma_ms_pointers_to_members); |
| 1594 | AnnotTok.setLocation(PointersToMembersLoc); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1595 | AnnotTok.setAnnotationEndLoc(EndLoc); |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 1596 | AnnotTok.setAnnotationValue( |
| 1597 | reinterpret_cast<void *>(static_cast<uintptr_t>(RepresentationMethod))); |
| 1598 | PP.EnterToken(AnnotTok); |
| 1599 | } |
| 1600 | |
Reid Kleckner | c0dca6d | 2014-02-12 23:50:26 +0000 | [diff] [blame] | 1601 | /// \brief Handle '#pragma vtordisp' |
| 1602 | // The grammar for this pragma is as follows: |
| 1603 | // |
| 1604 | // <vtordisp-mode> ::= ('off' | 'on' | '0' | '1' | '2' ) |
| 1605 | // |
| 1606 | // #pragma vtordisp '(' ['push' ','] vtordisp-mode ')' |
| 1607 | // #pragma vtordisp '(' 'pop' ')' |
| 1608 | // #pragma vtordisp '(' ')' |
| 1609 | void PragmaMSVtorDisp::HandlePragma(Preprocessor &PP, |
| 1610 | PragmaIntroducerKind Introducer, |
| 1611 | Token &Tok) { |
| 1612 | SourceLocation VtorDispLoc = Tok.getLocation(); |
| 1613 | PP.Lex(Tok); |
| 1614 | if (Tok.isNot(tok::l_paren)) { |
| 1615 | PP.Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) << "vtordisp"; |
| 1616 | return; |
| 1617 | } |
| 1618 | PP.Lex(Tok); |
| 1619 | |
| 1620 | Sema::PragmaVtorDispKind Kind = Sema::PVDK_Set; |
| 1621 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1622 | if (II) { |
| 1623 | if (II->isStr("push")) { |
| 1624 | // #pragma vtordisp(push, mode) |
| 1625 | PP.Lex(Tok); |
| 1626 | if (Tok.isNot(tok::comma)) { |
| 1627 | PP.Diag(VtorDispLoc, diag::warn_pragma_expected_punc) << "vtordisp"; |
| 1628 | return; |
| 1629 | } |
| 1630 | PP.Lex(Tok); |
| 1631 | Kind = Sema::PVDK_Push; |
| 1632 | // not push, could be on/off |
| 1633 | } else if (II->isStr("pop")) { |
| 1634 | // #pragma vtordisp(pop) |
| 1635 | PP.Lex(Tok); |
| 1636 | Kind = Sema::PVDK_Pop; |
| 1637 | } |
| 1638 | // not push or pop, could be on/off |
| 1639 | } else { |
| 1640 | if (Tok.is(tok::r_paren)) { |
| 1641 | // #pragma vtordisp() |
| 1642 | Kind = Sema::PVDK_Reset; |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | |
Reid Kleckner | a4b3b2d | 2014-02-13 00:44:34 +0000 | [diff] [blame] | 1647 | uint64_t Value = 0; |
Reid Kleckner | c0dca6d | 2014-02-12 23:50:26 +0000 | [diff] [blame] | 1648 | if (Kind == Sema::PVDK_Push || Kind == Sema::PVDK_Set) { |
| 1649 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1650 | if (II && II->isStr("off")) { |
| 1651 | PP.Lex(Tok); |
| 1652 | Value = 0; |
| 1653 | } else if (II && II->isStr("on")) { |
| 1654 | PP.Lex(Tok); |
| 1655 | Value = 1; |
| 1656 | } else if (Tok.is(tok::numeric_constant) && |
| 1657 | PP.parseSimpleIntegerLiteral(Tok, Value)) { |
| 1658 | if (Value > 2) { |
| 1659 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_integer) |
| 1660 | << 0 << 2 << "vtordisp"; |
| 1661 | return; |
| 1662 | } |
| 1663 | } else { |
| 1664 | PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_action) |
| 1665 | << "vtordisp"; |
| 1666 | return; |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | // Finish the pragma: ')' $ |
| 1671 | if (Tok.isNot(tok::r_paren)) { |
| 1672 | PP.Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) << "vtordisp"; |
| 1673 | return; |
| 1674 | } |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1675 | SourceLocation EndLoc = Tok.getLocation(); |
Reid Kleckner | c0dca6d | 2014-02-12 23:50:26 +0000 | [diff] [blame] | 1676 | PP.Lex(Tok); |
| 1677 | if (Tok.isNot(tok::eod)) { |
| 1678 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
| 1679 | << "vtordisp"; |
| 1680 | return; |
| 1681 | } |
| 1682 | |
| 1683 | // Enter the annotation. |
| 1684 | Token AnnotTok; |
| 1685 | AnnotTok.startToken(); |
| 1686 | AnnotTok.setKind(tok::annot_pragma_ms_vtordisp); |
| 1687 | AnnotTok.setLocation(VtorDispLoc); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1688 | AnnotTok.setAnnotationEndLoc(EndLoc); |
Reid Kleckner | a4b3b2d | 2014-02-13 00:44:34 +0000 | [diff] [blame] | 1689 | AnnotTok.setAnnotationValue(reinterpret_cast<void *>( |
| 1690 | static_cast<uintptr_t>((Kind << 16) | (Value & 0xFFFF)))); |
Reid Kleckner | c0dca6d | 2014-02-12 23:50:26 +0000 | [diff] [blame] | 1691 | PP.EnterToken(AnnotTok); |
| 1692 | } |
| 1693 | |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 1694 | /// \brief Handle all MS pragmas. Simply forwards the tokens after inserting |
| 1695 | /// an annotation token. |
| 1696 | void PragmaMSPragma::HandlePragma(Preprocessor &PP, |
| 1697 | PragmaIntroducerKind Introducer, |
| 1698 | Token &Tok) { |
| 1699 | Token EoF, AnnotTok; |
| 1700 | EoF.startToken(); |
| 1701 | EoF.setKind(tok::eof); |
| 1702 | AnnotTok.startToken(); |
| 1703 | AnnotTok.setKind(tok::annot_pragma_ms_pragma); |
| 1704 | AnnotTok.setLocation(Tok.getLocation()); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1705 | AnnotTok.setAnnotationEndLoc(Tok.getLocation()); |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 1706 | SmallVector<Token, 8> TokenVector; |
| 1707 | // Suck up all of the tokens before the eod. |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1708 | for (; Tok.isNot(tok::eod); PP.Lex(Tok)) { |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 1709 | TokenVector.push_back(Tok); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 1710 | AnnotTok.setAnnotationEndLoc(Tok.getLocation()); |
| 1711 | } |
Warren Hunt | c3b1896 | 2014-04-08 22:30:47 +0000 | [diff] [blame] | 1712 | // Add a sentinal EoF token to the end of the list. |
| 1713 | TokenVector.push_back(EoF); |
| 1714 | // We must allocate this array with new because EnterTokenStream is going to |
| 1715 | // delete it later. |
| 1716 | Token *TokenArray = new Token[TokenVector.size()]; |
| 1717 | std::copy(TokenVector.begin(), TokenVector.end(), TokenArray); |
| 1718 | auto Value = new (PP.getPreprocessorAllocator()) |
| 1719 | std::pair<Token*, size_t>(std::make_pair(TokenArray, TokenVector.size())); |
| 1720 | AnnotTok.setAnnotationValue(Value); |
| 1721 | PP.EnterToken(AnnotTok); |
Reid Kleckner | d3923aa | 2014-04-03 19:04:24 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
Aaron Ballman | 5d041be | 2013-06-04 02:07:14 +0000 | [diff] [blame] | 1724 | /// \brief Handle the Microsoft \#pragma detect_mismatch extension. |
| 1725 | /// |
| 1726 | /// The syntax is: |
| 1727 | /// \code |
| 1728 | /// #pragma detect_mismatch("name", "value") |
| 1729 | /// \endcode |
| 1730 | /// Where 'name' and 'value' are quoted strings. The values are embedded in |
| 1731 | /// the object file and passed along to the linker. If the linker detects a |
| 1732 | /// mismatch in the object file's values for the given name, a LNK2038 error |
| 1733 | /// is emitted. See MSDN for more details. |
| 1734 | void PragmaDetectMismatchHandler::HandlePragma(Preprocessor &PP, |
| 1735 | PragmaIntroducerKind Introducer, |
| 1736 | Token &Tok) { |
| 1737 | SourceLocation CommentLoc = Tok.getLocation(); |
| 1738 | PP.Lex(Tok); |
| 1739 | if (Tok.isNot(tok::l_paren)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1740 | PP.Diag(CommentLoc, diag::err_expected) << tok::l_paren; |
Aaron Ballman | 5d041be | 2013-06-04 02:07:14 +0000 | [diff] [blame] | 1741 | return; |
| 1742 | } |
| 1743 | |
| 1744 | // Read the name to embed, which must be a string literal. |
| 1745 | std::string NameString; |
| 1746 | if (!PP.LexStringLiteral(Tok, NameString, |
| 1747 | "pragma detect_mismatch", |
| 1748 | /*MacroExpansion=*/true)) |
| 1749 | return; |
| 1750 | |
| 1751 | // Read the comma followed by a second string literal. |
| 1752 | std::string ValueString; |
| 1753 | if (Tok.isNot(tok::comma)) { |
| 1754 | PP.Diag(Tok.getLocation(), diag::err_pragma_detect_mismatch_malformed); |
| 1755 | return; |
| 1756 | } |
| 1757 | |
| 1758 | if (!PP.LexStringLiteral(Tok, ValueString, "pragma detect_mismatch", |
| 1759 | /*MacroExpansion=*/true)) |
| 1760 | return; |
| 1761 | |
| 1762 | if (Tok.isNot(tok::r_paren)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1763 | PP.Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren; |
Aaron Ballman | 5d041be | 2013-06-04 02:07:14 +0000 | [diff] [blame] | 1764 | return; |
| 1765 | } |
| 1766 | PP.Lex(Tok); // Eat the r_paren. |
| 1767 | |
| 1768 | if (Tok.isNot(tok::eod)) { |
| 1769 | PP.Diag(Tok.getLocation(), diag::err_pragma_detect_mismatch_malformed); |
| 1770 | return; |
| 1771 | } |
| 1772 | |
Reid Kleckner | 71966c9 | 2014-02-20 23:37:45 +0000 | [diff] [blame] | 1773 | // If the pragma is lexically sound, notify any interested PPCallbacks. |
| 1774 | if (PP.getPPCallbacks()) |
| 1775 | PP.getPPCallbacks()->PragmaDetectMismatch(CommentLoc, NameString, |
| 1776 | ValueString); |
| 1777 | |
Aaron Ballman | 5d041be | 2013-06-04 02:07:14 +0000 | [diff] [blame] | 1778 | Actions.ActOnPragmaDetectMismatch(NameString, ValueString); |
| 1779 | } |
| 1780 | |
Reid Kleckner | 002562a | 2013-05-06 21:02:12 +0000 | [diff] [blame] | 1781 | /// \brief Handle the microsoft \#pragma comment extension. |
| 1782 | /// |
| 1783 | /// The syntax is: |
| 1784 | /// \code |
| 1785 | /// #pragma comment(linker, "foo") |
| 1786 | /// \endcode |
| 1787 | /// 'linker' is one of five identifiers: compiler, exestr, lib, linker, user. |
| 1788 | /// "foo" is a string, which is fully macro expanded, and permits string |
| 1789 | /// concatenation, embedded escape characters etc. See MSDN for more details. |
| 1790 | void PragmaCommentHandler::HandlePragma(Preprocessor &PP, |
| 1791 | PragmaIntroducerKind Introducer, |
| 1792 | Token &Tok) { |
| 1793 | SourceLocation CommentLoc = Tok.getLocation(); |
| 1794 | PP.Lex(Tok); |
| 1795 | if (Tok.isNot(tok::l_paren)) { |
| 1796 | PP.Diag(CommentLoc, diag::err_pragma_comment_malformed); |
| 1797 | return; |
| 1798 | } |
| 1799 | |
| 1800 | // Read the identifier. |
| 1801 | PP.Lex(Tok); |
| 1802 | if (Tok.isNot(tok::identifier)) { |
| 1803 | PP.Diag(CommentLoc, diag::err_pragma_comment_malformed); |
| 1804 | return; |
| 1805 | } |
| 1806 | |
| 1807 | // Verify that this is one of the 5 whitelisted options. |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 1808 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1809 | Sema::PragmaMSCommentKind Kind = |
| 1810 | llvm::StringSwitch<Sema::PragmaMSCommentKind>(II->getName()) |
| 1811 | .Case("linker", Sema::PCK_Linker) |
| 1812 | .Case("lib", Sema::PCK_Lib) |
| 1813 | .Case("compiler", Sema::PCK_Compiler) |
| 1814 | .Case("exestr", Sema::PCK_ExeStr) |
| 1815 | .Case("user", Sema::PCK_User) |
| 1816 | .Default(Sema::PCK_Unknown); |
| 1817 | if (Kind == Sema::PCK_Unknown) { |
Reid Kleckner | 002562a | 2013-05-06 21:02:12 +0000 | [diff] [blame] | 1818 | PP.Diag(Tok.getLocation(), diag::err_pragma_comment_unknown_kind); |
| 1819 | return; |
| 1820 | } |
| 1821 | |
Yunzhong Gao | 99efc03 | 2015-03-23 20:41:42 +0000 | [diff] [blame] | 1822 | // On PS4, issue a warning about any pragma comments other than |
| 1823 | // #pragma comment lib. |
| 1824 | if (PP.getTargetInfo().getTriple().isPS4() && Kind != Sema::PCK_Lib) { |
| 1825 | PP.Diag(Tok.getLocation(), diag::warn_pragma_comment_ignored) |
| 1826 | << II->getName(); |
| 1827 | return; |
| 1828 | } |
| 1829 | |
Reid Kleckner | 002562a | 2013-05-06 21:02:12 +0000 | [diff] [blame] | 1830 | // Read the optional string if present. |
| 1831 | PP.Lex(Tok); |
| 1832 | std::string ArgumentString; |
| 1833 | if (Tok.is(tok::comma) && !PP.LexStringLiteral(Tok, ArgumentString, |
| 1834 | "pragma comment", |
| 1835 | /*MacroExpansion=*/true)) |
| 1836 | return; |
| 1837 | |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 1838 | // FIXME: warn that 'exestr' is deprecated. |
Reid Kleckner | 002562a | 2013-05-06 21:02:12 +0000 | [diff] [blame] | 1839 | // FIXME: If the kind is "compiler" warn if the string is present (it is |
| 1840 | // ignored). |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 1841 | // The MSDN docs say that "lib" and "linker" require a string and have a short |
| 1842 | // whitelist of linker options they support, but in practice MSVC doesn't |
| 1843 | // issue a diagnostic. Therefore neither does clang. |
Reid Kleckner | 002562a | 2013-05-06 21:02:12 +0000 | [diff] [blame] | 1844 | |
| 1845 | if (Tok.isNot(tok::r_paren)) { |
| 1846 | PP.Diag(Tok.getLocation(), diag::err_pragma_comment_malformed); |
| 1847 | return; |
| 1848 | } |
| 1849 | PP.Lex(Tok); // eat the r_paren. |
| 1850 | |
| 1851 | if (Tok.isNot(tok::eod)) { |
| 1852 | PP.Diag(Tok.getLocation(), diag::err_pragma_comment_malformed); |
| 1853 | return; |
| 1854 | } |
| 1855 | |
Reid Kleckner | 71966c9 | 2014-02-20 23:37:45 +0000 | [diff] [blame] | 1856 | // If the pragma is lexically sound, notify any interested PPCallbacks. |
| 1857 | if (PP.getPPCallbacks()) |
| 1858 | PP.getPPCallbacks()->PragmaComment(CommentLoc, II, ArgumentString); |
| 1859 | |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 1860 | Actions.ActOnPragmaMSComment(Kind, ArgumentString); |
Reid Kleckner | 002562a | 2013-05-06 21:02:12 +0000 | [diff] [blame] | 1861 | } |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 1862 | |
| 1863 | // #pragma clang optimize off |
| 1864 | // #pragma clang optimize on |
| 1865 | void PragmaOptimizeHandler::HandlePragma(Preprocessor &PP, |
| 1866 | PragmaIntroducerKind Introducer, |
| 1867 | Token &FirstToken) { |
| 1868 | Token Tok; |
| 1869 | PP.Lex(Tok); |
| 1870 | if (Tok.is(tok::eod)) { |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1871 | PP.Diag(Tok.getLocation(), diag::err_pragma_missing_argument) |
Mark Heffernan | 450c238 | 2014-07-23 17:31:31 +0000 | [diff] [blame] | 1872 | << "clang optimize" << /*Expected=*/true << "'on' or 'off'"; |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 1873 | return; |
| 1874 | } |
| 1875 | if (Tok.isNot(tok::identifier)) { |
| 1876 | PP.Diag(Tok.getLocation(), diag::err_pragma_optimize_invalid_argument) |
| 1877 | << PP.getSpelling(Tok); |
| 1878 | return; |
| 1879 | } |
| 1880 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1881 | // The only accepted values are 'on' or 'off'. |
| 1882 | bool IsOn = false; |
| 1883 | if (II->isStr("on")) { |
| 1884 | IsOn = true; |
| 1885 | } else if (!II->isStr("off")) { |
| 1886 | PP.Diag(Tok.getLocation(), diag::err_pragma_optimize_invalid_argument) |
| 1887 | << PP.getSpelling(Tok); |
| 1888 | return; |
| 1889 | } |
| 1890 | PP.Lex(Tok); |
| 1891 | |
| 1892 | if (Tok.isNot(tok::eod)) { |
| 1893 | PP.Diag(Tok.getLocation(), diag::err_pragma_optimize_extra_argument) |
| 1894 | << PP.getSpelling(Tok); |
| 1895 | return; |
| 1896 | } |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 1897 | |
| 1898 | Actions.ActOnPragmaOptimize(IsOn, FirstToken.getLocation()); |
| 1899 | } |
| 1900 | |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1901 | /// \brief Parses loop or unroll pragma hint value and fills in Info. |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 1902 | static bool ParseLoopHintValue(Preprocessor &PP, Token &Tok, Token PragmaName, |
| 1903 | Token Option, bool ValueInParens, |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1904 | PragmaLoopHintInfo &Info) { |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 1905 | SmallVector<Token, 1> ValueList; |
| 1906 | int OpenParens = ValueInParens ? 1 : 0; |
| 1907 | // Read constant expression. |
| 1908 | while (Tok.isNot(tok::eod)) { |
| 1909 | if (Tok.is(tok::l_paren)) |
| 1910 | OpenParens++; |
| 1911 | else if (Tok.is(tok::r_paren)) { |
| 1912 | OpenParens--; |
| 1913 | if (OpenParens == 0 && ValueInParens) |
| 1914 | break; |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1915 | } |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1916 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 1917 | ValueList.push_back(Tok); |
| 1918 | PP.Lex(Tok); |
| 1919 | } |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1920 | |
| 1921 | if (ValueInParens) { |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 1922 | // Read ')' |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1923 | if (Tok.isNot(tok::r_paren)) { |
| 1924 | PP.Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren; |
| 1925 | return true; |
| 1926 | } |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 1927 | PP.Lex(Tok); |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 1930 | Token EOFTok; |
| 1931 | EOFTok.startToken(); |
| 1932 | EOFTok.setKind(tok::eof); |
| 1933 | EOFTok.setLocation(Tok.getLocation()); |
| 1934 | ValueList.push_back(EOFTok); // Terminates expression for parsing. |
| 1935 | |
Benjamin Kramer | fa7f855 | 2015-08-05 09:39:57 +0000 | [diff] [blame] | 1936 | Info.Toks = llvm::makeArrayRef(ValueList).copy(PP.getPreprocessorAllocator()); |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 1937 | |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1938 | Info.PragmaName = PragmaName; |
| 1939 | Info.Option = Option; |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1940 | return false; |
| 1941 | } |
| 1942 | |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 1943 | /// \brief Handle the \#pragma clang loop directive. |
| 1944 | /// #pragma clang 'loop' loop-hints |
| 1945 | /// |
| 1946 | /// loop-hints: |
| 1947 | /// loop-hint loop-hints[opt] |
| 1948 | /// |
| 1949 | /// loop-hint: |
| 1950 | /// 'vectorize' '(' loop-hint-keyword ')' |
| 1951 | /// 'interleave' '(' loop-hint-keyword ')' |
Mark Heffernan | 450c238 | 2014-07-23 17:31:31 +0000 | [diff] [blame] | 1952 | /// 'unroll' '(' unroll-hint-keyword ')' |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 1953 | /// 'vectorize_width' '(' loop-hint-value ')' |
| 1954 | /// 'interleave_count' '(' loop-hint-value ')' |
Eli Bendersky | 86483b3 | 2014-06-11 17:56:26 +0000 | [diff] [blame] | 1955 | /// 'unroll_count' '(' loop-hint-value ')' |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 1956 | /// |
| 1957 | /// loop-hint-keyword: |
| 1958 | /// 'enable' |
| 1959 | /// 'disable' |
Tyler Nowicki | 9d268e1 | 2015-06-11 23:23:17 +0000 | [diff] [blame] | 1960 | /// 'assume_safety' |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 1961 | /// |
Mark Heffernan | 450c238 | 2014-07-23 17:31:31 +0000 | [diff] [blame] | 1962 | /// unroll-hint-keyword: |
Mark Heffernan | 397a98d | 2015-08-10 17:29:39 +0000 | [diff] [blame] | 1963 | /// 'enable' |
Mark Heffernan | 450c238 | 2014-07-23 17:31:31 +0000 | [diff] [blame] | 1964 | /// 'disable' |
Mark Heffernan | 397a98d | 2015-08-10 17:29:39 +0000 | [diff] [blame] | 1965 | /// 'full' |
Mark Heffernan | 450c238 | 2014-07-23 17:31:31 +0000 | [diff] [blame] | 1966 | /// |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 1967 | /// loop-hint-value: |
| 1968 | /// constant-expression |
| 1969 | /// |
| 1970 | /// Specifying vectorize(enable) or vectorize_width(_value_) instructs llvm to |
| 1971 | /// try vectorizing the instructions of the loop it precedes. Specifying |
| 1972 | /// interleave(enable) or interleave_count(_value_) instructs llvm to try |
| 1973 | /// interleaving multiple iterations of the loop it precedes. The width of the |
| 1974 | /// vector instructions is specified by vectorize_width() and the number of |
| 1975 | /// interleaved loop iterations is specified by interleave_count(). Specifying a |
| 1976 | /// value of 1 effectively disables vectorization/interleaving, even if it is |
| 1977 | /// possible and profitable, and 0 is invalid. The loop vectorizer currently |
| 1978 | /// only works on inner loops. |
| 1979 | /// |
Eli Bendersky | 86483b3 | 2014-06-11 17:56:26 +0000 | [diff] [blame] | 1980 | /// The unroll and unroll_count directives control the concatenation |
Mark Heffernan | 397a98d | 2015-08-10 17:29:39 +0000 | [diff] [blame] | 1981 | /// unroller. Specifying unroll(enable) instructs llvm to unroll the loop |
| 1982 | /// completely if the trip count is known at compile time and unroll partially |
| 1983 | /// if the trip count is not known. Specifying unroll(full) is similar to |
| 1984 | /// unroll(enable) but will unroll the loop only if the trip count is known at |
| 1985 | /// compile time. Specifying unroll(disable) disables unrolling for the |
| 1986 | /// loop. Specifying unroll_count(_value_) instructs llvm to try to unroll the |
| 1987 | /// loop the number of times indicated by the value. |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 1988 | void PragmaLoopHintHandler::HandlePragma(Preprocessor &PP, |
| 1989 | PragmaIntroducerKind Introducer, |
| 1990 | Token &Tok) { |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 1991 | // Incoming token is "loop" from "#pragma clang loop". |
| 1992 | Token PragmaName = Tok; |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 1993 | SmallVector<Token, 1> TokenList; |
| 1994 | |
| 1995 | // Lex the optimization option and verify it is an identifier. |
| 1996 | PP.Lex(Tok); |
| 1997 | if (Tok.isNot(tok::identifier)) { |
| 1998 | PP.Diag(Tok.getLocation(), diag::err_pragma_loop_invalid_option) |
| 1999 | << /*MissingOption=*/true << ""; |
| 2000 | return; |
| 2001 | } |
| 2002 | |
| 2003 | while (Tok.is(tok::identifier)) { |
| 2004 | Token Option = Tok; |
| 2005 | IdentifierInfo *OptionInfo = Tok.getIdentifierInfo(); |
| 2006 | |
Eli Bendersky | 86483b3 | 2014-06-11 17:56:26 +0000 | [diff] [blame] | 2007 | bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->getName()) |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2008 | .Case("vectorize", true) |
| 2009 | .Case("interleave", true) |
| 2010 | .Case("unroll", true) |
| 2011 | .Case("vectorize_width", true) |
| 2012 | .Case("interleave_count", true) |
| 2013 | .Case("unroll_count", true) |
| 2014 | .Default(false); |
Eli Bendersky | 86483b3 | 2014-06-11 17:56:26 +0000 | [diff] [blame] | 2015 | if (!OptionValid) { |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 2016 | PP.Diag(Tok.getLocation(), diag::err_pragma_loop_invalid_option) |
| 2017 | << /*MissingOption=*/false << OptionInfo; |
| 2018 | return; |
| 2019 | } |
NAKAMURA Takumi | db9552f | 2014-07-31 01:52:33 +0000 | [diff] [blame] | 2020 | PP.Lex(Tok); |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2021 | |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 2022 | // Read '(' |
| 2023 | if (Tok.isNot(tok::l_paren)) { |
| 2024 | PP.Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren; |
NAKAMURA Takumi | db9552f | 2014-07-31 01:52:33 +0000 | [diff] [blame] | 2025 | return; |
| 2026 | } |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 2027 | PP.Lex(Tok); |
| 2028 | |
| 2029 | auto *Info = new (PP.getPreprocessorAllocator()) PragmaLoopHintInfo; |
| 2030 | if (ParseLoopHintValue(PP, Tok, PragmaName, Option, /*ValueInParens=*/true, |
| 2031 | *Info)) |
| 2032 | return; |
NAKAMURA Takumi | db9552f | 2014-07-31 01:52:33 +0000 | [diff] [blame] | 2033 | |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2034 | // Generate the loop hint token. |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 2035 | Token LoopHintTok; |
| 2036 | LoopHintTok.startToken(); |
| 2037 | LoopHintTok.setKind(tok::annot_pragma_loop_hint); |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2038 | LoopHintTok.setLocation(PragmaName.getLocation()); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 2039 | LoopHintTok.setAnnotationEndLoc(PragmaName.getLocation()); |
Eli Bendersky | 06a4042 | 2014-06-06 20:31:48 +0000 | [diff] [blame] | 2040 | LoopHintTok.setAnnotationValue(static_cast<void *>(Info)); |
| 2041 | TokenList.push_back(LoopHintTok); |
| 2042 | } |
| 2043 | |
| 2044 | if (Tok.isNot(tok::eod)) { |
| 2045 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
| 2046 | << "clang loop"; |
| 2047 | return; |
| 2048 | } |
| 2049 | |
| 2050 | Token *TokenArray = new Token[TokenList.size()]; |
| 2051 | std::copy(TokenList.begin(), TokenList.end(), TokenArray); |
| 2052 | |
| 2053 | PP.EnterTokenStream(TokenArray, TokenList.size(), |
| 2054 | /*DisableMacroExpansion=*/false, |
| 2055 | /*OwnsTokens=*/true); |
| 2056 | } |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2057 | |
| 2058 | /// \brief Handle the loop unroll optimization pragmas. |
| 2059 | /// #pragma unroll |
| 2060 | /// #pragma unroll unroll-hint-value |
| 2061 | /// #pragma unroll '(' unroll-hint-value ')' |
Mark Heffernan | c888e41 | 2014-07-24 18:09:38 +0000 | [diff] [blame] | 2062 | /// #pragma nounroll |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2063 | /// |
| 2064 | /// unroll-hint-value: |
| 2065 | /// constant-expression |
| 2066 | /// |
Mark Heffernan | c888e41 | 2014-07-24 18:09:38 +0000 | [diff] [blame] | 2067 | /// Loop unrolling hints can be specified with '#pragma unroll' or |
| 2068 | /// '#pragma nounroll'. '#pragma unroll' can take a numeric argument optionally |
| 2069 | /// contained in parentheses. With no argument the directive instructs llvm to |
| 2070 | /// try to unroll the loop completely. A positive integer argument can be |
| 2071 | /// specified to indicate the number of times the loop should be unrolled. To |
| 2072 | /// maximize compatibility with other compilers the unroll count argument can be |
| 2073 | /// specified with or without parentheses. Specifying, '#pragma nounroll' |
| 2074 | /// disables unrolling of the loop. |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2075 | void PragmaUnrollHintHandler::HandlePragma(Preprocessor &PP, |
| 2076 | PragmaIntroducerKind Introducer, |
| 2077 | Token &Tok) { |
Mark Heffernan | c888e41 | 2014-07-24 18:09:38 +0000 | [diff] [blame] | 2078 | // Incoming token is "unroll" for "#pragma unroll", or "nounroll" for |
| 2079 | // "#pragma nounroll". |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2080 | Token PragmaName = Tok; |
| 2081 | PP.Lex(Tok); |
| 2082 | auto *Info = new (PP.getPreprocessorAllocator()) PragmaLoopHintInfo; |
| 2083 | if (Tok.is(tok::eod)) { |
Mark Heffernan | c888e41 | 2014-07-24 18:09:38 +0000 | [diff] [blame] | 2084 | // nounroll or unroll pragma without an argument. |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2085 | Info->PragmaName = PragmaName; |
Aaron Ballman | d6807da | 2014-08-01 12:41:37 +0000 | [diff] [blame] | 2086 | Info->Option.startToken(); |
Mark Heffernan | c888e41 | 2014-07-24 18:09:38 +0000 | [diff] [blame] | 2087 | } else if (PragmaName.getIdentifierInfo()->getName() == "nounroll") { |
| 2088 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
| 2089 | << "nounroll"; |
| 2090 | return; |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2091 | } else { |
| 2092 | // Unroll pragma with an argument: "#pragma unroll N" or |
| 2093 | // "#pragma unroll(N)". |
Tyler Nowicki | 0c9b34b | 2014-07-31 20:15:14 +0000 | [diff] [blame] | 2094 | // Read '(' if it exists. |
| 2095 | bool ValueInParens = Tok.is(tok::l_paren); |
| 2096 | if (ValueInParens) |
| 2097 | PP.Lex(Tok); |
| 2098 | |
Aaron Ballman | d0b090d | 2014-08-01 12:20:20 +0000 | [diff] [blame] | 2099 | Token Option; |
| 2100 | Option.startToken(); |
| 2101 | if (ParseLoopHintValue(PP, Tok, PragmaName, Option, ValueInParens, *Info)) |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2102 | return; |
| 2103 | |
| 2104 | // In CUDA, the argument to '#pragma unroll' should not be contained in |
| 2105 | // parentheses. |
| 2106 | if (PP.getLangOpts().CUDA && ValueInParens) |
Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 2107 | PP.Diag(Info->Toks[0].getLocation(), |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2108 | diag::warn_pragma_unroll_cuda_value_in_parens); |
| 2109 | |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2110 | if (Tok.isNot(tok::eod)) { |
| 2111 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
| 2112 | << "unroll"; |
| 2113 | return; |
| 2114 | } |
| 2115 | } |
| 2116 | |
| 2117 | // Generate the hint token. |
| 2118 | Token *TokenArray = new Token[1]; |
| 2119 | TokenArray[0].startToken(); |
| 2120 | TokenArray[0].setKind(tok::annot_pragma_loop_hint); |
| 2121 | TokenArray[0].setLocation(PragmaName.getLocation()); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 2122 | TokenArray[0].setAnnotationEndLoc(PragmaName.getLocation()); |
Mark Heffernan | bd26f5e | 2014-07-21 18:08:34 +0000 | [diff] [blame] | 2123 | TokenArray[0].setAnnotationValue(static_cast<void *>(Info)); |
| 2124 | PP.EnterTokenStream(TokenArray, 1, /*DisableMacroExpansion=*/false, |
| 2125 | /*OwnsTokens=*/true); |
| 2126 | } |