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