blob: 6422752ae92b90e5c4f0235d1b927e4f568bad17 [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()) {
Chris Lattnerf8806622009-12-14 04:26:45 +0000145 // Handle "defined X" and "defined(X)".
146 if (II->isStr("defined"))
John Thompsona28cc092009-10-30 13:49:06 +0000147 return(EvaluateDefined(Result, PeekTok, DT, ValueLive, PP));
Chris Lattnerf8806622009-12-14 04:26:45 +0000148
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".
153 if (ValueLive)
154 PP.Diag(PeekTok, diag::warn_pp_undef_identifier) << II;
155 Result.Val = II->getTokenID() == tok::kw_true;
156 Result.Val.setIsUnsigned(false); // "0" is signed intmax_t 0.
157 Result.setRange(PeekTok.getLocation());
158 PP.LexNonComment(PeekTok);
159 return false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000160 }
Mike Stump1eb44332009-09-09 15:08:12 +0000161
Reid Spencer5f016e22007-07-11 17:01:13 +0000162 switch (PeekTok.getKind()) {
163 default: // Non-value token.
Chris Lattnerd98d9752008-04-13 20:38:43 +0000164 PP.Diag(PeekTok, diag::err_pp_expr_bad_token_start_expr);
Reid Spencer5f016e22007-07-11 17:01:13 +0000165 return true;
166 case tok::eom:
167 case tok::r_paren:
168 // If there is no expression, report and exit.
169 PP.Diag(PeekTok, diag::err_pp_expected_value_in_expr);
170 return true;
171 case tok::numeric_constant: {
172 llvm::SmallString<64> IntegerBuffer;
173 IntegerBuffer.resize(PeekTok.getLength());
174 const char *ThisTokBegin = &IntegerBuffer[0];
175 unsigned ActualLength = PP.getSpelling(PeekTok, ThisTokBegin);
Mike Stump1eb44332009-09-09 15:08:12 +0000176 NumericLiteralParser Literal(ThisTokBegin, ThisTokBegin+ActualLength,
Reid Spencer5f016e22007-07-11 17:01:13 +0000177 PeekTok.getLocation(), PP);
178 if (Literal.hadError)
179 return true; // a diagnostic was already reported.
Mike Stump1eb44332009-09-09 15:08:12 +0000180
Chris Lattner6e400c22007-08-26 03:29:23 +0000181 if (Literal.isFloatingLiteral() || Literal.isImaginary) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000182 PP.Diag(PeekTok, diag::err_pp_illegal_floating_literal);
183 return true;
184 }
185 assert(Literal.isIntegerLiteral() && "Unknown ppnumber");
186
Neil Boothb9449512007-08-29 22:00:19 +0000187 // long long is a C99 feature.
188 if (!PP.getLangOptions().C99 && !PP.getLangOptions().CPlusPlus0x
Neil Booth79859c32007-08-29 22:13:52 +0000189 && Literal.isLongLong)
Neil Boothb9449512007-08-29 22:00:19 +0000190 PP.Diag(PeekTok, diag::ext_longlong);
191
Reid Spencer5f016e22007-07-11 17:01:13 +0000192 // Parse the integer literal into Result.
Chris Lattner8ed30442008-05-05 06:45:50 +0000193 if (Literal.GetIntegerValue(Result.Val)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000194 // Overflow parsing integer literal.
195 if (ValueLive) PP.Diag(PeekTok, diag::warn_integer_too_large);
Chris Lattner8ed30442008-05-05 06:45:50 +0000196 Result.Val.setIsUnsigned(true);
Reid Spencer5f016e22007-07-11 17:01:13 +0000197 } else {
198 // Set the signedness of the result to match whether there was a U suffix
199 // or not.
Chris Lattner8ed30442008-05-05 06:45:50 +0000200 Result.Val.setIsUnsigned(Literal.isUnsigned);
Mike Stump1eb44332009-09-09 15:08:12 +0000201
Reid Spencer5f016e22007-07-11 17:01:13 +0000202 // Detect overflow based on whether the value is signed. If signed
203 // and if the value is too large, emit a warning "integer constant is so
204 // large that it is unsigned" e.g. on 12345678901234567890 where intmax_t
205 // is 64-bits.
Chris Lattner8ed30442008-05-05 06:45:50 +0000206 if (!Literal.isUnsigned && Result.Val.isNegative()) {
Chris Lattnerb081a352008-07-03 03:47:30 +0000207 // Don't warn for a hex literal: 0x8000..0 shouldn't warn.
208 if (ValueLive && Literal.getRadix() != 16)
Chris Lattner8ed30442008-05-05 06:45:50 +0000209 PP.Diag(PeekTok, diag::warn_integer_too_large_for_signed);
210 Result.Val.setIsUnsigned(true);
Reid Spencer5f016e22007-07-11 17:01:13 +0000211 }
212 }
Mike Stump1eb44332009-09-09 15:08:12 +0000213
Reid Spencer5f016e22007-07-11 17:01:13 +0000214 // Consume the token.
Chris Lattner8ed30442008-05-05 06:45:50 +0000215 Result.setRange(PeekTok.getLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +0000216 PP.LexNonComment(PeekTok);
217 return false;
218 }
219 case tok::char_constant: { // 'x'
220 llvm::SmallString<32> CharBuffer;
221 CharBuffer.resize(PeekTok.getLength());
222 const char *ThisTokBegin = &CharBuffer[0];
223 unsigned ActualLength = PP.getSpelling(PeekTok, ThisTokBegin);
Mike Stump1eb44332009-09-09 15:08:12 +0000224 CharLiteralParser Literal(ThisTokBegin, ThisTokBegin+ActualLength,
Reid Spencer5f016e22007-07-11 17:01:13 +0000225 PeekTok.getLocation(), PP);
226 if (Literal.hadError())
227 return true; // A diagnostic was already emitted.
228
229 // Character literals are always int or wchar_t, expand to intmax_t.
Daniel Dunbar444be732009-11-13 05:51:54 +0000230 const TargetInfo &TI = PP.getTargetInfo();
Eli Friedman2a1c3632009-06-01 05:25:02 +0000231 unsigned NumBits;
232 if (Literal.isMultiChar())
233 NumBits = TI.getIntWidth();
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000234 else if (Literal.isWide())
235 NumBits = TI.getWCharWidth();
Eli Friedman2a1c3632009-06-01 05:25:02 +0000236 else
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000237 NumBits = TI.getCharWidth();
Eli Friedman2a1c3632009-06-01 05:25:02 +0000238
Reid Spencer5f016e22007-07-11 17:01:13 +0000239 // Set the width.
240 llvm::APSInt Val(NumBits);
241 // Set the value.
242 Val = Literal.getValue();
243 // Set the signedness.
Eli Friedman15b91762009-06-05 07:05:05 +0000244 Val.setIsUnsigned(!PP.getLangOptions().CharIsSigned);
Mike Stump1eb44332009-09-09 15:08:12 +0000245
Chris Lattner8ed30442008-05-05 06:45:50 +0000246 if (Result.Val.getBitWidth() > Val.getBitWidth()) {
247 Result.Val = Val.extend(Result.Val.getBitWidth());
Reid Spencer5f016e22007-07-11 17:01:13 +0000248 } else {
Chris Lattner8ed30442008-05-05 06:45:50 +0000249 assert(Result.Val.getBitWidth() == Val.getBitWidth() &&
Reid Spencer5f016e22007-07-11 17:01:13 +0000250 "intmax_t smaller than char/wchar_t?");
Chris Lattner8ed30442008-05-05 06:45:50 +0000251 Result.Val = Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000252 }
253
254 // Consume the token.
Chris Lattner8ed30442008-05-05 06:45:50 +0000255 Result.setRange(PeekTok.getLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +0000256 PP.LexNonComment(PeekTok);
257 return false;
258 }
Chris Lattner8ed30442008-05-05 06:45:50 +0000259 case tok::l_paren: {
260 SourceLocation Start = PeekTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000261 PP.LexNonComment(PeekTok); // Eat the (.
262 // Parse the value and if there are any binary operators involved, parse
263 // them.
264 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
265
266 // If this is a silly value like (X), which doesn't need parens, check for
267 // !(defined X).
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000268 if (PeekTok.is(tok::r_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000269 // Just use DT unmodified as our result.
270 } else {
Chris Lattner8ed30442008-05-05 06:45:50 +0000271 // Otherwise, we have something like (x+y), and we consumed '(x'.
Reid Spencer5f016e22007-07-11 17:01:13 +0000272 if (EvaluateDirectiveSubExpr(Result, 1, PeekTok, ValueLive, PP))
273 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000274
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000275 if (PeekTok.isNot(tok::r_paren)) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000276 PP.Diag(PeekTok.getLocation(), diag::err_pp_expected_rparen)
277 << Result.getRange();
Chris Lattner28eb7e92008-11-23 23:17:07 +0000278 PP.Diag(Start, diag::note_matching) << "(";
Reid Spencer5f016e22007-07-11 17:01:13 +0000279 return true;
280 }
281 DT.State = DefinedTracker::Unknown;
282 }
Chris Lattner8ed30442008-05-05 06:45:50 +0000283 Result.setRange(Start, PeekTok.getLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +0000284 PP.LexNonComment(PeekTok); // Eat the ).
285 return false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000286 }
287 case tok::plus: {
288 SourceLocation Start = PeekTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000289 // Unary plus doesn't modify the value.
290 PP.LexNonComment(PeekTok);
Chris Lattner8ed30442008-05-05 06:45:50 +0000291 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
292 Result.setBegin(Start);
293 return false;
294 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000295 case tok::minus: {
296 SourceLocation Loc = PeekTok.getLocation();
297 PP.LexNonComment(PeekTok);
298 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
Chris Lattner8ed30442008-05-05 06:45:50 +0000299 Result.setBegin(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000300
Reid Spencer5f016e22007-07-11 17:01:13 +0000301 // C99 6.5.3.3p3: The sign of the result matches the sign of the operand.
Chris Lattner8ed30442008-05-05 06:45:50 +0000302 Result.Val = -Result.Val;
Mike Stump1eb44332009-09-09 15:08:12 +0000303
Chris Lattnerb081a352008-07-03 03:47:30 +0000304 // -MININT is the only thing that overflows. Unsigned never overflows.
305 bool Overflow = !Result.isUnsigned() && Result.Val.isMinSignedValue();
Mike Stump1eb44332009-09-09 15:08:12 +0000306
Reid Spencer5f016e22007-07-11 17:01:13 +0000307 // If this operator is live and overflowed, report the issue.
308 if (Overflow && ValueLive)
Chris Lattner204b2fe2008-11-18 21:48:13 +0000309 PP.Diag(Loc, diag::warn_pp_expr_overflow) << Result.getRange();
Mike Stump1eb44332009-09-09 15:08:12 +0000310
Reid Spencer5f016e22007-07-11 17:01:13 +0000311 DT.State = DefinedTracker::Unknown;
312 return false;
313 }
Mike Stump1eb44332009-09-09 15:08:12 +0000314
Chris Lattner8ed30442008-05-05 06:45:50 +0000315 case tok::tilde: {
316 SourceLocation Start = PeekTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000317 PP.LexNonComment(PeekTok);
318 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
Chris Lattner8ed30442008-05-05 06:45:50 +0000319 Result.setBegin(Start);
320
Reid Spencer5f016e22007-07-11 17:01:13 +0000321 // C99 6.5.3.3p4: The sign of the result matches the sign of the operand.
Chris Lattner8ed30442008-05-05 06:45:50 +0000322 Result.Val = ~Result.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000323 DT.State = DefinedTracker::Unknown;
324 return false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000325 }
Mike Stump1eb44332009-09-09 15:08:12 +0000326
Chris Lattner8ed30442008-05-05 06:45:50 +0000327 case tok::exclaim: {
328 SourceLocation Start = PeekTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000329 PP.LexNonComment(PeekTok);
330 if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true;
Chris Lattner8ed30442008-05-05 06:45:50 +0000331 Result.setBegin(Start);
332 Result.Val = !Result.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000333 // C99 6.5.3.3p5: The sign of the result is 'int', aka it is signed.
Chris Lattner8ed30442008-05-05 06:45:50 +0000334 Result.Val.setIsUnsigned(false);
Mike Stump1eb44332009-09-09 15:08:12 +0000335
Reid Spencer5f016e22007-07-11 17:01:13 +0000336 if (DT.State == DefinedTracker::DefinedMacro)
337 DT.State = DefinedTracker::NotDefinedMacro;
338 else if (DT.State == DefinedTracker::NotDefinedMacro)
339 DT.State = DefinedTracker::DefinedMacro;
340 return false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000341 }
Mike Stump1eb44332009-09-09 15:08:12 +0000342
Reid Spencer5f016e22007-07-11 17:01:13 +0000343 // FIXME: Handle #assert
344 }
345}
346
347
348
349/// getPrecedence - Return the precedence of the specified binary operator
350/// token. This returns:
351/// ~0 - Invalid token.
Chris Lattner9e66ba62008-05-05 04:10:51 +0000352/// 14 -> 3 - various operators.
353/// 0 - 'eom' or ')'
Reid Spencer5f016e22007-07-11 17:01:13 +0000354static unsigned getPrecedence(tok::TokenKind Kind) {
355 switch (Kind) {
356 default: return ~0U;
357 case tok::percent:
358 case tok::slash:
359 case tok::star: return 14;
360 case tok::plus:
361 case tok::minus: return 13;
362 case tok::lessless:
363 case tok::greatergreater: return 12;
364 case tok::lessequal:
365 case tok::less:
366 case tok::greaterequal:
367 case tok::greater: return 11;
368 case tok::exclaimequal:
369 case tok::equalequal: return 10;
370 case tok::amp: return 9;
371 case tok::caret: return 8;
372 case tok::pipe: return 7;
373 case tok::ampamp: return 6;
374 case tok::pipepipe: return 5;
Chris Lattner98ed49f2008-05-05 20:07:41 +0000375 case tok::question: return 4;
376 case tok::comma: return 3;
Chris Lattner91891562008-05-04 18:36:18 +0000377 case tok::colon: return 2;
Reid Spencer5f016e22007-07-11 17:01:13 +0000378 case tok::r_paren: return 0; // Lowest priority, end of expr.
379 case tok::eom: return 0; // Lowest priority, end of macro.
380 }
381}
382
383
384/// EvaluateDirectiveSubExpr - Evaluate the subexpression whose first token is
Chris Lattner8ed30442008-05-05 06:45:50 +0000385/// PeekTok, and whose precedence is PeekPrec. This returns the result in LHS.
Reid Spencer5f016e22007-07-11 17:01:13 +0000386///
387/// If ValueLive is false, then this value is being evaluated in a context where
388/// the result is not used. As such, avoid diagnostics that relate to
Chris Lattner8ed30442008-05-05 06:45:50 +0000389/// evaluation, such as division by zero warnings.
390static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec,
Chris Lattnerd2177732007-07-20 16:59:19 +0000391 Token &PeekTok, bool ValueLive,
Reid Spencer5f016e22007-07-11 17:01:13 +0000392 Preprocessor &PP) {
393 unsigned PeekPrec = getPrecedence(PeekTok.getKind());
394 // If this token isn't valid, report the error.
395 if (PeekPrec == ~0U) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000396 PP.Diag(PeekTok.getLocation(), diag::err_pp_expr_bad_token_binop)
397 << LHS.getRange();
Reid Spencer5f016e22007-07-11 17:01:13 +0000398 return true;
399 }
Mike Stump1eb44332009-09-09 15:08:12 +0000400
Reid Spencer5f016e22007-07-11 17:01:13 +0000401 while (1) {
402 // If this token has a lower precedence than we are allowed to parse, return
403 // it so that higher levels of the recursion can parse it.
404 if (PeekPrec < MinPrec)
405 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000406
Reid Spencer5f016e22007-07-11 17:01:13 +0000407 tok::TokenKind Operator = PeekTok.getKind();
Mike Stump1eb44332009-09-09 15:08:12 +0000408
Reid Spencer5f016e22007-07-11 17:01:13 +0000409 // If this is a short-circuiting operator, see if the RHS of the operator is
Mike Stump1eb44332009-09-09 15:08:12 +0000410 // dead. Note that this cannot just clobber ValueLive. Consider
Reid Spencer5f016e22007-07-11 17:01:13 +0000411 // "0 && 1 ? 4 : 1 / 0", which is parsed as "(0 && 1) ? 4 : (1 / 0)". In
412 // this example, the RHS of the && being dead does not make the rest of the
413 // expr dead.
414 bool RHSIsLive;
Chris Lattner8ed30442008-05-05 06:45:50 +0000415 if (Operator == tok::ampamp && LHS.Val == 0)
Reid Spencer5f016e22007-07-11 17:01:13 +0000416 RHSIsLive = false; // RHS of "0 && x" is dead.
Chris Lattner8ed30442008-05-05 06:45:50 +0000417 else if (Operator == tok::pipepipe && LHS.Val != 0)
Reid Spencer5f016e22007-07-11 17:01:13 +0000418 RHSIsLive = false; // RHS of "1 || x" is dead.
Chris Lattner8ed30442008-05-05 06:45:50 +0000419 else if (Operator == tok::question && LHS.Val == 0)
Reid Spencer5f016e22007-07-11 17:01:13 +0000420 RHSIsLive = false; // RHS (x) of "0 ? x : y" is dead.
421 else
422 RHSIsLive = ValueLive;
423
Chris Lattner8ed30442008-05-05 06:45:50 +0000424 // Consume the operator, remembering the operator's location for reporting.
425 SourceLocation OpLoc = PeekTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000426 PP.LexNonComment(PeekTok);
427
Chris Lattner8ed30442008-05-05 06:45:50 +0000428 PPValue RHS(LHS.getBitWidth());
Reid Spencer5f016e22007-07-11 17:01:13 +0000429 // Parse the RHS of the operator.
430 DefinedTracker DT;
431 if (EvaluateValue(RHS, PeekTok, DT, RHSIsLive, PP)) return true;
432
433 // Remember the precedence of this operator and get the precedence of the
434 // operator immediately to the right of the RHS.
435 unsigned ThisPrec = PeekPrec;
436 PeekPrec = getPrecedence(PeekTok.getKind());
437
438 // If this token isn't valid, report the error.
439 if (PeekPrec == ~0U) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000440 PP.Diag(PeekTok.getLocation(), diag::err_pp_expr_bad_token_binop)
441 << RHS.getRange();
Reid Spencer5f016e22007-07-11 17:01:13 +0000442 return true;
443 }
Mike Stump1eb44332009-09-09 15:08:12 +0000444
Chris Lattner98ed49f2008-05-05 20:07:41 +0000445 // Decide whether to include the next binop in this subexpression. For
446 // example, when parsing x+y*z and looking at '*', we want to recursively
Chris Lattner44cbbb02008-05-05 20:09:27 +0000447 // handle y*z as a single subexpression. We do this because the precedence
448 // of * is higher than that of +. The only strange case we have to handle
449 // here is for the ?: operator, where the precedence is actually lower than
450 // the LHS of the '?'. The grammar rule is:
Chris Lattner98ed49f2008-05-05 20:07:41 +0000451 //
452 // conditional-expression ::=
453 // logical-OR-expression ? expression : conditional-expression
454 // where 'expression' is actually comma-expression.
455 unsigned RHSPrec;
456 if (Operator == tok::question)
457 // The RHS of "?" should be maximally consumed as an expression.
458 RHSPrec = getPrecedence(tok::comma);
459 else // All others should munch while higher precedence.
460 RHSPrec = ThisPrec+1;
Mike Stump1eb44332009-09-09 15:08:12 +0000461
Chris Lattner98ed49f2008-05-05 20:07:41 +0000462 if (PeekPrec >= RHSPrec) {
463 if (EvaluateDirectiveSubExpr(RHS, RHSPrec, PeekTok, RHSIsLive, PP))
Reid Spencer5f016e22007-07-11 17:01:13 +0000464 return true;
465 PeekPrec = getPrecedence(PeekTok.getKind());
466 }
467 assert(PeekPrec <= ThisPrec && "Recursion didn't work!");
Mike Stump1eb44332009-09-09 15:08:12 +0000468
Reid Spencer5f016e22007-07-11 17:01:13 +0000469 // Usual arithmetic conversions (C99 6.3.1.8p1): result is unsigned if
Mike Stump1eb44332009-09-09 15:08:12 +0000470 // either operand is unsigned.
Reid Spencer5f016e22007-07-11 17:01:13 +0000471 llvm::APSInt Res(LHS.getBitWidth());
Chris Lattner019ef7e2008-05-04 23:46:17 +0000472 switch (Operator) {
473 case tok::question: // No UAC for x and y in "x ? y : z".
474 case tok::lessless: // Shift amount doesn't UAC with shift value.
475 case tok::greatergreater: // Shift amount doesn't UAC with shift value.
476 case tok::comma: // Comma operands are not subject to UACs.
477 case tok::pipepipe: // Logical || does not do UACs.
478 case tok::ampamp: // Logical && does not do UACs.
479 break; // No UAC
480 default:
Reid Spencer5f016e22007-07-11 17:01:13 +0000481 Res.setIsUnsigned(LHS.isUnsigned()|RHS.isUnsigned());
482 // If this just promoted something from signed to unsigned, and if the
483 // value was negative, warn about it.
484 if (ValueLive && Res.isUnsigned()) {
Chris Lattner8ed30442008-05-05 06:45:50 +0000485 if (!LHS.isUnsigned() && LHS.Val.isNegative())
Chris Lattner204b2fe2008-11-18 21:48:13 +0000486 PP.Diag(OpLoc, diag::warn_pp_convert_lhs_to_positive)
487 << LHS.Val.toString(10, true) + " to " +
488 LHS.Val.toString(10, false)
489 << LHS.getRange() << RHS.getRange();
Chris Lattner8ed30442008-05-05 06:45:50 +0000490 if (!RHS.isUnsigned() && RHS.Val.isNegative())
Chris Lattner204b2fe2008-11-18 21:48:13 +0000491 PP.Diag(OpLoc, diag::warn_pp_convert_rhs_to_positive)
492 << RHS.Val.toString(10, true) + " to " +
493 RHS.Val.toString(10, false)
494 << LHS.getRange() << RHS.getRange();
Reid Spencer5f016e22007-07-11 17:01:13 +0000495 }
Chris Lattner8ed30442008-05-05 06:45:50 +0000496 LHS.Val.setIsUnsigned(Res.isUnsigned());
497 RHS.Val.setIsUnsigned(Res.isUnsigned());
Reid Spencer5f016e22007-07-11 17:01:13 +0000498 }
Mike Stump1eb44332009-09-09 15:08:12 +0000499
Reid Spencer5f016e22007-07-11 17:01:13 +0000500 // FIXME: All of these should detect and report overflow??
501 bool Overflow = false;
502 switch (Operator) {
503 default: assert(0 && "Unknown operator token!");
504 case tok::percent:
Chris Lattner8ed30442008-05-05 06:45:50 +0000505 if (RHS.Val != 0)
506 Res = LHS.Val % RHS.Val;
507 else if (ValueLive) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000508 PP.Diag(OpLoc, diag::err_pp_remainder_by_zero)
509 << LHS.getRange() << RHS.getRange();
Chris Lattner8ed30442008-05-05 06:45:50 +0000510 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000511 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000512 break;
513 case tok::slash:
Chris Lattner8ed30442008-05-05 06:45:50 +0000514 if (RHS.Val != 0) {
515 Res = LHS.Val / RHS.Val;
516 if (LHS.Val.isSigned()) // MININT/-1 --> overflow.
517 Overflow = LHS.Val.isMinSignedValue() && RHS.Val.isAllOnesValue();
518 } else if (ValueLive) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000519 PP.Diag(OpLoc, diag::err_pp_division_by_zero)
520 << LHS.getRange() << RHS.getRange();
Chris Lattner8ed30442008-05-05 06:45:50 +0000521 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000522 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000523 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000524
Reid Spencer5f016e22007-07-11 17:01:13 +0000525 case tok::star:
Chris Lattner8ed30442008-05-05 06:45:50 +0000526 Res = LHS.Val * RHS.Val;
Eli Friedman3265a422009-05-16 21:24:10 +0000527 if (Res.isSigned() && LHS.Val != 0 && RHS.Val != 0)
Chris Lattner8ed30442008-05-05 06:45:50 +0000528 Overflow = Res/RHS.Val != LHS.Val || Res/LHS.Val != RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000529 break;
530 case tok::lessless: {
531 // Determine whether overflow is about to happen.
Chris Lattner8ed30442008-05-05 06:45:50 +0000532 unsigned ShAmt = static_cast<unsigned>(RHS.Val.getLimitedValue());
533 if (ShAmt >= LHS.Val.getBitWidth())
534 Overflow = true, ShAmt = LHS.Val.getBitWidth()-1;
Reid Spencer5f016e22007-07-11 17:01:13 +0000535 else if (LHS.isUnsigned())
Eli Friedman3265a422009-05-16 21:24:10 +0000536 Overflow = false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000537 else if (LHS.Val.isNonNegative()) // Don't allow sign change.
538 Overflow = ShAmt >= LHS.Val.countLeadingZeros();
Reid Spencer5f016e22007-07-11 17:01:13 +0000539 else
Chris Lattner8ed30442008-05-05 06:45:50 +0000540 Overflow = ShAmt >= LHS.Val.countLeadingOnes();
Mike Stump1eb44332009-09-09 15:08:12 +0000541
Chris Lattner8ed30442008-05-05 06:45:50 +0000542 Res = LHS.Val << ShAmt;
Reid Spencer5f016e22007-07-11 17:01:13 +0000543 break;
544 }
545 case tok::greatergreater: {
546 // Determine whether overflow is about to happen.
Chris Lattner8ed30442008-05-05 06:45:50 +0000547 unsigned ShAmt = static_cast<unsigned>(RHS.Val.getLimitedValue());
Reid Spencer5f016e22007-07-11 17:01:13 +0000548 if (ShAmt >= LHS.getBitWidth())
549 Overflow = true, ShAmt = LHS.getBitWidth()-1;
Chris Lattner8ed30442008-05-05 06:45:50 +0000550 Res = LHS.Val >> ShAmt;
Reid Spencer5f016e22007-07-11 17:01:13 +0000551 break;
552 }
553 case tok::plus:
Chris Lattner8ed30442008-05-05 06:45:50 +0000554 Res = LHS.Val + RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000555 if (LHS.isUnsigned())
Eli Friedman3265a422009-05-16 21:24:10 +0000556 Overflow = false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000557 else if (LHS.Val.isNonNegative() == RHS.Val.isNonNegative() &&
558 Res.isNonNegative() != LHS.Val.isNonNegative())
Reid Spencer5f016e22007-07-11 17:01:13 +0000559 Overflow = true; // Overflow for signed addition.
560 break;
561 case tok::minus:
Chris Lattner8ed30442008-05-05 06:45:50 +0000562 Res = LHS.Val - RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000563 if (LHS.isUnsigned())
Eli Friedman3265a422009-05-16 21:24:10 +0000564 Overflow = false;
Chris Lattner8ed30442008-05-05 06:45:50 +0000565 else if (LHS.Val.isNonNegative() != RHS.Val.isNonNegative() &&
566 Res.isNonNegative() != LHS.Val.isNonNegative())
Reid Spencer5f016e22007-07-11 17:01:13 +0000567 Overflow = true; // Overflow for signed subtraction.
568 break;
569 case tok::lessequal:
Chris Lattner8ed30442008-05-05 06:45:50 +0000570 Res = LHS.Val <= RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000571 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
572 break;
573 case tok::less:
Chris Lattner8ed30442008-05-05 06:45:50 +0000574 Res = LHS.Val < RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000575 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
576 break;
577 case tok::greaterequal:
Chris Lattner8ed30442008-05-05 06:45:50 +0000578 Res = LHS.Val >= RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000579 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
580 break;
581 case tok::greater:
Chris Lattner8ed30442008-05-05 06:45:50 +0000582 Res = LHS.Val > RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000583 Res.setIsUnsigned(false); // C99 6.5.8p6, result is always int (signed)
584 break;
585 case tok::exclaimequal:
Chris Lattner8ed30442008-05-05 06:45:50 +0000586 Res = LHS.Val != RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000587 Res.setIsUnsigned(false); // C99 6.5.9p3, result is always int (signed)
588 break;
589 case tok::equalequal:
Chris Lattner8ed30442008-05-05 06:45:50 +0000590 Res = LHS.Val == RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000591 Res.setIsUnsigned(false); // C99 6.5.9p3, result is always int (signed)
592 break;
593 case tok::amp:
Chris Lattner8ed30442008-05-05 06:45:50 +0000594 Res = LHS.Val & RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000595 break;
596 case tok::caret:
Chris Lattner8ed30442008-05-05 06:45:50 +0000597 Res = LHS.Val ^ RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000598 break;
599 case tok::pipe:
Chris Lattner8ed30442008-05-05 06:45:50 +0000600 Res = LHS.Val | RHS.Val;
Reid Spencer5f016e22007-07-11 17:01:13 +0000601 break;
602 case tok::ampamp:
Chris Lattner8ed30442008-05-05 06:45:50 +0000603 Res = (LHS.Val != 0 && RHS.Val != 0);
Reid Spencer5f016e22007-07-11 17:01:13 +0000604 Res.setIsUnsigned(false); // C99 6.5.13p3, result is always int (signed)
605 break;
606 case tok::pipepipe:
Chris Lattner8ed30442008-05-05 06:45:50 +0000607 Res = (LHS.Val != 0 || RHS.Val != 0);
Reid Spencer5f016e22007-07-11 17:01:13 +0000608 Res.setIsUnsigned(false); // C99 6.5.14p3, result is always int (signed)
609 break;
610 case tok::comma:
Chris Lattner91891562008-05-04 18:36:18 +0000611 // Comma is invalid in pp expressions in c89/c++ mode, but is valid in C99
612 // if not being evaluated.
613 if (!PP.getLangOptions().C99 || ValueLive)
Chris Lattner204b2fe2008-11-18 21:48:13 +0000614 PP.Diag(OpLoc, diag::ext_pp_comma_expr)
615 << LHS.getRange() << RHS.getRange();
Chris Lattner8ed30442008-05-05 06:45:50 +0000616 Res = RHS.Val; // LHS = LHS,RHS -> RHS.
Mike Stump1eb44332009-09-09 15:08:12 +0000617 break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000618 case tok::question: {
619 // Parse the : part of the expression.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000620 if (PeekTok.isNot(tok::colon)) {
Chris Lattner204b2fe2008-11-18 21:48:13 +0000621 PP.Diag(PeekTok.getLocation(), diag::err_expected_colon)
622 << LHS.getRange(), RHS.getRange();
Chris Lattner28eb7e92008-11-23 23:17:07 +0000623 PP.Diag(OpLoc, diag::note_matching) << "?";
Reid Spencer5f016e22007-07-11 17:01:13 +0000624 return true;
625 }
626 // Consume the :.
627 PP.LexNonComment(PeekTok);
628
629 // Evaluate the value after the :.
Chris Lattner8ed30442008-05-05 06:45:50 +0000630 bool AfterColonLive = ValueLive && LHS.Val == 0;
631 PPValue AfterColonVal(LHS.getBitWidth());
Reid Spencer5f016e22007-07-11 17:01:13 +0000632 DefinedTracker DT;
633 if (EvaluateValue(AfterColonVal, PeekTok, DT, AfterColonLive, PP))
634 return true;
635
Chris Lattner44cbbb02008-05-05 20:09:27 +0000636 // Parse anything after the : with the same precedence as ?. We allow
637 // things of equal precedence because ?: is right associative.
Chris Lattner98ed49f2008-05-05 20:07:41 +0000638 if (EvaluateDirectiveSubExpr(AfterColonVal, ThisPrec,
Reid Spencer5f016e22007-07-11 17:01:13 +0000639 PeekTok, AfterColonLive, PP))
640 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000641
Reid Spencer5f016e22007-07-11 17:01:13 +0000642 // Now that we have the condition, the LHS and the RHS of the :, evaluate.
Chris Lattner8ed30442008-05-05 06:45:50 +0000643 Res = LHS.Val != 0 ? RHS.Val : AfterColonVal.Val;
644 RHS.setEnd(AfterColonVal.getRange().getEnd());
Reid Spencer5f016e22007-07-11 17:01:13 +0000645
646 // Usual arithmetic conversions (C99 6.3.1.8p1): result is unsigned if
647 // either operand is unsigned.
648 Res.setIsUnsigned(RHS.isUnsigned() | AfterColonVal.isUnsigned());
Mike Stump1eb44332009-09-09 15:08:12 +0000649
Reid Spencer5f016e22007-07-11 17:01:13 +0000650 // Figure out the precedence of the token after the : part.
651 PeekPrec = getPrecedence(PeekTok.getKind());
652 break;
653 }
654 case tok::colon:
655 // Don't allow :'s to float around without being part of ?: exprs.
Chris Lattner204b2fe2008-11-18 21:48:13 +0000656 PP.Diag(OpLoc, diag::err_pp_colon_without_question)
657 << LHS.getRange() << RHS.getRange();
Reid Spencer5f016e22007-07-11 17:01:13 +0000658 return true;
659 }
660
661 // If this operator is live and overflowed, report the issue.
662 if (Overflow && ValueLive)
Chris Lattner204b2fe2008-11-18 21:48:13 +0000663 PP.Diag(OpLoc, diag::warn_pp_expr_overflow)
664 << LHS.getRange() << RHS.getRange();
Mike Stump1eb44332009-09-09 15:08:12 +0000665
Reid Spencer5f016e22007-07-11 17:01:13 +0000666 // Put the result back into 'LHS' for our next iteration.
Chris Lattner8ed30442008-05-05 06:45:50 +0000667 LHS.Val = Res;
668 LHS.setEnd(RHS.getRange().getEnd());
Reid Spencer5f016e22007-07-11 17:01:13 +0000669 }
Mike Stump1eb44332009-09-09 15:08:12 +0000670
Reid Spencer5f016e22007-07-11 17:01:13 +0000671 return false;
672}
673
674/// EvaluateDirectiveExpression - Evaluate an integer constant expression that
675/// may occur after a #if or #elif directive. If the expression is equivalent
676/// to "!defined(X)" return X in IfNDefMacro.
677bool Preprocessor::
678EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) {
679 // Peek ahead one token.
Chris Lattnerd2177732007-07-20 16:59:19 +0000680 Token Tok;
Reid Spencer5f016e22007-07-11 17:01:13 +0000681 Lex(Tok);
Mike Stump1eb44332009-09-09 15:08:12 +0000682
Reid Spencer5f016e22007-07-11 17:01:13 +0000683 // C99 6.10.1p3 - All expressions are evaluated as intmax_t or uintmax_t.
Chris Lattner98be4942008-03-05 18:54:05 +0000684 unsigned BitWidth = getTargetInfo().getIntMaxTWidth();
Mike Stump1eb44332009-09-09 15:08:12 +0000685
Chris Lattner8ed30442008-05-05 06:45:50 +0000686 PPValue ResVal(BitWidth);
Reid Spencer5f016e22007-07-11 17:01:13 +0000687 DefinedTracker DT;
688 if (EvaluateValue(ResVal, Tok, DT, true, *this)) {
689 // Parse error, skip the rest of the macro line.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000690 if (Tok.isNot(tok::eom))
Reid Spencer5f016e22007-07-11 17:01:13 +0000691 DiscardUntilEndOfDirective();
692 return false;
693 }
Mike Stump1eb44332009-09-09 15:08:12 +0000694
Reid Spencer5f016e22007-07-11 17:01:13 +0000695 // If we are at the end of the expression after just parsing a value, there
696 // must be no (unparenthesized) binary operators involved, so we can exit
697 // directly.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000698 if (Tok.is(tok::eom)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000699 // If the expression we parsed was of the form !defined(macro), return the
700 // macro in IfNDefMacro.
701 if (DT.State == DefinedTracker::NotDefinedMacro)
702 IfNDefMacro = DT.TheMacro;
Mike Stump1eb44332009-09-09 15:08:12 +0000703
Chris Lattner8ed30442008-05-05 06:45:50 +0000704 return ResVal.Val != 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000705 }
Mike Stump1eb44332009-09-09 15:08:12 +0000706
Reid Spencer5f016e22007-07-11 17:01:13 +0000707 // Otherwise, we must have a binary operator (e.g. "#if 1 < 2"), so parse the
708 // operator and the stuff after it.
Chris Lattner98ed49f2008-05-05 20:07:41 +0000709 if (EvaluateDirectiveSubExpr(ResVal, getPrecedence(tok::question),
710 Tok, true, *this)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000711 // Parse error, skip the rest of the macro line.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000712 if (Tok.isNot(tok::eom))
Reid Spencer5f016e22007-07-11 17:01:13 +0000713 DiscardUntilEndOfDirective();
714 return false;
715 }
Mike Stump1eb44332009-09-09 15:08:12 +0000716
Reid Spencer5f016e22007-07-11 17:01:13 +0000717 // If we aren't at the tok::eom token, something bad happened, like an extra
718 // ')' token.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000719 if (Tok.isNot(tok::eom)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000720 Diag(Tok, diag::err_pp_expected_eol);
721 DiscardUntilEndOfDirective();
722 }
Mike Stump1eb44332009-09-09 15:08:12 +0000723
Chris Lattner8ed30442008-05-05 06:45:50 +0000724 return ResVal.Val != 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000725}
726