Commit Graph

167 Commits

Author SHA1 Message Date
Chandler Carruth a88a221855 Move the rest of the preprocessor terminology from 'instantiate' and
variants to 'expand'. This changed a couple of public APIs, including
one public type "MacroInstantiation" which is now "MacroExpansion". The
rest of the codebase was updated to reflect this, especially the
libclang code. Two of the C++ (and thus easily changed) libclang APIs
were updated as well because they pertained directly to the old
MacroInstantiation class.

No functionality changed.

llvm-svn: 135139
2011-07-14 08:20:46 +00:00
Douglas Gregor 53e191ed94 Properly implement the scope restriction on the NRVO for
throw-expressions, such that we don't consider the NRVO when the
non-volatile automatic object comes from outside the innermost try
scope (C++0x [class.copymove]p13). In C++98/03, our ASTs were
incorrect but it didn't matter because IR generation doesn't actually
apply the NRVO here. In C++0x, however, we were moving from an object
when in fact we should have copied from it. Fixes PR10142 /
<rdar://problem/9714312>.

llvm-svn: 134548
2011-07-06 22:04:06 +00:00
David Majnemer c6a998712d Remove the Fix-it for missing statement in switches
llvm-svn: 132994
2011-06-14 15:24:38 +00:00
David Majnemer 0ac67fa22f Improve the diagnostics generated for switch statements missing expressions
- Move the diagnostic to the case statement instead of at the end of the switch
- Add a fix-it hint as to how to fix the compilation error

llvm-svn: 132903
2011-06-13 05:50:12 +00:00
Francois Pichet a5b3fcbc02 Add support for _if_exists and __if_not_exists at namespace/global scope.
llvm-svn: 131050
2011-05-07 17:30:27 +00:00
Francois Pichet 4a7de3eb2c Add support for Microsoft __if_exists and __if_not_exists construct inside function definition.
Allow to include or exclude code depending on if a symbol exists or not. Just like a #ifdef but for C/C++ symbols.

More doc: http://msdn.microsoft.com/en-us/library/x7wy9xh3(v=VS.100).aspx

Support at class and namespace scopes will be added later.

llvm-svn: 131014
2011-05-06 20:48:22 +00:00
Francois Pichet bfaf477a99 SEH was crashing under -fms-extensions.
llvm-svn: 130377
2011-04-28 03:14:31 +00:00
John Wiegley 1c0675e155 Parsing/AST support for Structured Exception Handling
Patch authored by Sohail Somani.

Provide parsing and AST support for Windows structured exception handling.

llvm-svn: 130366
2011-04-28 01:08:34 +00:00
Douglas Gregor da6c89de48 Introduce a new parser annotation token for primary expressions. When
ClassifyName() builds a primary expression, generate one of these
annotation tokens rather than jumping into the parser.

llvm-svn: 130297
2011-04-27 06:18:01 +00:00
Douglas Gregor 9b2d706e05 Clean out some cruft I introduced when adding Sema::ClassifyName()
llvm-svn: 130295
2011-04-27 05:44:51 +00:00
Douglas Gregor 19b7acff10 Simplify the parser's handling of Sema::ClassifyName() for types, by
creating a type-annotation token rather than jumping into the
declaration parsing.

llvm-svn: 130293
2011-04-27 05:41:15 +00:00
Argyrios Kyrtzidis f7620e4d49 If a null statement was preceded by an empty macro keep its instantiation source location
in NullStmt.

llvm-svn: 130289
2011-04-27 05:04:02 +00:00
Douglas Gregor 8b02cd0bea Extend Sema::ClassifyName() to support C++, ironing out a few issues
in the classification of template names and using declarations. We now
properly typo-correct the leading identifiers in statements to types,
templates, values, etc. As an added bonus, this reduces the number of
lookups required for disambiguation.

llvm-svn: 130288
2011-04-27 04:48:22 +00:00
Douglas Gregor b90f5185b6 When Sema::ClassifyName() finds an invalid ivar reference, return an
invalid expression rather than the far-more-generic "error". Fixes a
mild regression in error recovery uncovered by the GCC testsuite.

llvm-svn: 130128
2011-04-25 15:05:41 +00:00
Douglas Gregor 0e7dde535d Implement a new identifier-classification scheme where Sema
performs name lookup for an identifier and resolves it to a
type/expression/template/etc. in the same step. This scheme is
intended to improve both performance (by reducing the number of
redundant name lookups for a given identifier token) and error
recovery (by giving Sema a chance to correct type names before the
parser has decided that the identifier isn't a type name). For
example, this allows us to properly typo-correct type names at the
beginning of a statement:

t.c:6:3: error: use of undeclared identifier 'integer'; did you mean
'Integer'?
  integer *i = 0;
  ^~~~~~~
  Integer
t.c:1:13: note: 'Integer' declared here
typedef int Integer;
            ^


Previously, we wouldn't give a Fix-It because the typo correction
occurred after the parser had checked whether "integer" was a type
name (via Sema::getTypeName(), which isn't allowed to typo-correct)
and therefore decided to parse "integer * i = 0" as an expression. By
typo-correcting earlier, we typo-correct to the type name Integer and
parse this as a declaration. 

Moreover, in this context, we can also typo-correct identifiers to
keywords, e.g.,

t.c:7:3: error: use of undeclared identifier 'vid'; did you mean
'void'?
  vid *p = i;
  ^~~
  void

and recover appropriately.

Note that this is very much a work-in-progress. The new
Sema::ClassifyName is only used for expression-or-declaration
disambiguation in C at the statement level. The next steps will be to
make this work for the same disambiguation in C++ (where
functional-style casts make some trouble), then push it
further into the parser to eliminate more redundant name lookups.

Fixes <rdar://problem/7963833> for C and starts us down the path of
<rdar://problem/8172000>.

llvm-svn: 130082
2011-04-24 05:37:28 +00:00
Richard Smith d4257d847e Fix gcc warning. Add parens to this assert, incidentally reassociating it, but the condition is the same either way.
llvm-svn: 129948
2011-04-21 22:48:40 +00:00
Richard Trieu 2c850c0980 Add a fixit suggest for missing case keywords inside a switch scope. For instance, in the following code, 'case ' will be suggested before the '1:'
switch (x) {
  1: return 0;
  default: return 1;
}

llvm-svn: 129943
2011-04-21 21:44:26 +00:00
Richard Smith 02e85f3bc5 Add support for C++0x's range-based for loops, as specified by the C++11 draft standard (N3291).
llvm-svn: 129541
2011-04-14 22:09:26 +00:00
John McCall 084e83dfe7 Insomniac refactoring: change how the parser allocates attributes so that
AttributeLists do not accumulate over the lifetime of parsing, but are
instead reused.  Also make the arguments array not require a separate
allocation, and make availability attributes store their stuff in
augmented memory, too.

llvm-svn: 128209
2011-03-24 11:26:52 +00:00
Douglas Gregor a0ff0c34a7 Make sure that we always pop a function's scope *before* we call
ActOnFinishFunctionBody/ActOnBlockStmtExpr. This way, we ensure that
we diagnose undefined labels before the jump-scope checker gets run,
since the jump-scope checker requires (as its invariant) that all of
the GotoStmts be wired up correctly.

Fixes PR9495.

llvm-svn: 127738
2011-03-16 17:05:57 +00:00
Douglas Gregor e9e27d95db Implement a hack intended to allow Clang to parse libstdc++ 4.5's
headers, which use C++0x generalized initializer lists. Per PR7069, it
appears that the only use is as the return type of a function, so this
commit enables this extension just in that narrow case. If it's enough
for libstdc++ 4.5, or if it can be trivially extended to work with
libstdc++ 4.5, we'll keep it. Otherwise, or if this breaks anything,
we'll revert and wait for the real feature.

llvm-svn: 127507
2011-03-11 23:10:44 +00:00
Abramo Bagnara 1c3af96724 Fixed LabelDecl source range and cleaned creation code.
llvm-svn: 127094
2011-03-05 18:21:20 +00:00
Chris Lattner 43e7f31f11 implement basic support for __label__. I wouldn't be shocked if there are
bugs from other clients that don't expect to see a LabelDecl in a DeclStmt,
but if so they should be easy to fix.

This implements most of PR3429 and rdar://8287027

llvm-svn: 125817
2011-02-18 02:08:43 +00:00
Chris Lattner ebb5c6c717 Switch labels over to using normal name lookup, instead of their
own weird little DenseMap.  Hey look, we now emit unused label
warnings deterministically, amazing.

llvm-svn: 125813
2011-02-18 01:27:55 +00:00
Douglas Gregor 230a7e60b1 Improve parser recovery in "for" statements, from Richard Smith!
llvm-svn: 125722
2011-02-17 03:38:46 +00:00
John McCall 0140bfeead Improve our parse recovery on 'case blah;' and 'default;'.
llvm-svn: 124025
2011-01-22 09:28:32 +00:00
Jeffrey Yasskin 8dfa5f1776 Fix warnings found by gcc-4.6, from -Wunused-but-set-variable and
-Wint-to-pointer-cast.

llvm-svn: 123719
2011-01-18 02:00:16 +00:00
Argyrios Kyrtzidis ee56962cc1 Convert "#pragma unused(...)" into tokens for the parser.
This allows us to cache a "#pragma unused" that occurs inside an inline C++ member function.
Fixes rdar://8829590&8770988.

llvm-svn: 123666
2011-01-17 18:58:44 +00:00
Argyrios Kyrtzidis bd9dfb2e29 Rename MaybeSkipFunctionBodyForCodeCompletion -> trySkippingFunctionBodyForCodeCompletion and check isCodeCompletionEnabled() before doing the call.
Suggestions by Chris.

llvm-svn: 122792
2011-01-04 00:27:27 +00:00
Argyrios Kyrtzidis d5756a609d When in code-completion, skip obj-c method bodies for speed up.
llvm-svn: 122781
2011-01-03 22:33:06 +00:00
Argyrios Kyrtzidis 76dbe8c800 Speed up code-completion by skipping function bodies.
When we are in code-completion mode, skip parsing of all function bodies except the one where the
code-completion point resides.

For big .cpp files like 'SemaExpr.cpp' the improvement makes a huge difference, in some cases cutting down
code-completion time -62% !

We don't get diagnostics for the bodies though, so modify the code-completion tests that check for errors.

See rdar://8814203.

llvm-svn: 122765
2011-01-03 19:44:02 +00:00
John McCall 53fa71476d Refactor how we collect attributes during parsing, and add slots for attributes
on array and function declarators.  This is pretty far from complete, and I'll
revisit it later if someone doesn't beat me to it.

llvm-svn: 122535
2010-12-24 02:08:15 +00:00
Douglas Gregor 0d0a965b62 Improve the diagnostic and recovery for missing colons after 'case'
and 'default' statements, including a Fix-It to add the colon:

test/Parser/switch-recovery.cpp:13:12: error: expected ':' after 'case'
    case 17 // expected-error{{expected ':' after 'case'}}
           ^
           :
test/Parser/switch-recovery.cpp:16:12: error: expected ':' after 'default'
    default // expected-error{{expected ':' after 'default'}}
           ^
           :

llvm-svn: 122522
2010-12-23 22:56:40 +00:00
John McCall 34376a68c4 Although we currently have explicit lvalue-to-rvalue conversions, they're
not actually frequently used, because ImpCastExprToType only creates a node
if the types differ.  So explicitly create an ICE in the lvalue-to-rvalue
conversion code in DefaultFunctionArrayLvalueConversion() as well as several
other new places, and consistently deal with the consequences throughout the
compiler.

In addition, introduce a new cast kind for loading an ObjCProperty l-value,
and make sure we emit those nodes whenever an ObjCProperty l-value appears
that's not on the LHS of an assignment operator.

This breaks a couple of rewriter tests, which I've x-failed until future
development occurs on the rewriter.

Ted Kremenek kindly contributed the analyzer workarounds in this patch.

llvm-svn: 120890
2010-12-04 03:47:34 +00:00
Abramo Bagnara e0acd859d0 Fixed source range for MS asm statement.
llvm-svn: 120724
2010-12-02 18:34:55 +00:00
Argyrios Kyrtzidis de2bdf637e Revert r119838 "Don't warn for empty 'if' body if there is a macro that expands to nothing"
and use a better and more general approach, where NullStmt has a flag to indicate whether it was preceded by an empty macro.

Thanks to Abramo Bagnara for the hint!

llvm-svn: 119887
2010-11-20 02:04:01 +00:00
Argyrios Kyrtzidis 90ee2a4ecf Don't warn for empty 'if' body if there is a macro that expands to nothing, e.g:
if (condition)
    CALL(0); // empty macro but don't warn for empty body.

Fixes rdar://8436021.

llvm-svn: 119838
2010-11-19 20:54:25 +00:00
Ted Kremenek 5eec2b0bd3 Region-allocate all AttributeList objects from a factory object instead of manually managing them
using new/delete and OwningPtrs.  After memory profiling Clang, I witnessed periodic leaks of these
objects; digging deeper into the code, it was clear that our management of these objects was a mess.  The ownership rules were murky at best, and not always followed.  Worse, there are plenty of error paths where we could screw up.

This patch introduces AttributeList::Factory, which is a factory class that creates AttributeList
objects and then blows them away all at once.  While conceptually simple, most of the changes in
this patch just have to do with migrating over to the new interface.  Most of the changes have resulted in some nice simplifications.

This new strategy currently holds on to all AttributeList objects during the lifetime of the Parser
object.  This is easily tunable.  If we desire to have more bound the lifetime of AttributeList
objects more precisely, we can have the AttributeList::Factory object (in Parser) push/pop its
underlying allocator as we enter/leave key methods in the Parser.  This means that we get
simple memory management while still having the ability to finely control memory use if necessary.

Note that because AttributeList objects are now BumpPtrAllocated, we may reduce malloc() traffic
in many large files with attributes.

This fixes the leak reported in: <rdar://problem/8650003>

llvm-svn: 118675
2010-11-10 05:59:39 +00:00
Argyrios Kyrtzidis 3050d9bdb8 Properly handle temporaries that are created in a AsmStmt.
Previously the temporaries would get destroyed before the asm call.

llvm-svn: 118001
2010-11-02 02:33:08 +00:00
Argyrios Kyrtzidis 375584c7eb Clean up temporaries created by an asm statement. Fixes rdar://8540491
llvm-svn: 117961
2010-11-01 21:51:42 +00:00
Fariborz Jahanian 1db5c941ad vla expressions used in __typeof__ must be evaluated.
Fixes rdar://8476159.

llvm-svn: 114982
2010-09-28 20:42:35 +00:00
Argyrios Kyrtzidis 9f48354b71 Don't warn for an unused label if it has 'unused' attribute. Fixes rdar://8483139.
llvm-svn: 114954
2010-09-28 14:54:07 +00:00
Douglas Gregor e9bba4f1a4 Implement bracket insertion for Objective-C instance message sends as
part of parser recovery. For example, given:

  a method1:arg];

we detect after parsing the expression "a" that we have the start of a
message send expression. We pretend we've seen a '[' prior to the a,
then parse the remainder as a message send. We'll then give a
diagnostic+fix-it such as:

fixit-objc-message.m:17:3: error: missing '[' at start of message
      send expression
  a method1:arg];
  ^
  [

The algorithm here is very simple, and always assumes that the open
bracket goes at the beginning of the message send. It also only works
for non-super instance message sends at this time.

llvm-svn: 113968
2010-09-15 14:51:05 +00:00
Douglas Gregor 45d6bdfa88 Improve recovery when there is a stray ']' or ')' before the ';' at
the end of a statement. Fixes <rdar://problem/6896493>.

llvm-svn: 113202
2010-09-07 15:23:11 +00:00
Chris Lattner 0073962025 when emitting an error about a missing } in a compound statement, emit
a "to match this {" note, pointing out the opener.

llvm-svn: 112709
2010-09-01 15:49:26 +00:00
Alexis Hunt 3b7918625c Revert my user-defined literal commits - r1124{58,60,67} pending
some issues being sorted out.

llvm-svn: 112493
2010-08-30 17:47:05 +00:00
Alexis Hunt 79eb5469e0 Implement C++0x user-defined string literals.
The extra data stored on user-defined literal Tokens is stored in extra
allocated memory, which is managed by the PreprocessorLexer because there isn't
a better place to put it that makes sure it gets deallocated, but only after
it's used up. My testing has shown no significant slowdown as a result, but
independent testing would be appreciated.

llvm-svn: 112458
2010-08-29 21:26:48 +00:00
John McCall faf5fb4b78 One who seeks knowledge learns something new every day.
One who seeks the Tao unlearns something new every day.
Less and less remains until you arrive at non-action.
When you arrive at non-action,
nothing will be left undone.

llvm-svn: 112244
2010-08-26 23:41:50 +00:00
John McCall dadc575b1e OwningExprResult -> ExprResult. This patch brought to you by
M-x query-replace-regexp
\(Sema::\|Action::\|Parser::\|\)Owning\(Expr\|Stmt\)Result -> \2Result

llvm-svn: 111903
2010-08-24 06:29:42 +00:00
John McCall b268a282a4 Kill off ExprArg (now just Expr*) and StmtArg (now just Stmt*).
llvm-svn: 111863
2010-08-23 23:25:46 +00:00