blob: a74396c3146ceba36925fb2200193270874c7bb1 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- PPExpressions.cpp - Preprocessor Expression Evaluation -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Preprocessor::EvaluateDirectiveExpression method,
11// which parses and evaluates integer constant expressions for #if directives.
12//
13//===----------------------------------------------------------------------===//
14//
15// FIXME: implement testing for #assert's.
16//
17//===----------------------------------------------------------------------===//
18
19#include "clang/Lex/Preprocessor.h"
20#include "clang/Lex/MacroInfo.h"
21#include "clang/Lex/LiteralSupport.h"
22#include "clang/Basic/TargetInfo.h"
Chris Lattner500d3292009-01-29 05:15:15 +000023#include "clang/Lex/LexDiagnostic.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000024#include "llvm/ADT/APSInt.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000025using namespace clang;
26
Chris Lattner8ed30442008-05-05 06:45:50 +000027/// PPValue - Represents the value of a subexpression of a preprocessor
28/// conditional and the source range covered by it.
29class PPValue {
30 SourceRange Range;
31public:
32 llvm::APSInt Val;
Mike Stump1eb44332009-09-09 15:08:12 +000033
Chris Lattner8ed30442008-05-05 06:45:50 +000034 // Default ctor - Construct an 'invalid' PPValue.
35 PPValue(unsigned BitWidth) : Val(BitWidth) {}
Mike Stump1eb44332009-09-09 15:08:12 +000036
Chris Lattner8ed30442008-05-05 06:45:50 +000037 unsigned getBitWidth() const { return Val.getBitWidth(); }
38 bool isUnsigned() const { return Val.isUnsigned(); }
Mike Stump1eb44332009-09-09 15:08:12 +000039
Chris Lattner8ed30442008-05-05 06:45:50 +000040 const SourceRange &getRange() const { return Range; }
Mike Stump1eb44332009-09-09 15:08:12 +000041
Chris Lattner8ed30442008-05-05 06:45:50 +000042 void setRange(SourceLocation L) { Range.setBegin(L); Range.setEnd(L); }
43 void setRange(SourceLocation B, SourceLocation E) {
Mike Stump1eb44332009-09-09 15:08:12 +000044 Range.setBegin(B); Range.setEnd(E);
Chris Lattner8ed30442008-05-05 06:45:50 +000045 }
46 void setBegin(SourceLocation L) { Range.setBegin(L); }
47 void setEnd(SourceLocation L) { Range.setEnd(L); }
48};
49
50static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec,
Chris Lattnerd2177732007-07-20 16:59:19 +000051 Token &PeekTok, bool ValueLive,
Reid Spencer5f016e22007-07-11 17:01:13 +000052 Preprocessor &PP);
53
54/// DefinedTracker - This struct is used while parsing expressions to keep track
55/// of whether !defined(X) has been seen.
56///
57/// With this simple scheme, we handle the basic forms:
58/// !defined(X) and !defined X
59/// but we also trivially handle (silly) stuff like:
60/// !!!defined(X) and +!defined(X) and !+!+!defined(X) and !(defined(X)).
61struct DefinedTracker {
62 /// Each time a Value is evaluated, it returns information about whether the
63 /// parsed value is of the form defined(X), !defined(X) or is something else.
64 enum TrackerState {
65 DefinedMacro, // defined(X)
66 NotDefinedMacro, // !defined(X)
67 Unknown // Something else.
68 } State;
69 /// TheMacro - When the state is DefinedMacro or NotDefinedMacro, this
70 /// indicates the macro that was checked.
71 IdentifierInfo *TheMacro;
72};
73
John Thompsona28cc092009-10-30 13:49:06 +000074/// EvaluateDefined - Process a 'defined(sym)' expression.
75static bool EvaluateDefined(PPValue &Result, Token &PeekTok,
76 DefinedTracker &DT, bool ValueLive, Preprocessor &PP) {
77 IdentifierInfo *II;
78 Result.setBegin(PeekTok.getLocation());
79
80 // Get the next token, don't expand it.
81 PP.LexUnexpandedToken(PeekTok);
82
83 // Two options, it can either be a pp-identifier or a (.
84 SourceLocation LParenLoc;
85 if (PeekTok.is(tok::l_paren)) {
86 // Found a paren, remember we saw it and skip it.
87 LParenLoc = PeekTok.getLocation();
88 PP.LexUnexpandedToken(PeekTok);
89 }
90
91 // If we don't have a pp-identifier now, this is an error.
92 if ((II = PeekTok.getIdentifierInfo()) == 0) {
93 PP.Diag(PeekTok, diag::err_pp_defined_requires_identifier);
94 return true;
95 }
96
97 // Otherwise, we got an identifier, is it defined to something?
98 Result.Val = II->hasMacroDefinition();
99 Result.Val.setIsUnsigned(false); // Result is signed intmax_t.
100
101 // If there is a macro, mark it used.
102 if (Result.Val != 0 && ValueLive) {
103 MacroInfo *Macro = PP.getMacroInfo(II);
104 Macro->setIsUsed(true);
105 }
106
107 // Consume identifier.
108 Result.setEnd(PeekTok.getLocation());
109 PP.LexNonComment(PeekTok);
110
111 // If we are in parens, ensure we have a trailing ).
112 if (LParenLoc.isValid()) {
113 if (PeekTok.isNot(tok::r_paren)) {
114 PP.Diag(PeekTok.getLocation(), diag::err_pp_missing_rparen) << "defined";
115 PP.Diag(LParenLoc, diag::note_matching) << "(";
116 return true;
117 }
118 // Consume the ).
119 Result.setEnd(PeekTok.getLocation());
120 PP.LexNonComment(PeekTok);
121 }
122
123 // Success, remember that we saw defined(X).
124 DT.State = DefinedTracker::DefinedMacro;
125 DT.TheMacro = II;
126 return false;
127}
128
Reid Spencer5f016e22007-07-11 17:01:13 +0000129/// EvaluateValue - Evaluate the token PeekTok (and any others needed) and
130/// return the computed value in Result. Return true if there was an error
131/// parsing. This function also returns information about the form of the
132/// expression in DT. See above for information on what DT means.
133///
134/// If ValueLive is false, then this value is being evaluated in a context where
135/// the result is not used. As such, avoid diagnostics that relate to
136/// evaluation.
Chris Lattner8ed30442008-05-05 06:45:50 +0000137static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
138 bool ValueLive, Preprocessor &PP) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000139 DT.State = DefinedTracker::Unknown;
Mike Stump1eb44332009-09-09 15:08:12 +0000140
Reid Spencer5f016e22007-07-11 17:01:13 +0000141 // If this token's spelling is a pp-identifier, check to see if it is
142 // 'defined' or if it is a macro. Note that we check here because many
143 // keywords are pp-identifiers, so we can't check the kind.
144 if (IdentifierInfo *II = PeekTok.getIdentifierInfo()) {
John Thompsona28cc092009-10-30 13:49:06 +0000145 if (II->isStr("defined")) {
146 // Handle "defined X" and "defined(X)".
147 return(EvaluateDefined(Result, PeekTok, DT, ValueLive, PP));
148 } else {
149 // If this identifier isn't 'defined' or one of the special
150 // preprocessor keywords and it wasn't macro expanded, it turns
151 // into a simple 0, unless it is the C++ keyword "true", in which case it
152 // turns into "1".
Chris Lattner4d2d04e2009-01-18 21:18:58 +0000153 if (ValueLive)
154 PP.Diag(PeekTok, diag::warn_pp_undef_identifier) << II;
Chris Lattner8ed30442008-05-05 06:45:50 +0000155 Result.Val = II->getTokenID() == tok::kw_true;
156 Result.Val.setIsUnsigned(false); // "0" is signed intmax_t 0.
157 Result.setRange(PeekTok.getLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +0000158 PP.LexNonComment(PeekTok);
159 return false;
160 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000161 }
Mike Stump1eb44332009-09-09 15:08:12 +0000162
Reid Spencer5f016e22007-07-11 17:01:13 +0000163 switch (PeekTok.getKind()) {
164 default: // Non-value token.
Chris Lattnerd98d9752008-04-13 20:38:43 +0000165 PP.Diag(PeekTok, diag::err_pp_expr_bad_token_start_expr);
Reid Spencer5f016e22007-07-11 17:01:13 +0000166 return true;
167 case tok::eom:
168 case tok::r_paren:
169 // If there is no expression, report and exit.
170 PP.Diag(PeekTok, diag::err_pp_expected_value_in_expr);
171 return true;
172 case tok::numeric_constant: {
173 llvm::SmallString<64> IntegerBuffer;
174 IntegerBuffer.resize(PeekTok.getLength());
175 const char *ThisTokBegin = &IntegerBuffer[0];
176 unsigned ActualLength = PP.getSpelling(PeekTok, ThisTokBegin);
Mike Stump1eb44332009-09-09 15:08:12 +0000177 NumericLiteralParser Literal(ThisTokBegin, ThisTokBegin+ActualLength,
Reid Spencer5f016e22007-07-11 17:01:13 +0000178 PeekTok.getLocation(), PP);
179 if (Literal.hadError)
180 return true; // a diagnostic was already reported.
Mike Stump1eb44332009-09-09 15:08:12 +0000181
Chris Lattner6e400c22007-08-26 03:29:23 +0000182 if (Literal.isFloatingLiteral() || Literal.isImaginary) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000183 PP.Diag(PeekTok, diag::err_pp_illegal_floating_literal);
184 return true;
185 }
186 assert(Literal.isIntegerLiteral() && "Unknown ppnumber");
187
Neil Boothb9449512007-08-29 22:00:19 +0000188 // long long is a C99 feature.
189 if (!PP.getLangOptions().C99 && !PP.getLangOptions().CPlusPlus0x
Neil Booth79859c32007-08-29 22:13:52 +0000190 && Literal.isLongLong)
Neil Boothb9449512007-08-29 22:00:19 +0000191 PP.Diag(PeekTok, diag::ext_longlong);
192
Reid Spencer5f016e22007-07-11 17:01:13 +0000193 // Parse the integer literal into Result.
Chris Lattner8ed30442008-05-05 06:45:50 +0000194 if (Literal.GetIntegerValue(Result.Val)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000195 // Overflow parsing integer literal.
196 if (ValueLive) PP.Diag(PeekTok, diag::warn_integer_too_large);
Chris Lattner8ed30442008-05-05 06:45:50 +0000197 Result.Val.setIsUnsigned(true);
Reid Spencer5f016e22007-07-11 17:01:13 +0000198 } else {
199 // Set the signedness of the result to match whether there was a U suffix
200 // or not.
Chris Lattner8ed30442008-05-05 06:45:50 +0000201 Result.Val.setIsUnsigned(Literal.isUnsigned);
Mike Stump1eb44332009-09-09 15:08:12 +0000202
Reid Spencer5f016e22007-07-11 17:01:13 +0000203 // Detect overflow based on whether the value is signed. If signed
204 // and if the value is too large, emit a warning "integer constant is so
205 // large that it is unsigned" e.g. on 12345678901234567890 where intmax_t
206 // is 64-bits.
Chris Lattner8ed30442008-05-05 06:45:50 +0000207 if (!Literal.isUnsigned && Result.Val.isNegative()) {
Chris Lattnerb081a352008-07-03 03:47:30 +0000208 // Don't warn for a hex literal: 0x8000..0 shouldn't warn.
209 if (ValueLive && Literal.getRadix() != 16)
Chris Lattner8ed30442008-05-05 06:45:50 +0000210 PP.Diag(PeekTok, diag::warn_integer_too_large_for_signed);
211 Result.Val.setIsUnsigned(true);
Reid Spencer5f016e22007-07-11 17:01:13 +0000212 }
213 }
Mike Stump1eb44332009-09-09 15:08:12 +0000214
Reid Spencer5f016e22007-07-11 17:01:13 +0000215 // Consume the token.
Chris Lattner8ed30442008-05-05 06:45:50 +0000216 Result.setRange(PeekTok.getLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +0000217 PP.LexNonComment(PeekTok);
218 return false;
219 }
220 case tok::char_constant: { // 'x'
221 llvm::SmallString<32> CharBuffer;
222 CharBuffer.resize(PeekTok.getLength());
223 const char *ThisTokBegin = &CharBuffer[0];
224 unsigned ActualLength = PP.getSpelling(PeekTok, ThisTokBegin);
Mike Stump1eb44332009-09-09 15:08:12 +0000225 CharLiteralParser Literal(ThisTokBegin, ThisTokBegin+ActualLength,
Reid Spencer5f016e22007-07-11 17:01:13 +0000226 PeekTok.getLocation(), PP);
227 if (Literal.hadError())
228 return true; // A diagnostic was already emitted.
229
230 // Character literals are always int or wchar_t, expand to intmax_t.
231 TargetInfo &TI = PP.getTargetInfo();
Eli Friedman2a1c3632009-06-01 05:25:02 +0000232 unsigned NumBits;
233 if (Literal.isMultiChar())
234 NumBits = TI.getIntWidth();
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000235 else if (Literal.isWide())
236 NumBits = TI.getWCharWidth();
Eli Friedman2a1c3632009-06-01 05:25:02 +0000237 else
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000238 NumBits = TI.getCharWidth();
Eli Friedman2a1c3632009-06-01 05:25:02 +0000239
Reid Spencer5f016e22007-07-11 17:01:13 +0000240 // Set the width.
241 llvm::APSInt Val(NumBits);
242 // Set the value.
243 Val = Literal.getValue();
244 // Set the signedness.
Eli Friedman15b91762009-06-05 07:05:05 +0000245 Val.setIsUnsigned(!PP.getLangOptions().CharIsSigned);
Mike Stump1eb44332009-09-09 15:08:12 +0000246
Chris Lattner8ed30442008-05-05 06:45:50 +0000247 if (Result.Val.getBitWidth() > Val.getBitWidth()) {
248 Result.Val = Val.extend(Result.Val.getBitWidth());
Reid Spencer5f016e22007-07-11 17:01:13 +0000249 } else {
Chris Lattner8ed30442008-05-05 06:45:50 +0000250 assert(Result.Val.getBitWidth() == Val.getBitWidth() &&
Reid Spencer5f016e22007-07-11 17:01:13 +0000251 "intmax_t smaller than char/wchar_t?");
Chris Lattner8ed30442008-05-05 06:45:50 +0000252 Result.Val = Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000253 }
254
255 // Consume the token.
Chris Lattner8ed30442008-05-05 06:45:50 +0000256 Result.setRange(PeekTok.getLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +0000257 PP.LexNonComment(PeekTok);
258 return false;
259 }
Chris Lattner8ed30442008-05-05 06:45:50 +0000260 case tok::l_paren: {
261 SourceLocation Start = PeekTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000262 PP.LexNonComment(PeekTok); // Eat the (.
263 // Parse the value and if there are any binary operators involved, parse
264 // them.
265 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
266
267 // If this is a silly value like (X), which doesn't need parens, check for
268 // !(defined X).
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000269 if (PeekTok.is(tok::r_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000270 // Just use DT unmodified as our result.
271 } else {
Chris Lattner8ed30442008-05-05 06:45:50 +0000272 // Otherwise, we have something like (x+y), and we consumed '(x'.
Reid Spencer5f016e22007-07-11 17:01:13 +0000273 if (EvaluateDirectiveSubExpr(Result, 1, PeekTok, ValueLive, PP))
274 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000275
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000276 if (PeekTok.isNot(tok::r_paren)) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000277 PP.Diag(PeekTok.getLocation(), diag::err_pp_expected_rparen)
278 << Result.getRange();
Chris Lattner28eb7e92008-11-23 23:17:07 +0000279 PP.Diag(Start, diag::note_matching) << "(";
Reid Spencer5f016e22007-07-11 17:01:13 +0000280 return true;
281 }
282 DT.State = DefinedTracker::Unknown;
283 }
Chris Lattner8ed30442008-05-05 06:45:50 +0000284 Result.setRange(Start, PeekTok.getLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +0000285 PP.LexNonComment(PeekTok); // Eat the ).
286 return false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000287 }
288 case tok::plus: {
289 SourceLocation Start = PeekTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000290 // Unary plus doesn't modify the value.
291 PP.LexNonComment(PeekTok);
Chris Lattner8ed30442008-05-05 06:45:50 +0000292 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
293 Result.setBegin(Start);
294 return false;
295 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000296 case tok::minus: {
297 SourceLocation Loc = PeekTok.getLocation();
298 PP.LexNonComment(PeekTok);
299 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
Chris Lattner8ed30442008-05-05 06:45:50 +0000300 Result.setBegin(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000301
Reid Spencer5f016e22007-07-11 17:01:13 +0000302 // C99 6.5.3.3p3: The sign of the result matches the sign of the operand.
Chris Lattner8ed30442008-05-05 06:45:50 +0000303 Result.Val = -Result.Val;
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Chris Lattnerb081a352008-07-03 03:47:30 +0000305 // -MININT is the only thing that overflows. Unsigned never overflows.
306 bool Overflow = !Result.isUnsigned() && Result.Val.isMinSignedValue();
Mike Stump1eb44332009-09-09 15:08:12 +0000307
Reid Spencer5f016e22007-07-11 17:01:13 +0000308 // If this operator is live and overflowed, report the issue.
309 if (Overflow && ValueLive)
Chris Lattner204b2fe2008-11-18 21:48:13 +0000310 PP.Diag(Loc, diag::warn_pp_expr_overflow) << Result.getRange();
Mike Stump1eb44332009-09-09 15:08:12 +0000311
Reid Spencer5f016e22007-07-11 17:01:13 +0000312 DT.State = DefinedTracker::Unknown;
313 return false;
314 }
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Chris Lattner8ed30442008-05-05 06:45:50 +0000316 case tok::tilde: {
317 SourceLocation Start = PeekTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000318 PP.LexNonComment(PeekTok);
319 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
Chris Lattner8ed30442008-05-05 06:45:50 +0000320 Result.setBegin(Start);
321
Reid Spencer5f016e22007-07-11 17:01:13 +0000322 // C99 6.5.3.3p4: The sign of the result matches the sign of the operand.
Chris Lattner8ed30442008-05-05 06:45:50 +0000323 Result.Val = ~Result.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000324 DT.State = DefinedTracker::Unknown;
325 return false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000326 }
Mike Stump1eb44332009-09-09 15:08:12 +0000327
Chris Lattner8ed30442008-05-05 06:45:50 +0000328 case tok::exclaim: {
329 SourceLocation Start = PeekTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000330 PP.LexNonComment(PeekTok);
331 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
Chris Lattner8ed30442008-05-05 06:45:50 +0000332 Result.setBegin(Start);
333 Result.Val = !Result.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000334 // C99 6.5.3.3p5: The sign of the result is 'int', aka it is signed.
Chris Lattner8ed30442008-05-05 06:45:50 +0000335 Result.Val.setIsUnsigned(false);
Mike Stump1eb44332009-09-09 15:08:12 +0000336
Reid Spencer5f016e22007-07-11 17:01:13 +0000337 if (DT.State == DefinedTracker::DefinedMacro)
338 DT.State = DefinedTracker::NotDefinedMacro;
339 else if (DT.State == DefinedTracker::NotDefinedMacro)
340 DT.State = DefinedTracker::DefinedMacro;
341 return false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000342 }
Mike Stump1eb44332009-09-09 15:08:12 +0000343
Reid Spencer5f016e22007-07-11 17:01:13 +0000344 // FIXME: Handle #assert
345 }
346}
347
348
349
350/// getPrecedence - Return the precedence of the specified binary operator
351/// token. This returns:
352/// ~0 - Invalid token.
Chris Lattner9e66ba62008-05-05 04:10:51 +0000353/// 14 -> 3 - various operators.
354/// 0 - 'eom' or ')'
Reid Spencer5f016e22007-07-11 17:01:13 +0000355static unsigned getPrecedence(tok::TokenKind Kind) {
356 switch (Kind) {
357 default: return ~0U;
358 case tok::percent:
359 case tok::slash:
360 case tok::star: return 14;
361 case tok::plus:
362 case tok::minus: return 13;
363 case tok::lessless:
364 case tok::greatergreater: return 12;
365 case tok::lessequal:
366 case tok::less:
367 case tok::greaterequal:
368 case tok::greater: return 11;
369 case tok::exclaimequal:
370 case tok::equalequal: return 10;
371 case tok::amp: return 9;
372 case tok::caret: return 8;
373 case tok::pipe: return 7;
374 case tok::ampamp: return 6;
375 case tok::pipepipe: return 5;
Chris Lattner98ed49f2008-05-05 20:07:41 +0000376 case tok::question: return 4;
377 case tok::comma: return 3;
Chris Lattner91891562008-05-04 18:36:18 +0000378 case tok::colon: return 2;
Reid Spencer5f016e22007-07-11 17:01:13 +0000379 case tok::r_paren: return 0; // Lowest priority, end of expr.
380 case tok::eom: return 0; // Lowest priority, end of macro.
381 }
382}
383
384
385/// EvaluateDirectiveSubExpr - Evaluate the subexpression whose first token is
Chris Lattner8ed30442008-05-05 06:45:50 +0000386/// PeekTok, and whose precedence is PeekPrec. This returns the result in LHS.
Reid Spencer5f016e22007-07-11 17:01:13 +0000387///
388/// If ValueLive is false, then this value is being evaluated in a context where
389/// the result is not used. As such, avoid diagnostics that relate to
Chris Lattner8ed30442008-05-05 06:45:50 +0000390/// evaluation, such as division by zero warnings.
391static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec,
Chris Lattnerd2177732007-07-20 16:59:19 +0000392 Token &PeekTok, bool ValueLive,
Reid Spencer5f016e22007-07-11 17:01:13 +0000393 Preprocessor &PP) {
394 unsigned PeekPrec = getPrecedence(PeekTok.getKind());
395 // If this token isn't valid, report the error.
396 if (PeekPrec == ~0U) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000397 PP.Diag(PeekTok.getLocation(), diag::err_pp_expr_bad_token_binop)
398 << LHS.getRange();
Reid Spencer5f016e22007-07-11 17:01:13 +0000399 return true;
400 }
Mike Stump1eb44332009-09-09 15:08:12 +0000401
Reid Spencer5f016e22007-07-11 17:01:13 +0000402 while (1) {
403 // If this token has a lower precedence than we are allowed to parse, return
404 // it so that higher levels of the recursion can parse it.
405 if (PeekPrec < MinPrec)
406 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000407
Reid Spencer5f016e22007-07-11 17:01:13 +0000408 tok::TokenKind Operator = PeekTok.getKind();
Mike Stump1eb44332009-09-09 15:08:12 +0000409
Reid Spencer5f016e22007-07-11 17:01:13 +0000410 // If this is a short-circuiting operator, see if the RHS of the operator is
Mike Stump1eb44332009-09-09 15:08:12 +0000411 // dead. Note that this cannot just clobber ValueLive. Consider
Reid Spencer5f016e22007-07-11 17:01:13 +0000412 // "0 && 1 ? 4 : 1 / 0", which is parsed as "(0 && 1) ? 4 : (1 / 0)". In
413 // this example, the RHS of the && being dead does not make the rest of the
414 // expr dead.
415 bool RHSIsLive;
Chris Lattner8ed30442008-05-05 06:45:50 +0000416 if (Operator == tok::ampamp && LHS.Val == 0)
Reid Spencer5f016e22007-07-11 17:01:13 +0000417 RHSIsLive = false; // RHS of "0 && x" is dead.
Chris Lattner8ed30442008-05-05 06:45:50 +0000418 else if (Operator == tok::pipepipe && LHS.Val != 0)
Reid Spencer5f016e22007-07-11 17:01:13 +0000419 RHSIsLive = false; // RHS of "1 || x" is dead.
Chris Lattner8ed30442008-05-05 06:45:50 +0000420 else if (Operator == tok::question && LHS.Val == 0)
Reid Spencer5f016e22007-07-11 17:01:13 +0000421 RHSIsLive = false; // RHS (x) of "0 ? x : y" is dead.
422 else
423 RHSIsLive = ValueLive;
424
Chris Lattner8ed30442008-05-05 06:45:50 +0000425 // Consume the operator, remembering the operator's location for reporting.
426 SourceLocation OpLoc = PeekTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000427 PP.LexNonComment(PeekTok);
428
Chris Lattner8ed30442008-05-05 06:45:50 +0000429 PPValue RHS(LHS.getBitWidth());
Reid Spencer5f016e22007-07-11 17:01:13 +0000430 // Parse the RHS of the operator.
431 DefinedTracker DT;
432 if (EvaluateValue(RHS, PeekTok, DT, RHSIsLive, PP)) return true;
433
434 // Remember the precedence of this operator and get the precedence of the
435 // operator immediately to the right of the RHS.
436 unsigned ThisPrec = PeekPrec;
437 PeekPrec = getPrecedence(PeekTok.getKind());
438
439 // If this token isn't valid, report the error.
440 if (PeekPrec == ~0U) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000441 PP.Diag(PeekTok.getLocation(), diag::err_pp_expr_bad_token_binop)
442 << RHS.getRange();
Reid Spencer5f016e22007-07-11 17:01:13 +0000443 return true;
444 }
Mike Stump1eb44332009-09-09 15:08:12 +0000445
Chris Lattner98ed49f2008-05-05 20:07:41 +0000446 // Decide whether to include the next binop in this subexpression. For
447 // example, when parsing x+y*z and looking at '*', we want to recursively
Chris Lattner44cbbb02008-05-05 20:09:27 +0000448 // handle y*z as a single subexpression. We do this because the precedence
449 // of * is higher than that of +. The only strange case we have to handle
450 // here is for the ?: operator, where the precedence is actually lower than
451 // the LHS of the '?'. The grammar rule is:
Chris Lattner98ed49f2008-05-05 20:07:41 +0000452 //
453 // conditional-expression ::=
454 // logical-OR-expression ? expression : conditional-expression
455 // where 'expression' is actually comma-expression.
456 unsigned RHSPrec;
457 if (Operator == tok::question)
458 // The RHS of "?" should be maximally consumed as an expression.
459 RHSPrec = getPrecedence(tok::comma);
460 else // All others should munch while higher precedence.
461 RHSPrec = ThisPrec+1;
Mike Stump1eb44332009-09-09 15:08:12 +0000462
Chris Lattner98ed49f2008-05-05 20:07:41 +0000463 if (PeekPrec >= RHSPrec) {
464 if (EvaluateDirectiveSubExpr(RHS, RHSPrec, PeekTok, RHSIsLive, PP))
Reid Spencer5f016e22007-07-11 17:01:13 +0000465 return true;
466 PeekPrec = getPrecedence(PeekTok.getKind());
467 }
468 assert(PeekPrec <= ThisPrec && "Recursion didn't work!");
Mike Stump1eb44332009-09-09 15:08:12 +0000469
Reid Spencer5f016e22007-07-11 17:01:13 +0000470 // Usual arithmetic conversions (C99 6.3.1.8p1): result is unsigned if
Mike Stump1eb44332009-09-09 15:08:12 +0000471 // either operand is unsigned.
Reid Spencer5f016e22007-07-11 17:01:13 +0000472 llvm::APSInt Res(LHS.getBitWidth());
Chris Lattner019ef7e2008-05-04 23:46:17 +0000473 switch (Operator) {
474 case tok::question: // No UAC for x and y in "x ? y : z".
475 case tok::lessless: // Shift amount doesn't UAC with shift value.
476 case tok::greatergreater: // Shift amount doesn't UAC with shift value.
477 case tok::comma: // Comma operands are not subject to UACs.
478 case tok::pipepipe: // Logical || does not do UACs.
479 case tok::ampamp: // Logical && does not do UACs.
480 break; // No UAC
481 default:
Reid Spencer5f016e22007-07-11 17:01:13 +0000482 Res.setIsUnsigned(LHS.isUnsigned()|RHS.isUnsigned());
483 // If this just promoted something from signed to unsigned, and if the
484 // value was negative, warn about it.
485 if (ValueLive && Res.isUnsigned()) {
Chris Lattner8ed30442008-05-05 06:45:50 +0000486 if (!LHS.isUnsigned() && LHS.Val.isNegative())
Chris Lattner204b2fe2008-11-18 21:48:13 +0000487 PP.Diag(OpLoc, diag::warn_pp_convert_lhs_to_positive)
488 << LHS.Val.toString(10, true) + " to " +
489 LHS.Val.toString(10, false)
490 << LHS.getRange() << RHS.getRange();
Chris Lattner8ed30442008-05-05 06:45:50 +0000491 if (!RHS.isUnsigned() && RHS.Val.isNegative())
Chris Lattner204b2fe2008-11-18 21:48:13 +0000492 PP.Diag(OpLoc, diag::warn_pp_convert_rhs_to_positive)
493 << RHS.Val.toString(10, true) + " to " +
494 RHS.Val.toString(10, false)
495 << LHS.getRange() << RHS.getRange();
Reid Spencer5f016e22007-07-11 17:01:13 +0000496 }
Chris Lattner8ed30442008-05-05 06:45:50 +0000497 LHS.Val.setIsUnsigned(Res.isUnsigned());
498 RHS.Val.setIsUnsigned(Res.isUnsigned());
Reid Spencer5f016e22007-07-11 17:01:13 +0000499 }
Mike Stump1eb44332009-09-09 15:08:12 +0000500
Reid Spencer5f016e22007-07-11 17:01:13 +0000501 // FIXME: All of these should detect and report overflow??
502 bool Overflow = false;
503 switch (Operator) {
504 default: assert(0 && "Unknown operator token!");
505 case tok::percent:
Chris Lattner8ed30442008-05-05 06:45:50 +0000506 if (RHS.Val != 0)
507 Res = LHS.Val % RHS.Val;
508 else if (ValueLive) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000509 PP.Diag(OpLoc, diag::err_pp_remainder_by_zero)
510 << LHS.getRange() << RHS.getRange();
Chris Lattner8ed30442008-05-05 06:45:50 +0000511 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000512 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000513 break;
514 case tok::slash:
Chris Lattner8ed30442008-05-05 06:45:50 +0000515 if (RHS.Val != 0) {
516 Res = LHS.Val / RHS.Val;
517 if (LHS.Val.isSigned()) // MININT/-1 --> overflow.
518 Overflow = LHS.Val.isMinSignedValue() && RHS.Val.isAllOnesValue();
519 } else if (ValueLive) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000520 PP.Diag(OpLoc, diag::err_pp_division_by_zero)
521 << LHS.getRange() << RHS.getRange();
Chris Lattner8ed30442008-05-05 06:45:50 +0000522 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000523 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000524 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000525
Reid Spencer5f016e22007-07-11 17:01:13 +0000526 case tok::star:
Chris Lattner8ed30442008-05-05 06:45:50 +0000527 Res = LHS.Val * RHS.Val;
Eli Friedman3265a422009-05-16 21:24:10 +0000528 if (Res.isSigned() && LHS.Val != 0 && RHS.Val != 0)
Chris Lattner8ed30442008-05-05 06:45:50 +0000529 Overflow = Res/RHS.Val != LHS.Val || Res/LHS.Val != RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000530 break;
531 case tok::lessless: {
532 // Determine whether overflow is about to happen.
Chris Lattner8ed30442008-05-05 06:45:50 +0000533 unsigned ShAmt = static_cast<unsigned>(RHS.Val.getLimitedValue());
534 if (ShAmt >= LHS.Val.getBitWidth())
535 Overflow = true, ShAmt = LHS.Val.getBitWidth()-1;
Reid Spencer5f016e22007-07-11 17:01:13 +0000536 else if (LHS.isUnsigned())
Eli Friedman3265a422009-05-16 21:24:10 +0000537 Overflow = false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000538 else if (LHS.Val.isNonNegative()) // Don't allow sign change.
539 Overflow = ShAmt >= LHS.Val.countLeadingZeros();
Reid Spencer5f016e22007-07-11 17:01:13 +0000540 else
Chris Lattner8ed30442008-05-05 06:45:50 +0000541 Overflow = ShAmt >= LHS.Val.countLeadingOnes();
Mike Stump1eb44332009-09-09 15:08:12 +0000542
Chris Lattner8ed30442008-05-05 06:45:50 +0000543 Res = LHS.Val << ShAmt;
Reid Spencer5f016e22007-07-11 17:01:13 +0000544 break;
545 }
546 case tok::greatergreater: {
547 // Determine whether overflow is about to happen.
Chris Lattner8ed30442008-05-05 06:45:50 +0000548 unsigned ShAmt = static_cast<unsigned>(RHS.Val.getLimitedValue());
Reid Spencer5f016e22007-07-11 17:01:13 +0000549 if (ShAmt >= LHS.getBitWidth())
550 Overflow = true, ShAmt = LHS.getBitWidth()-1;
Chris Lattner8ed30442008-05-05 06:45:50 +0000551 Res = LHS.Val >> ShAmt;
Reid Spencer5f016e22007-07-11 17:01:13 +0000552 break;
553 }
554 case tok::plus:
Chris Lattner8ed30442008-05-05 06:45:50 +0000555 Res = LHS.Val + RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000556 if (LHS.isUnsigned())
Eli Friedman3265a422009-05-16 21:24:10 +0000557 Overflow = false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000558 else if (LHS.Val.isNonNegative() == RHS.Val.isNonNegative() &&
559 Res.isNonNegative() != LHS.Val.isNonNegative())
Reid Spencer5f016e22007-07-11 17:01:13 +0000560 Overflow = true; // Overflow for signed addition.
561 break;
562 case tok::minus:
Chris Lattner8ed30442008-05-05 06:45:50 +0000563 Res = LHS.Val - RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000564 if (LHS.isUnsigned())
Eli Friedman3265a422009-05-16 21:24:10 +0000565 Overflow = false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000566 else if (LHS.Val.isNonNegative() != RHS.Val.isNonNegative() &&
567 Res.isNonNegative() != LHS.Val.isNonNegative())
Reid Spencer5f016e22007-07-11 17:01:13 +0000568 Overflow = true; // Overflow for signed subtraction.
569 break;
570 case tok::lessequal:
Chris Lattner8ed30442008-05-05 06:45:50 +0000571 Res = LHS.Val <= RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000572 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
573 break;
574 case tok::less:
Chris Lattner8ed30442008-05-05 06:45:50 +0000575 Res = LHS.Val < RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000576 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
577 break;
578 case tok::greaterequal:
Chris Lattner8ed30442008-05-05 06:45:50 +0000579 Res = LHS.Val >= RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000580 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
581 break;
582 case tok::greater:
Chris Lattner8ed30442008-05-05 06:45:50 +0000583 Res = LHS.Val > RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000584 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
585 break;
586 case tok::exclaimequal:
Chris Lattner8ed30442008-05-05 06:45:50 +0000587 Res = LHS.Val != RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000588 Res.setIsUnsigned(false); // C99 6.5.9p3, result is always int (signed)
589 break;
590 case tok::equalequal:
Chris Lattner8ed30442008-05-05 06:45:50 +0000591 Res = LHS.Val == RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000592 Res.setIsUnsigned(false); // C99 6.5.9p3, result is always int (signed)
593 break;
594 case tok::amp:
Chris Lattner8ed30442008-05-05 06:45:50 +0000595 Res = LHS.Val & RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000596 break;
597 case tok::caret:
Chris Lattner8ed30442008-05-05 06:45:50 +0000598 Res = LHS.Val ^ RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000599 break;
600 case tok::pipe:
Chris Lattner8ed30442008-05-05 06:45:50 +0000601 Res = LHS.Val | RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000602 break;
603 case tok::ampamp:
Chris Lattner8ed30442008-05-05 06:45:50 +0000604 Res = (LHS.Val != 0 && RHS.Val != 0);
Reid Spencer5f016e22007-07-11 17:01:13 +0000605 Res.setIsUnsigned(false); // C99 6.5.13p3, result is always int (signed)
606 break;
607 case tok::pipepipe:
Chris Lattner8ed30442008-05-05 06:45:50 +0000608 Res = (LHS.Val != 0 || RHS.Val != 0);
Reid Spencer5f016e22007-07-11 17:01:13 +0000609 Res.setIsUnsigned(false); // C99 6.5.14p3, result is always int (signed)
610 break;
611 case tok::comma:
Chris Lattner91891562008-05-04 18:36:18 +0000612 // Comma is invalid in pp expressions in c89/c++ mode, but is valid in C99
613 // if not being evaluated.
614 if (!PP.getLangOptions().C99 || ValueLive)
Chris Lattner204b2fe2008-11-18 21:48:13 +0000615 PP.Diag(OpLoc, diag::ext_pp_comma_expr)
616 << LHS.getRange() << RHS.getRange();
Chris Lattner8ed30442008-05-05 06:45:50 +0000617 Res = RHS.Val; // LHS = LHS,RHS -> RHS.
Mike Stump1eb44332009-09-09 15:08:12 +0000618 break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000619 case tok::question: {
620 // Parse the : part of the expression.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000621 if (PeekTok.isNot(tok::colon)) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000622 PP.Diag(PeekTok.getLocation(), diag::err_expected_colon)
623 << LHS.getRange(), RHS.getRange();
Chris Lattner28eb7e92008-11-23 23:17:07 +0000624 PP.Diag(OpLoc, diag::note_matching) << "?";
Reid Spencer5f016e22007-07-11 17:01:13 +0000625 return true;
626 }
627 // Consume the :.
628 PP.LexNonComment(PeekTok);
629
630 // Evaluate the value after the :.
Chris Lattner8ed30442008-05-05 06:45:50 +0000631 bool AfterColonLive = ValueLive && LHS.Val == 0;
632 PPValue AfterColonVal(LHS.getBitWidth());
Reid Spencer5f016e22007-07-11 17:01:13 +0000633 DefinedTracker DT;
634 if (EvaluateValue(AfterColonVal, PeekTok, DT, AfterColonLive, PP))
635 return true;
636
Chris Lattner44cbbb02008-05-05 20:09:27 +0000637 // Parse anything after the : with the same precedence as ?. We allow
638 // things of equal precedence because ?: is right associative.
Chris Lattner98ed49f2008-05-05 20:07:41 +0000639 if (EvaluateDirectiveSubExpr(AfterColonVal, ThisPrec,
Reid Spencer5f016e22007-07-11 17:01:13 +0000640 PeekTok, AfterColonLive, PP))
641 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Reid Spencer5f016e22007-07-11 17:01:13 +0000643 // Now that we have the condition, the LHS and the RHS of the :, evaluate.
Chris Lattner8ed30442008-05-05 06:45:50 +0000644 Res = LHS.Val != 0 ? RHS.Val : AfterColonVal.Val;
645 RHS.setEnd(AfterColonVal.getRange().getEnd());
Reid Spencer5f016e22007-07-11 17:01:13 +0000646
647 // Usual arithmetic conversions (C99 6.3.1.8p1): result is unsigned if
648 // either operand is unsigned.
649 Res.setIsUnsigned(RHS.isUnsigned() | AfterColonVal.isUnsigned());
Mike Stump1eb44332009-09-09 15:08:12 +0000650
Reid Spencer5f016e22007-07-11 17:01:13 +0000651 // Figure out the precedence of the token after the : part.
652 PeekPrec = getPrecedence(PeekTok.getKind());
653 break;
654 }
655 case tok::colon:
656 // Don't allow :'s to float around without being part of ?: exprs.
Chris Lattner204b2fe2008-11-18 21:48:13 +0000657 PP.Diag(OpLoc, diag::err_pp_colon_without_question)
658 << LHS.getRange() << RHS.getRange();
Reid Spencer5f016e22007-07-11 17:01:13 +0000659 return true;
660 }
661
662 // If this operator is live and overflowed, report the issue.
663 if (Overflow && ValueLive)
Chris Lattner204b2fe2008-11-18 21:48:13 +0000664 PP.Diag(OpLoc, diag::warn_pp_expr_overflow)
665 << LHS.getRange() << RHS.getRange();
Mike Stump1eb44332009-09-09 15:08:12 +0000666
Reid Spencer5f016e22007-07-11 17:01:13 +0000667 // Put the result back into 'LHS' for our next iteration.
Chris Lattner8ed30442008-05-05 06:45:50 +0000668 LHS.Val = Res;
669 LHS.setEnd(RHS.getRange().getEnd());
Reid Spencer5f016e22007-07-11 17:01:13 +0000670 }
Mike Stump1eb44332009-09-09 15:08:12 +0000671
Reid Spencer5f016e22007-07-11 17:01:13 +0000672 return false;
673}
674
675/// EvaluateDirectiveExpression - Evaluate an integer constant expression that
676/// may occur after a #if or #elif directive. If the expression is equivalent
677/// to "!defined(X)" return X in IfNDefMacro.
678bool Preprocessor::
679EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) {
680 // Peek ahead one token.
Chris Lattnerd2177732007-07-20 16:59:19 +0000681 Token Tok;
Reid Spencer5f016e22007-07-11 17:01:13 +0000682 Lex(Tok);
Mike Stump1eb44332009-09-09 15:08:12 +0000683
Reid Spencer5f016e22007-07-11 17:01:13 +0000684 // C99 6.10.1p3 - All expressions are evaluated as intmax_t or uintmax_t.
Chris Lattner98be4942008-03-05 18:54:05 +0000685 unsigned BitWidth = getTargetInfo().getIntMaxTWidth();
Mike Stump1eb44332009-09-09 15:08:12 +0000686
Chris Lattner8ed30442008-05-05 06:45:50 +0000687 PPValue ResVal(BitWidth);
Reid Spencer5f016e22007-07-11 17:01:13 +0000688 DefinedTracker DT;
689 if (EvaluateValue(ResVal, Tok, DT, true, *this)) {
690 // Parse error, skip the rest of the macro line.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000691 if (Tok.isNot(tok::eom))
Reid Spencer5f016e22007-07-11 17:01:13 +0000692 DiscardUntilEndOfDirective();
693 return false;
694 }
Mike Stump1eb44332009-09-09 15:08:12 +0000695
Reid Spencer5f016e22007-07-11 17:01:13 +0000696 // If we are at the end of the expression after just parsing a value, there
697 // must be no (unparenthesized) binary operators involved, so we can exit
698 // directly.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000699 if (Tok.is(tok::eom)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000700 // If the expression we parsed was of the form !defined(macro), return the
701 // macro in IfNDefMacro.
702 if (DT.State == DefinedTracker::NotDefinedMacro)
703 IfNDefMacro = DT.TheMacro;
Mike Stump1eb44332009-09-09 15:08:12 +0000704
Chris Lattner8ed30442008-05-05 06:45:50 +0000705 return ResVal.Val != 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000706 }
Mike Stump1eb44332009-09-09 15:08:12 +0000707
Reid Spencer5f016e22007-07-11 17:01:13 +0000708 // Otherwise, we must have a binary operator (e.g. "#if 1 < 2"), so parse the
709 // operator and the stuff after it.
Chris Lattner98ed49f2008-05-05 20:07:41 +0000710 if (EvaluateDirectiveSubExpr(ResVal, getPrecedence(tok::question),
711 Tok, true, *this)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000712 // Parse error, skip the rest of the macro line.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000713 if (Tok.isNot(tok::eom))
Reid Spencer5f016e22007-07-11 17:01:13 +0000714 DiscardUntilEndOfDirective();
715 return false;
716 }
Mike Stump1eb44332009-09-09 15:08:12 +0000717
Reid Spencer5f016e22007-07-11 17:01:13 +0000718 // If we aren't at the tok::eom token, something bad happened, like an extra
719 // ')' token.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000720 if (Tok.isNot(tok::eom)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000721 Diag(Tok, diag::err_pp_expected_eol);
722 DiscardUntilEndOfDirective();
723 }
Mike Stump1eb44332009-09-09 15:08:12 +0000724
Chris Lattner8ed30442008-05-05 06:45:50 +0000725 return ResVal.Val != 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000726}
727