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