clang 24.0.0git
PPExpressions.cpp
Go to the documentation of this file.
1//===--- PPExpressions.cpp - Preprocessor Expression Evaluation -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Preprocessor::EvaluateDirectiveExpression method,
10// which parses and evaluates integer constant expressions for #if directives.
11//
12//===----------------------------------------------------------------------===//
13//
14// FIXME: implement testing for #assert's.
15//
16//===----------------------------------------------------------------------===//
17
26#include "clang/Lex/MacroInfo.h"
30#include "clang/Lex/Token.h"
31#include "llvm/ADT/APSInt.h"
32#include "llvm/ADT/STLExtras.h"
33#include "llvm/ADT/StringExtras.h"
34#include "llvm/ADT/StringRef.h"
35#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/SaveAndRestore.h"
37#include <cassert>
38
39using namespace clang;
40
41namespace {
42
43/// PPValue - Represents the value of a subexpression of a preprocessor
44/// conditional and the source range covered by it.
45class PPValue {
46 SourceRange Range;
47 IdentifierInfo *II = nullptr;
48
49public:
50 llvm::APSInt Val;
51
52 // Default ctor - Construct an 'invalid' PPValue.
53 PPValue(unsigned BitWidth) : Val(BitWidth) {}
54
55 // If this value was produced by directly evaluating an identifier, produce
56 // that identifier.
57 IdentifierInfo *getIdentifier() const { return II; }
58 void setIdentifier(IdentifierInfo *II) { this->II = II; }
59
60 unsigned getBitWidth() const { return Val.getBitWidth(); }
61 bool isUnsigned() const { return Val.isUnsigned(); }
62
63 SourceRange getRange() const { return Range; }
64
65 void setRange(SourceLocation L) { Range.setBegin(L); Range.setEnd(L); }
66 void setRange(SourceLocation B, SourceLocation E) {
67 Range.setBegin(B); Range.setEnd(E);
68 }
69 void setBegin(SourceLocation L) { Range.setBegin(L); }
70 void setEnd(SourceLocation L) { Range.setEnd(L); }
71};
72
73} // end anonymous namespace
74
75static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec,
76 Token &PeekTok, bool ValueLive,
77 bool &IncludedUndefinedIds,
78 Preprocessor &PP);
79
80/// DefinedTracker - This struct is used while parsing expressions to keep track
81/// of whether !defined(X) has been seen.
82///
83/// With this simple scheme, we handle the basic forms:
84/// !defined(X) and !defined X
85/// but we also trivially handle (silly) stuff like:
86/// !!!defined(X) and +!defined(X) and !+!+!defined(X) and !(defined(X)).
88 /// Each time a Value is evaluated, it returns information about whether the
89 /// parsed value is of the form defined(X), !defined(X) or is something else.
91 DefinedMacro, // defined(X)
92 NotDefinedMacro, // !defined(X)
93 Unknown // Something else.
94 } State;
95 /// TheMacro - When the state is DefinedMacro or NotDefinedMacro, this
96 /// indicates the macro that was checked.
99};
100
101/// EvaluateDefined - Process a 'defined(sym)' expression.
102static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
103 bool ValueLive, Preprocessor &PP) {
104 SourceLocation beginLoc(PeekTok.getLocation());
105 Result.setBegin(beginLoc);
106
107 // Get the next token, don't expand it.
108 PP.LexUnexpandedNonComment(PeekTok);
109
110 // Two options, it can either be a pp-identifier or a (.
111 SourceLocation LParenLoc;
112 if (PeekTok.is(tok::l_paren)) {
113 // Found a paren, remember we saw it and skip it.
114 LParenLoc = PeekTok.getLocation();
115 PP.LexUnexpandedNonComment(PeekTok);
116 }
117
118 if (PeekTok.is(tok::code_completion)) {
122 PP.LexUnexpandedNonComment(PeekTok);
123 }
124
125 // If we don't have a pp-identifier now, this is an error.
126 if (PP.CheckMacroName(PeekTok, MU_Other))
127 return true;
128
129 // Otherwise, we got an identifier, is it defined to something?
130 IdentifierInfo *II = PeekTok.getIdentifierInfo();
132 Result.Val = !!Macro;
133 Result.Val.setIsUnsigned(false); // Result is signed intmax_t.
135
137 PeekTok,
138 (II->getName() == "INFINITY" || II->getName() == "NAN") ? true : false);
139
140 // If there is a macro, mark it used.
141 if (Result.Val != 0 && ValueLive)
142 PP.markMacroAsUsed(Macro.getMacroInfo());
143
144 // Save macro token for callback.
145 Token macroToken(PeekTok);
146
147 // If we are in parens, ensure we have a trailing ).
148 if (LParenLoc.isValid()) {
149 // Consume identifier.
150 Result.setEnd(PeekTok.getLocation());
151 PP.LexUnexpandedNonComment(PeekTok);
152
153 if (PeekTok.isNot(tok::r_paren)) {
154 PP.Diag(PeekTok.getLocation(), diag::err_pp_expected_after)
155 << "'defined'" << tok::r_paren;
156 PP.Diag(LParenLoc, diag::note_matching) << tok::l_paren;
157 return true;
158 }
159 // Consume the ).
160 PP.LexNonComment(PeekTok);
161 Result.setEnd(PeekTok.getLocation());
162 } else {
163 // Consume identifier.
164 Result.setEnd(PeekTok.getLocation());
165 PP.LexNonComment(PeekTok);
166 }
167
168 // [cpp.cond]p4:
169 // Prior to evaluation, macro invocations in the list of preprocessing
170 // tokens that will become the controlling constant expression are replaced
171 // (except for those macro names modified by the 'defined' unary operator),
172 // just as in normal text. If the token 'defined' is generated as a result
173 // of this replacement process or use of the 'defined' unary operator does
174 // not match one of the two specified forms prior to macro replacement, the
175 // behavior is undefined.
176 // This isn't an idle threat, consider this program:
177 // #define FOO
178 // #define BAR defined(FOO)
179 // #if BAR
180 // ...
181 // #else
182 // ...
183 // #endif
184 // clang and gcc will pick the #if branch while Visual Studio will take the
185 // #else branch. Emit a warning about this undefined behavior.
186 if (beginLoc.isMacroID()) {
187 bool IsFunctionTypeMacro =
190 .getExpansion()
192 // For object-type macros, it's easy to replace
193 // #define FOO defined(BAR)
194 // with
195 // #if defined(BAR)
196 // #define FOO 1
197 // #else
198 // #define FOO 0
199 // #endif
200 // and doing so makes sense since compilers handle this differently in
201 // practice (see example further up). But for function-type macros,
202 // there is no good way to write
203 // # define FOO(x) (defined(M_ ## x) && M_ ## x)
204 // in a different way, and compilers seem to agree on how to behave here.
205 // So warn by default on object-type macros, but only warn in -pedantic
206 // mode on function-type macros.
207 if (IsFunctionTypeMacro)
208 PP.Diag(beginLoc, diag::warn_defined_in_function_type_macro);
209 else
210 PP.Diag(beginLoc, diag::warn_defined_in_object_type_macro);
211 }
212
213 // Invoke the 'defined' callback.
214 if (PPCallbacks *Callbacks = PP.getPPCallbacks()) {
215 Callbacks->Defined(macroToken, Macro,
216 SourceRange(beginLoc, PeekTok.getLocation()));
217 }
218
219 // Success, remember that we saw defined(X).
221 DT.TheMacro = II;
222 return false;
223}
224
225/// EvaluateValue - Evaluate the token PeekTok (and any others needed) and
226/// return the computed value in Result. Return true if there was an error
227/// parsing. This function also returns information about the form of the
228/// expression in DT. See above for information on what DT means.
229///
230/// If ValueLive is false, then this value is being evaluated in a context where
231/// the result is not used. As such, avoid diagnostics that relate to
232/// evaluation.
233static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
234 bool ValueLive, Preprocessor &PP) {
236
237 Result.setIdentifier(nullptr);
238
239 if (PeekTok.is(tok::code_completion)) {
243 PP.LexNonComment(PeekTok);
244 }
245
246 switch (PeekTok.getKind()) {
247 default:
248 // If this token's spelling is a pp-identifier, check to see if it is
249 // 'defined' or if it is a macro. Note that we check here because many
250 // keywords are pp-identifiers, so we can't check the kind.
251 // Pragma operators can produce annotation tokens, which have no
252 // IdentifierInfo and should be diagnosed as invalid expression tokens.
253 if (!PeekTok.isAnnotation() && PeekTok.getIdentifierInfo()) {
254 IdentifierInfo *II = PeekTok.getIdentifierInfo();
255 // Handle "defined X" and "defined(X)".
256 if (II->isStr("defined"))
257 return EvaluateDefined(Result, PeekTok, DT, ValueLive, PP);
258
259 if (!II->isCPlusPlusOperatorKeyword()) {
260 // If this identifier isn't 'defined' or one of the special
261 // preprocessor keywords and it wasn't macro expanded, it turns
262 // into a simple 0
263 if (ValueLive) {
264 unsigned DiagID = II->getName() == "true"
265 ? diag::warn_pp_undef_true_identifier
266 : diag::warn_pp_undef_identifier;
267 PP.Diag(PeekTok, DiagID) << II;
268
269 const DiagnosticsEngine &DiagEngine = PP.getDiagnostics();
270 // If 'Wundef' is enabled, do not emit 'undef-prefix' diagnostics.
271 if (DiagEngine.isIgnored(DiagID, PeekTok.getLocation())) {
272 const std::vector<std::string> UndefPrefixes =
274 const StringRef IdentifierName = II->getName();
275 if (llvm::any_of(UndefPrefixes,
276 [&IdentifierName](const std::string &Prefix) {
277 return IdentifierName.starts_with(Prefix);
278 }))
279 PP.Diag(PeekTok, diag::warn_pp_undef_prefix)
280 << AddFlagValue{llvm::join(UndefPrefixes, ",")} << II;
281 }
282 }
283 Result.Val = 0;
284 Result.Val.setIsUnsigned(false); // "0" is signed intmax_t 0.
285 Result.setIdentifier(II);
286 Result.setRange(PeekTok.getLocation());
287 DT.IncludedUndefinedIds = true;
288 PP.LexNonComment(PeekTok);
289 return false;
290 }
291 }
292 PP.Diag(PeekTok, diag::err_pp_expr_bad_token_start_expr);
293 return true;
294 case tok::eod:
295 case tok::r_paren:
296 // If there is no expression, report and exit.
297 PP.Diag(PeekTok, diag::err_pp_expected_value_in_expr);
298 return true;
299 case tok::numeric_constant: {
300 SmallString<64> IntegerBuffer;
301 bool NumberInvalid = false;
302 StringRef Spelling = PP.getSpelling(PeekTok, IntegerBuffer,
303 &NumberInvalid);
304 if (NumberInvalid)
305 return true; // a diagnostic was already reported
306
307 NumericLiteralParser Literal(Spelling, PeekTok.getLocation(),
308 PP.getSourceManager(), PP.getLangOpts(),
309 PP.getTargetInfo(), PP.getDiagnostics());
310 if (Literal.hadError)
311 return true; // a diagnostic was already reported.
312
313 if (Literal.isFloatingLiteral() || Literal.isImaginary) {
314 PP.Diag(PeekTok, diag::err_pp_illegal_floating_literal);
315 return true;
316 }
317 assert(Literal.isIntegerLiteral() && "Unknown ppnumber");
318
319 // Complain about, and drop, any ud-suffix.
320 if (Literal.hasUDSuffix())
321 PP.Diag(PeekTok, diag::err_pp_invalid_udl) << /*integer*/1;
322
323 // 'long long' is a C99 or C++11 feature.
324 if (!PP.getLangOpts().C99 && Literal.isLongLong) {
325 if (PP.getLangOpts().CPlusPlus)
326 PP.Diag(PeekTok,
327 PP.getLangOpts().CPlusPlus11 ?
328 diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
329 else
330 PP.Diag(PeekTok, diag::ext_c99_longlong);
331 }
332
333 // 'z/uz' literals are a C++23 feature.
334 if (Literal.isSizeT) {
335 if (PP.getLangOpts().CPlusPlus) {
336 PP.DiagCompat(PeekTok, diag_compat::size_t_suffix);
337 } else {
338 PP.Diag(PeekTok, diag::err_cxx23_size_t_suffix);
339 }
340 }
341
342 // 'wb/uwb' literals are a C23 feature.
343 // '__wb/__uwb' are a C++ extension.
344 if (Literal.isBitInt)
345 PP.Diag(PeekTok, PP.getLangOpts().CPlusPlus ? diag::ext_cxx_bitint_suffix
346 : PP.getLangOpts().C23
347 ? diag::warn_c23_compat_bitint_suffix
348 : diag::ext_c23_bitint_suffix);
349
350 // Parse the integer literal into Result.
351 if (Literal.GetIntegerValue(Result.Val)) {
352 // Overflow parsing integer literal.
353 PP.Diag(PeekTok, diag::err_integer_literal_too_large) << /* Unsigned */ 1;
354 Result.Val.setIsUnsigned(true);
355 } else {
356 // Set the signedness of the result to match whether there was a U suffix
357 // or not.
358 Result.Val.setIsUnsigned(Literal.isUnsigned);
359
360 // Detect overflow based on whether the value is signed. If signed
361 // and if the value is too large, emit a warning "integer constant is so
362 // large that it is unsigned" e.g. on 12345678901234567890 where intmax_t
363 // is 64-bits.
364 if (!Literal.isUnsigned && Result.Val.isNegative()) {
365 // Octal, hexadecimal, and binary literals are implicitly unsigned if
366 // the value does not fit into a signed integer type.
367 if (ValueLive && Literal.getRadix() == 10)
368 PP.Diag(PeekTok, diag::ext_integer_literal_too_large_for_signed);
369 Result.Val.setIsUnsigned(true);
370 }
371 }
372
373 // Consume the token.
374 Result.setRange(PeekTok.getLocation());
375 PP.LexNonComment(PeekTok);
376 return false;
377 }
378 case tok::char_constant: // 'x'
379 case tok::wide_char_constant: // L'x'
380 case tok::utf8_char_constant: // u8'x'
381 case tok::utf16_char_constant: // u'x'
382 case tok::utf32_char_constant: { // U'x'
383 // Complain about, and drop, any ud-suffix.
384 if (PeekTok.hasUDSuffix())
385 PP.Diag(PeekTok, diag::err_pp_invalid_udl) << /*character*/0;
386
387 SmallString<32> CharBuffer;
388 bool CharInvalid = false;
389 StringRef ThisTok = PP.getSpelling(PeekTok, CharBuffer, &CharInvalid);
390 if (CharInvalid)
391 return true;
392
393 CharLiteralParser Literal(ThisTok.begin(), ThisTok.end(),
394 PeekTok.getLocation(), PP, PeekTok.getKind());
395 if (Literal.hadError())
396 return true; // A diagnostic was already emitted.
397
398 // Character literals are always int or wchar_t, expand to intmax_t.
399 const TargetInfo &TI = PP.getTargetInfo();
400 unsigned NumBits;
401 if (Literal.isMultiChar())
402 NumBits = TI.getIntWidth();
403 else if (Literal.isWide())
404 NumBits = TI.getWCharWidth();
405 else if (Literal.isUTF16())
406 NumBits = TI.getChar16Width();
407 else if (Literal.isUTF32())
408 NumBits = TI.getChar32Width();
409 else // char or char8_t
410 NumBits = TI.getCharWidth();
411
412 // Set the width.
413 llvm::APSInt Val(NumBits);
414 // Set the value.
415 Val = Literal.getValue();
416 // Set the signedness. UTF-16 and UTF-32 are always unsigned
417 // UTF-8 is unsigned if -fchar8_t is specified.
418 if (Literal.isWide())
419 Val.setIsUnsigned(!TargetInfo::isTypeSigned(TI.getWCharType()));
420 else if (Literal.isUTF16() || Literal.isUTF32())
421 Val.setIsUnsigned(true);
422 else if (Literal.isUTF8()) {
423 if (PP.getLangOpts().CPlusPlus)
424 Val.setIsUnsigned(
425 PP.getLangOpts().Char8 ? true : !PP.getLangOpts().CharIsSigned);
426 else
427 Val.setIsUnsigned(true);
428 } else
429 Val.setIsUnsigned(!PP.getLangOpts().CharIsSigned);
430
431 if (Result.Val.getBitWidth() > Val.getBitWidth()) {
432 Result.Val = Val.extend(Result.Val.getBitWidth());
433 } else {
434 assert(Result.Val.getBitWidth() == Val.getBitWidth() &&
435 "intmax_t smaller than char/wchar_t?");
436 Result.Val = std::move(Val);
437 }
438
439 // Consume the token.
440 Result.setRange(PeekTok.getLocation());
441 PP.LexNonComment(PeekTok);
442 return false;
443 }
444 case tok::l_paren: {
445 SourceLocation Start = PeekTok.getLocation();
446 PP.LexNonComment(PeekTok); // Eat the (.
447 // Parse the value and if there are any binary operators involved, parse
448 // them.
449 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
450
451 // If this is a silly value like (X), which doesn't need parens, check for
452 // !(defined X).
453 if (PeekTok.is(tok::r_paren)) {
454 // Just use DT unmodified as our result.
455 } else {
456 // Otherwise, we have something like (x+y), and we consumed '(x'.
457 if (EvaluateDirectiveSubExpr(Result, 1, PeekTok, ValueLive,
458 DT.IncludedUndefinedIds, PP))
459 return true;
460
461 if (PeekTok.isNot(tok::r_paren)) {
462 PP.Diag(PeekTok.getLocation(), diag::err_pp_expected_rparen)
463 << Result.getRange();
464 PP.Diag(Start, diag::note_matching) << tok::l_paren;
465 return true;
466 }
468 }
469 Result.setRange(Start, PeekTok.getLocation());
470 Result.setIdentifier(nullptr);
471 PP.LexNonComment(PeekTok); // Eat the ).
472 return false;
473 }
474 case tok::plus: {
475 SourceLocation Start = PeekTok.getLocation();
476 // Unary plus doesn't modify the value.
477 PP.LexNonComment(PeekTok);
478 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
479 Result.setBegin(Start);
480 Result.setIdentifier(nullptr);
481 return false;
482 }
483 case tok::minus: {
484 SourceLocation Loc = PeekTok.getLocation();
485 PP.LexNonComment(PeekTok);
486 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
487 Result.setBegin(Loc);
488 Result.setIdentifier(nullptr);
489
490 // C99 6.5.3.3p3: The sign of the result matches the sign of the operand.
491 Result.Val = -Result.Val;
492
493 // -MININT is the only thing that overflows. Unsigned never overflows.
494 bool Overflow = !Result.isUnsigned() && Result.Val.isMinSignedValue();
495
496 // If this operator is live and overflowed, report the issue.
497 if (Overflow && ValueLive)
498 PP.Diag(Loc, diag::warn_pp_expr_overflow) << Result.getRange();
499
501 return false;
502 }
503
504 case tok::tilde: {
505 SourceLocation Start = PeekTok.getLocation();
506 PP.LexNonComment(PeekTok);
507 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
508 Result.setBegin(Start);
509 Result.setIdentifier(nullptr);
510
511 // C99 6.5.3.3p4: The sign of the result matches the sign of the operand.
512 Result.Val = ~Result.Val;
514 return false;
515 }
516
517 case tok::exclaim: {
518 SourceLocation Start = PeekTok.getLocation();
519 PP.LexNonComment(PeekTok);
520 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
521 Result.setBegin(Start);
522 Result.Val = !Result.Val;
523 // C99 6.5.3.3p5: The sign of the result is 'int', aka it is signed.
524 Result.Val.setIsUnsigned(false);
525 Result.setIdentifier(nullptr);
526
531 return false;
532 }
533 case tok::kw_true:
534 case tok::kw_false:
535 Result.Val = PeekTok.getKind() == tok::kw_true;
536 Result.Val.setIsUnsigned(false); // "0" is signed intmax_t 0.
537 Result.setIdentifier(PeekTok.getIdentifierInfo());
538 Result.setRange(PeekTok.getLocation());
539 PP.LexNonComment(PeekTok);
540 return false;
541
542 // FIXME: Handle #assert
543 }
544}
545
546/// getPrecedence - Return the precedence of the specified binary operator
547/// token. This returns:
548/// ~0 - Invalid token.
549/// 14 -> 3 - various operators.
550/// 0 - 'eod' or ')'
551static unsigned getPrecedence(tok::TokenKind Kind) {
552 switch (Kind) {
553 default: return ~0U;
554 case tok::percent:
555 case tok::slash:
556 case tok::star: return 14;
557 case tok::plus:
558 case tok::minus: return 13;
559 case tok::lessless:
560 case tok::greatergreater: return 12;
561 case tok::lessequal:
562 case tok::less:
563 case tok::greaterequal:
564 case tok::greater: return 11;
565 case tok::exclaimequal:
566 case tok::equalequal: return 10;
567 case tok::amp: return 9;
568 case tok::caret: return 8;
569 case tok::pipe: return 7;
570 case tok::ampamp: return 6;
571 case tok::pipepipe: return 5;
572 case tok::question: return 4;
573 case tok::comma: return 3;
574 case tok::colon: return 2;
575 case tok::r_paren: return 0;// Lowest priority, end of expr.
576 case tok::eod: return 0;// Lowest priority, end of directive.
577 }
578}
579
580static void diagnoseUnexpectedOperator(Preprocessor &PP, PPValue &LHS,
581 Token &Tok) {
582 if (Tok.is(tok::l_paren) && LHS.getIdentifier())
583 PP.Diag(LHS.getRange().getBegin(), diag::err_pp_expr_bad_token_lparen)
584 << LHS.getIdentifier();
585 else
586 PP.Diag(Tok.getLocation(), diag::err_pp_expr_bad_token_binop)
587 << LHS.getRange();
588}
589
590/// EvaluateDirectiveSubExpr - Evaluate the subexpression whose first token is
591/// PeekTok, and whose precedence is PeekPrec. This returns the result in LHS.
592///
593/// If ValueLive is false, then this value is being evaluated in a context where
594/// the result is not used. As such, avoid diagnostics that relate to
595/// evaluation, such as division by zero warnings.
596static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec,
597 Token &PeekTok, bool ValueLive,
598 bool &IncludedUndefinedIds,
599 Preprocessor &PP) {
602 IncludedUndefinedIds) {
603 // The single-{file,module}-parse mode behavior kicks in as soon as single
604 // identifier is undefined. If we've already seen one, there's no point in
605 // continuing with the rest of the expression. Besides saving work, this
606 // also prevents calling undefined function-like macros.
607 // If the directive already ended (e.g. due to unclosed '('), there is
608 // nothing left to discard.
609 if (PeekTok.isNot(tok::eod))
610 PP.DiscardUntilEndOfDirective(PeekTok);
611 return true;
612 }
613
614 unsigned PeekPrec = getPrecedence(PeekTok.getKind());
615 // If this token isn't valid, report the error.
616 if (PeekPrec == ~0U) {
617 diagnoseUnexpectedOperator(PP, LHS, PeekTok);
618 return true;
619 }
620
621 while (true) {
622 // If this token has a lower precedence than we are allowed to parse, return
623 // it so that higher levels of the recursion can parse it.
624 if (PeekPrec < MinPrec)
625 return false;
626
627 tok::TokenKind Operator = PeekTok.getKind();
628
629 // If this is a short-circuiting operator, see if the RHS of the operator is
630 // dead. Note that this cannot just clobber ValueLive. Consider
631 // "0 && 1 ? 4 : 1 / 0", which is parsed as "(0 && 1) ? 4 : (1 / 0)". In
632 // this example, the RHS of the && being dead does not make the rest of the
633 // expr dead.
634 bool RHSIsLive;
635 if (Operator == tok::ampamp && LHS.Val == 0)
636 RHSIsLive = false; // RHS of "0 && x" is dead.
637 else if (Operator == tok::pipepipe && LHS.Val != 0)
638 RHSIsLive = false; // RHS of "1 || x" is dead.
639 else if (Operator == tok::question && LHS.Val == 0)
640 RHSIsLive = false; // RHS (x) of "0 ? x : y" is dead.
641 else
642 RHSIsLive = ValueLive;
643
644 // Consume the operator, remembering the operator's location for reporting.
645 SourceLocation OpLoc = PeekTok.getLocation();
646 PP.LexNonComment(PeekTok);
647
648 PPValue RHS(LHS.getBitWidth());
649 // Parse the RHS of the operator.
651 if (EvaluateValue(RHS, PeekTok, DT, RHSIsLive, PP)) return true;
652 IncludedUndefinedIds = DT.IncludedUndefinedIds;
653
654 // Remember the precedence of this operator and get the precedence of the
655 // operator immediately to the right of the RHS.
656 unsigned ThisPrec = PeekPrec;
657 PeekPrec = getPrecedence(PeekTok.getKind());
658
659 // If this token isn't valid, report the error.
660 if (PeekPrec == ~0U) {
661 diagnoseUnexpectedOperator(PP, RHS, PeekTok);
662 return true;
663 }
664
665 // Decide whether to include the next binop in this subexpression. For
666 // example, when parsing x+y*z and looking at '*', we want to recursively
667 // handle y*z as a single subexpression. We do this because the precedence
668 // of * is higher than that of +. The only strange case we have to handle
669 // here is for the ?: operator, where the precedence is actually lower than
670 // the LHS of the '?'. The grammar rule is:
671 //
672 // conditional-expression ::=
673 // logical-OR-expression ? expression : conditional-expression
674 // where 'expression' is actually comma-expression.
675 unsigned RHSPrec;
676 if (Operator == tok::question)
677 // The RHS of "?" should be maximally consumed as an expression.
678 RHSPrec = getPrecedence(tok::comma);
679 else // All others should munch while higher precedence.
680 RHSPrec = ThisPrec+1;
681
682 if (PeekPrec >= RHSPrec) {
683 if (EvaluateDirectiveSubExpr(RHS, RHSPrec, PeekTok, RHSIsLive,
684 IncludedUndefinedIds, PP))
685 return true;
686 PeekPrec = getPrecedence(PeekTok.getKind());
687 }
688 assert(PeekPrec <= ThisPrec && "Recursion didn't work!");
689
690 // Usual arithmetic conversions (C99 6.3.1.8p1): result is unsigned if
691 // either operand is unsigned.
692 llvm::APSInt Res(LHS.getBitWidth());
693 switch (Operator) {
694 case tok::question: // No UAC for x and y in "x ? y : z".
695 case tok::lessless: // Shift amount doesn't UAC with shift value.
696 case tok::greatergreater: // Shift amount doesn't UAC with shift value.
697 case tok::comma: // Comma operands are not subject to UACs.
698 case tok::pipepipe: // Logical || does not do UACs.
699 case tok::ampamp: // Logical && does not do UACs.
700 break; // No UAC
701 default:
702 Res.setIsUnsigned(LHS.isUnsigned() || RHS.isUnsigned());
703 // If this just promoted something from signed to unsigned, and if the
704 // value was negative, warn about it.
705 if (ValueLive && Res.isUnsigned()) {
706 if (!LHS.isUnsigned() && LHS.Val.isNegative())
707 PP.Diag(OpLoc, diag::warn_pp_convert_to_positive) << 0
708 << toString(LHS.Val, 10, true) + " to " +
709 toString(LHS.Val, 10, false)
710 << LHS.getRange() << RHS.getRange();
711 if (!RHS.isUnsigned() && RHS.Val.isNegative())
712 PP.Diag(OpLoc, diag::warn_pp_convert_to_positive) << 1
713 << toString(RHS.Val, 10, true) + " to " +
714 toString(RHS.Val, 10, false)
715 << LHS.getRange() << RHS.getRange();
716 }
717 LHS.Val.setIsUnsigned(Res.isUnsigned());
718 RHS.Val.setIsUnsigned(Res.isUnsigned());
719 }
720
721 bool Overflow = false;
722 switch (Operator) {
723 default: llvm_unreachable("Unknown operator token!");
724 case tok::percent:
725 if (RHS.Val != 0)
726 Res = LHS.Val % RHS.Val;
727 else if (ValueLive) {
728 PP.Diag(OpLoc, diag::err_pp_remainder_by_zero)
729 << LHS.getRange() << RHS.getRange();
730 return true;
731 }
732 break;
733 case tok::slash:
734 if (RHS.Val != 0) {
735 if (LHS.Val.isSigned())
736 Res = llvm::APSInt(LHS.Val.sdiv_ov(RHS.Val, Overflow), false);
737 else
738 Res = LHS.Val / RHS.Val;
739 } else if (ValueLive) {
740 PP.Diag(OpLoc, diag::err_pp_division_by_zero)
741 << LHS.getRange() << RHS.getRange();
742 return true;
743 }
744 break;
745
746 case tok::star:
747 if (Res.isSigned())
748 Res = llvm::APSInt(LHS.Val.smul_ov(RHS.Val, Overflow), false);
749 else
750 Res = LHS.Val * RHS.Val;
751 break;
752 case tok::lessless: {
753 // Determine whether overflow is about to happen.
754 if (LHS.isUnsigned())
755 Res = LHS.Val.ushl_ov(RHS.Val, Overflow);
756 else
757 Res = llvm::APSInt(LHS.Val.sshl_ov(RHS.Val, Overflow), false);
758 break;
759 }
760 case tok::greatergreater: {
761 // Determine whether overflow is about to happen.
762 unsigned ShAmt = static_cast<unsigned>(RHS.Val.getLimitedValue());
763 if (ShAmt >= LHS.getBitWidth()) {
764 Overflow = true;
765 ShAmt = LHS.getBitWidth()-1;
766 }
767 Res = LHS.Val >> ShAmt;
768 break;
769 }
770 case tok::plus:
771 if (LHS.isUnsigned())
772 Res = LHS.Val + RHS.Val;
773 else
774 Res = llvm::APSInt(LHS.Val.sadd_ov(RHS.Val, Overflow), false);
775 break;
776 case tok::minus:
777 if (LHS.isUnsigned())
778 Res = LHS.Val - RHS.Val;
779 else
780 Res = llvm::APSInt(LHS.Val.ssub_ov(RHS.Val, Overflow), false);
781 break;
782 case tok::lessequal:
783 Res = LHS.Val <= RHS.Val;
784 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
785 break;
786 case tok::less:
787 Res = LHS.Val < RHS.Val;
788 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
789 break;
790 case tok::greaterequal:
791 Res = LHS.Val >= RHS.Val;
792 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
793 break;
794 case tok::greater:
795 Res = LHS.Val > RHS.Val;
796 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
797 break;
798 case tok::exclaimequal:
799 Res = LHS.Val != RHS.Val;
800 Res.setIsUnsigned(false); // C99 6.5.9p3, result is always int (signed)
801 break;
802 case tok::equalequal:
803 Res = LHS.Val == RHS.Val;
804 Res.setIsUnsigned(false); // C99 6.5.9p3, result is always int (signed)
805 break;
806 case tok::amp:
807 Res = LHS.Val & RHS.Val;
808 break;
809 case tok::caret:
810 Res = LHS.Val ^ RHS.Val;
811 break;
812 case tok::pipe:
813 Res = LHS.Val | RHS.Val;
814 break;
815 case tok::ampamp:
816 Res = (LHS.Val != 0 && RHS.Val != 0);
817 Res.setIsUnsigned(false); // C99 6.5.13p3, result is always int (signed)
818 break;
819 case tok::pipepipe:
820 Res = (LHS.Val != 0 || RHS.Val != 0);
821 Res.setIsUnsigned(false); // C99 6.5.14p3, result is always int (signed)
822 break;
823 case tok::comma:
824 // Comma is invalid in pp expressions in c89/c++ mode, but is valid in C99
825 // if not being evaluated.
826 if (!PP.getLangOpts().C99 || ValueLive)
827 PP.Diag(OpLoc, diag::ext_pp_comma_expr)
828 << LHS.getRange() << RHS.getRange();
829 Res = RHS.Val; // LHS = LHS,RHS -> RHS.
830 break;
831 case tok::question: {
832 // Parse the : part of the expression.
833 if (PeekTok.isNot(tok::colon)) {
834 PP.Diag(PeekTok.getLocation(), diag::err_expected)
835 << tok::colon << LHS.getRange() << RHS.getRange();
836 PP.Diag(OpLoc, diag::note_matching) << tok::question;
837 return true;
838 }
839 // Consume the :.
840 PP.LexNonComment(PeekTok);
841
842 // Evaluate the value after the :.
843 bool AfterColonLive = ValueLive && LHS.Val == 0;
844 PPValue AfterColonVal(LHS.getBitWidth());
846 if (EvaluateValue(AfterColonVal, PeekTok, DT, AfterColonLive, PP))
847 return true;
848
849 // Parse anything after the : with the same precedence as ?. We allow
850 // things of equal precedence because ?: is right associative.
851 if (EvaluateDirectiveSubExpr(AfterColonVal, ThisPrec,
852 PeekTok, AfterColonLive,
853 IncludedUndefinedIds, PP))
854 return true;
855
856 // Now that we have the condition, the LHS and the RHS of the :, evaluate.
857 Res = LHS.Val != 0 ? RHS.Val : AfterColonVal.Val;
858 RHS.setEnd(AfterColonVal.getRange().getEnd());
859
860 // Usual arithmetic conversions (C99 6.3.1.8p1): result is unsigned if
861 // either operand is unsigned.
862 Res.setIsUnsigned(RHS.isUnsigned() || AfterColonVal.isUnsigned());
863
864 // Figure out the precedence of the token after the : part.
865 PeekPrec = getPrecedence(PeekTok.getKind());
866 break;
867 }
868 case tok::colon:
869 // Don't allow :'s to float around without being part of ?: exprs.
870 PP.Diag(OpLoc, diag::err_pp_colon_without_question)
871 << LHS.getRange() << RHS.getRange();
872 return true;
873 }
874
875 // If this operator is live and overflowed, report the issue.
876 if (Overflow && ValueLive)
877 PP.Diag(OpLoc, diag::warn_pp_expr_overflow)
878 << LHS.getRange() << RHS.getRange();
879
880 // Put the result back into 'LHS' for our next iteration.
881 LHS.Val = Res;
882 LHS.setEnd(RHS.getRange().getEnd());
883 RHS.setIdentifier(nullptr);
884 }
885}
886
887/// EvaluateDirectiveExpression - Evaluate an integer constant expression that
888/// may occur after a #if or #elif directive. If the expression is equivalent
889/// to "!defined(X)" return X in IfNDefMacro.
890Preprocessor::DirectiveEvalResult
891Preprocessor::EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro,
892 Token &Tok, bool &EvaluatedDefined,
893 bool CheckForEoD) {
894 SaveAndRestore PPDir(ParsingIfOrElifDirective, true);
895 // Save the current state of 'DisableMacroExpansion' and reset it to false. If
896 // 'DisableMacroExpansion' is true, then we must be in a macro argument list
897 // in which case a directive is undefined behavior. We want macros to be able
898 // to recursively expand in order to get more gcc-list behavior, so we force
899 // DisableMacroExpansion to false and restore it when we're done parsing the
900 // expression.
901 bool DisableMacroExpansionAtStartOfDirective = DisableMacroExpansion;
902 DisableMacroExpansion = false;
903
904 // Peek ahead one token.
906
907 // C99 6.10.1p3 - All expressions are evaluated as intmax_t or uintmax_t.
908 unsigned BitWidth = getTargetInfo().getIntMaxTWidth();
909
910 PPValue ResVal(BitWidth);
911 DefinedTracker DT;
912 SourceLocation ExprStartLoc = SourceMgr.getExpansionLoc(Tok.getLocation());
913 if (EvaluateValue(ResVal, Tok, DT, true, *this)) {
914 // Parse error, skip the rest of the macro line.
915 if (Tok.isNot(tok::eod))
917
918 // Restore 'DisableMacroExpansion'.
919 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective;
920
921 // We cannot trust the source range from the value because there was a
922 // parse error. Track the range manually -- the end of the directive is the
923 // end of the condition range.
924 return {std::nullopt,
925 false,
927 {ExprStartLoc, Tok.getLocation()}};
928 }
929
930 EvaluatedDefined = DT.State != DefinedTracker::Unknown;
931
932 // If we are at the end of the expression after just parsing a value, there
933 // must be no (unparenthesized) binary operators involved, so we can exit
934 // directly.
935 if (Tok.is(tok::eod)) {
936 // If the expression we parsed was of the form !defined(macro), return the
937 // macro in IfNDefMacro.
939 IfNDefMacro = DT.TheMacro;
940
941 // Restore 'DisableMacroExpansion'.
942 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective;
943 bool IsNonZero = ResVal.Val != 0;
944 SourceRange ValRange = ResVal.getRange();
945 return {std::move(ResVal.Val), IsNonZero, DT.IncludedUndefinedIds,
946 ValRange};
947 }
948
949 // Otherwise, we must have a binary operator (e.g. "#if 1 < 2"), so parse the
950 // operator and the stuff after it.
951 if (EvaluateDirectiveSubExpr(ResVal, getPrecedence(tok::question),
952 Tok, true, DT.IncludedUndefinedIds, *this)) {
953 // Parse error, skip the rest of the macro line.
954 if (Tok.isNot(tok::eod))
956
957 // Restore 'DisableMacroExpansion'.
958 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective;
959 return {std::nullopt,
960 false,
962 {ExprStartLoc, Tok.getLocation()}};
963 }
964
965 if (CheckForEoD) {
966 // If we aren't at the tok::eod token, something bad happened, like an extra
967 // ')' token.
968 if (Tok.isNot(tok::eod)) {
969 Diag(Tok, diag::err_pp_expected_eol);
971 }
972 }
973
974 EvaluatedDefined = EvaluatedDefined || DT.State != DefinedTracker::Unknown;
975
976 // Restore 'DisableMacroExpansion'.
977 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective;
978 bool IsNonZero = ResVal.Val != 0;
979 SourceRange ValRange = ResVal.getRange();
980 return {std::move(ResVal.Val), IsNonZero, DT.IncludedUndefinedIds, ValRange};
981}
982
983Preprocessor::DirectiveEvalResult
984Preprocessor::EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro,
985 bool CheckForEoD) {
986 Token Tok;
987 bool EvaluatedDefined;
988 return EvaluateDirectiveExpression(IfNDefMacro, Tok, EvaluatedDefined,
989 CheckForEoD);
990}
991
992static std::optional<CXXStandardLibraryVersionInfo>
995 MacroInfo *Macro = PP.getMacroInfo(MacroName);
996 if (!Macro || Macro->getNumTokens() != 1 || !Macro->isObjectLike())
997 return std::nullopt;
998
999 const Token &RevisionDateTok = Macro->getReplacementToken(0);
1000
1001 bool Invalid = false;
1003 llvm::StringRef RevisionDate =
1004 PP.getSpelling(RevisionDateTok, Buffer, &Invalid);
1005 if (!Invalid) {
1006 std::uint64_t Value;
1007 // We don't use NumericParser to avoid diagnostics
1008 if (!RevisionDate.consumeInteger(10, Value))
1010 }
1012 0};
1013}
1014
1015std::optional<uint64_t> Preprocessor::getStdLibCxxVersion() {
1016 if (!CXXStandardLibraryVersion)
1017 CXXStandardLibraryVersion = getCXXStandardLibraryVersion(
1018 *this, Ident__GLIBCXX__, CXXStandardLibraryVersionInfo::LibStdCXX);
1019 if (!CXXStandardLibraryVersion)
1020 return std::nullopt;
1021
1022 if (CXXStandardLibraryVersion->Lib ==
1024 return CXXStandardLibraryVersion->Version;
1025 return std::nullopt;
1026}
1027
1028void Preprocessor::setStdLibCxxVersion(std::uint64_t Version) {
1029 CXXStandardLibraryVersion = {
1031 Version,
1032 };
1033}
1034
1036 assert(FixedVersion >= 2000'00'00 && FixedVersion <= 2100'00'00 &&
1037 "invalid value for __GLIBCXX__");
1038 std::optional<std::uint64_t> Ver = getStdLibCxxVersion();
1039 if (!Ver)
1040 return false;
1041 return *Ver < FixedVersion;
1042}
static bool isUnsigned(SValBuilder &SVB, NonLoc Value)
static uint32_t getBitWidth(const Expr *E)
Token Tok
The Token.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Result
Implement __builtin_bit_cast and related operations.
Defines the clang::MacroInfo and clang::MacroDirective classes.
Defines the PPCallbacks interface.
static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, bool ValueLive, Preprocessor &PP)
EvaluateValue - Evaluate the token PeekTok (and any others needed) and return the computed value in R...
static void diagnoseUnexpectedOperator(Preprocessor &PP, PPValue &LHS, Token &Tok)
static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, Token &PeekTok, bool ValueLive, bool &IncludedUndefinedIds, Preprocessor &PP)
EvaluateDirectiveSubExpr - Evaluate the subexpression whose first token is PeekTok,...
static std::optional< CXXStandardLibraryVersionInfo > getCXXStandardLibraryVersion(Preprocessor &PP, IdentifierInfo *MacroName, CXXStandardLibraryVersionInfo::Library Lib)
static unsigned getPrecedence(tok::TokenKind Kind)
getPrecedence - Return the precedence of the specified binary operator token.
static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT, bool ValueLive, Preprocessor &PP)
EvaluateDefined - Process a 'defined(sym)' expression.
static StringRef getIdentifier(const Token &Tok)
Defines the clang::Preprocessor interface.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
static CharSourceRange getRange(const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion)
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines the clang::TokenKind enum and support functions.
CharLiteralParser - Perform interpretation and semantic analysis of a character literal.
void setBegin(SourceLocation b)
virtual void CodeCompleteMacroName(bool IsDefinition)
Callback invoked when performing code completion in a context where the name of a macro is expected.
virtual void CodeCompletePreprocessorExpression()
Callback invoked when performing code completion in a preprocessor expression, such as the condition ...
std::vector< std::string > UndefPrefixes
The list of prefixes from -Wundef-prefix=... used to generate warnings for undefined macros.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:241
DiagnosticOptions & getDiagnosticOptions() const
Retrieve the diagnostic options.
Definition Diagnostic.h:635
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Definition Diagnostic.h:992
One of these records is kept for each identifier that is lexed.
bool isCPlusPlusOperatorKeyword() const
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
A description of the current definition of a macro.
Definition MacroInfo.h:590
Encapsulates the data about a macro definition (e.g.
Definition MacroInfo.h:40
NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber,...
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition PPCallbacks.h:37
bool SingleFileParseMode
When enabled, preprocessor is in a mode for parsing a single file only.
bool SingleModuleParseMode
When enabled, preprocessor is in a mode for parsing a single module only.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void setStdLibCxxVersion(std::uint64_t Version)
PPCallbacks * getPPCallbacks() const
SourceRange DiscardUntilEndOfDirective(SmallVectorImpl< Token > *DiscardedToks=nullptr)
Read and discard all tokens remaining on the current line until the tok::eod token is found.
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
DiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagID) const
void markMacroAsUsed(MacroInfo *MI)
A macro is used, update information about macros that need unused warnings.
void setCodeCompletionReached()
Note that we hit the code-completion point.
void LexNonComment(Token &Result)
Lex a token.
SourceManager & getSourceManager() const
MacroDefinition getMacroDefinition(const IdentifierInfo *II)
bool CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef, bool *ShadowFlag=nullptr)
std::optional< std::uint64_t > getStdLibCxxVersion()
const TargetInfo & getTargetInfo() const
void LexUnexpandedNonComment(Token &Result)
Like LexNonComment, but this disables macro expansion of identifier tokens.
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
void emitMacroExpansionWarnings(const Token &Identifier, bool IsIfnDef=false) const
bool NeedsStdLibCxxWorkaroundBefore(std::uint64_t FixedVersion)
CodeCompletionHandler * getCodeCompletionHandler() const
Retrieve the current code-completion handler.
const PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
const LangOptions & getLangOpts() const
DiagnosticsEngine & getDiagnostics() const
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
A trivial tuple used to represent a source range.
const ExpansionInfo & getExpansion() const
Exposes information about the current target.
Definition TargetInfo.h:228
unsigned getChar32Width() const
getChar32Width/Align - Return the size of 'char32_t' for this target, in bits.
Definition TargetInfo.h:778
static bool isTypeSigned(IntType T)
Returns true if the type is signed; false otherwise.
unsigned getChar16Width() const
getChar16Width/Align - Return the size of 'char16_t' for this target, in bits.
Definition TargetInfo.h:773
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target,...
Definition TargetInfo.h:538
IntType getWCharType() const
Definition TargetInfo.h:426
unsigned getWCharWidth() const
getWCharWidth/Align - Return the size of 'wchar_t' for this target, in bits.
Definition TargetInfo.h:768
unsigned getIntMaxTWidth() const
Return the size of intmax_t and uintmax_t for this target, in bits.
Definition TargetInfo.h:892
unsigned getCharWidth() const
Definition TargetInfo.h:528
Token - This structure provides full information about a lexed token.
Definition Token.h:36
IdentifierInfo * getIdentifierInfo() const
Definition Token.h:225
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition Token.h:142
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
Definition Token.h:104
tok::TokenKind getKind() const
Definition Token.h:99
bool isNot(tok::TokenKind K) const
Definition Token.h:111
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
Definition Token.h:131
bool hasUDSuffix() const
Return true if this token is a string or character literal which has a ud-suffix.
Definition Token.h:349
Defines the clang::TargetInfo interface.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition TokenKinds.h:33
Top level wrappers for InstallAPI frontend operations.
DefinedTracker - This struct is used while parsing expressions to keep track of whether !...
TrackerState
Each time a Value is evaluated, it returns information about whether the parsed value is of the form ...
IdentifierInfo * TheMacro
TheMacro - When the state is DefinedMacro or NotDefinedMacro, this indicates the macro that was check...
enum DefinedTracker::TrackerState State