Commit Graph

1397 Commits

Author SHA1 Message Date
Richard Smith 7b8c3c91f4 PR10359: Template declarations which define classes are not permitted to also contain declarators. Previously we would accept code like this:
template<typename T> struct S { } f() { return 0; }

This case now produces a missing ';' diagnostic, since that seems like a much more likely error than an attempt to declare a function or variable in addition to the class template.

Treat this 

llvm-svn: 135195
2011-07-14 21:35:26 +00:00
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
Chandler Carruth e2c09ebcaa Convert terminology in the Lexer from 'instantiate' and variants to
'expand'. Also update the public API it provides to the new term, and
propagate that update to the various clients.

No functionality changed.

llvm-svn: 135138
2011-07-14 08:20:40 +00:00
Douglas Gregor ad69e65a39 Add 'mutable' to the function declarator chunk, to be used when
parsing lambda expressions, from John Freeman!

llvm-svn: 135090
2011-07-13 21:47:47 +00:00
Chandler Carruth 904cb14225 Remove a no-op break after a return, and correct one of the most
confusing indentations I've seen recently... Just noticed these while
making a change elsewhere.

No functionality changed.

llvm-svn: 134685
2011-07-08 04:59:44 +00:00
Chandler Carruth c5c3b0a25b Minor style cleanup.
Original patch by John Freeman, some style tweaks by me.

llvm-svn: 134683
2011-07-08 04:28:55 +00:00
Argyrios Kyrtzidis 61c58f7f43 Move SourceManager::isAt[Start/End]OfMacroInstantiation functions to the Lexer, since they depend on it now.
llvm-svn: 134644
2011-07-07 21:54:45 +00:00
Argyrios Kyrtzidis 41fb2d95a3 Make the Preprocessor more memory efficient and improve macro instantiation diagnostics.
When a macro instantiation occurs, reserve a SLocEntry chunk with length the
full length of the macro definition source. Set the spelling location of this chunk
to point to the start of the macro definition and any tokens that are lexed directly
from the macro definition will get a location from this chunk with the appropriate offset.

For any tokens that come from argument expansion, '##' paste operator, etc. have their
instantiation location point at the appropriate place in the instantiated macro definition
(the argument identifier and the '##' token respectively).
This improves macro instantiation diagnostics:

Before:

t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
int y = M(/);
        ^~~~
t.c:5:11: note: instantiated from:
int y = M(/);
          ^

After:

t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
int y = M(/);
        ^~~~
t.c:3:20: note: instantiated from:
\#define M(op) (foo op 3);
                ~~~ ^  ~
t.c:5:11: note: instantiated from:
int y = M(/);
          ^

The memory savings for a candidate boost library that abuses the preprocessor are:

- 32% less SLocEntries (37M -> 25M)
- 30% reduction in PCH file size (900M -> 635M)
- 50% reduction in memory usage for the SLocEntry table (1.6G -> 800M)

llvm-svn: 134587
2011-07-07 03:40:34 +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
Chandler Carruth b4836ea7a8 Build up statistics about the work done for analysis based warnings.
Special detail is added for uninitialized variable analysis as this has
serious performance problems than need to be tracked.

Computing some of this data is expensive, for example walking the CFG to
determine its size. To avoid doing that unless the stats data is going
to be used, we thread a bit into the Sema object to track whether
detailed stats should be collected or not. This bit is used to avoid
computations whereever the computations are likely to be more expensive
than checking the state of the flag. Thus, counters are in some cases
unconditionally updated, but the more expensive (and less frequent)
aggregation steps are skipped.

With this patch, we're able to see that for 'gcc.c':
*** Analysis Based Warnings Stats:
232 functions analyzed (0 w/o CFGs).
  7151 CFG blocks built.
  30 average CFG blocks per function.
  1167 max CFG blocks per function.
163 functions analyzed for uninitialiazed variables
  640 variables analyzed.
  3 average variables per function.
  94 max variables per function.
  96409 block visits.
  591 average block visits per function.
  61546 max block visits per function.

And for the reduced testcase in PR10183:
*** Analysis Based Warnings Stats:
98 functions analyzed (0 w/o CFGs).
  8526 CFG blocks built.
  87 average CFG blocks per function.
  7277 max CFG blocks per function.
68 functions analyzed for uninitialiazed variables
  1359 variables analyzed.
  19 average variables per function.
  1196 max variables per function.
  2540494 block visits.
  37360 average block visits per function.
  2536495 max block visits per function.

That last number is the somewhat scary one that indicates the problem in
PR10183.

llvm-svn: 134494
2011-07-06 16:21:37 +00:00
John McCall cb432faf6d Properly protect colons when parsing a nested-name-specifier as part
of an enum specifier in dialects which permit fixed underlying types.
Fixes the rejects-valid part of PR10264.

llvm-svn: 134468
2011-07-06 05:58:41 +00:00
Douglas Gregor 6b9be0ffb3 Some documentation fixes for the parser, from John Freeman
llvm-svn: 134419
2011-07-05 17:13:11 +00:00
Douglas Gregor 9e66af44ad Clean up and refactor ParseFunctionDeclarator to reduce code
repetition and better reflect the actual grammar, from John Freeman!

llvm-svn: 134417
2011-07-05 16:44:18 +00:00
Chandler Carruth 3c147a7731 Start switching the AST stats printing to use llvm::errs() instead of
fprintf. There is more cleanup to be done to the AST stats printing...

llvm-svn: 134373
2011-07-04 05:32:14 +00:00
Argyrios Kyrtzidis 7192a3b841 [ARC] When casting from a pointer to an objective-c object with known ownership, if the
cast type has no ownership specified, implicitly "transfer" the ownership of the cast'ed type
to the cast type:

id x;
(NSString**)&x; // Casting as (__strong NSString**).

llvm-svn: 134275
2011-07-01 22:22:59 +00:00
Argyrios Kyrtzidis d8701b60f7 -Remove Sema::ActOnCastOfParenListExpr and move most of its functionality to
newly introduced Sema::BuildVectorLiteral.
-Make Sema::ActOnCastExpr handle a vector initializer both when the cast'ed expression
 is a ParenListExpr and when it is a ParenExpr.
-Ultimately make Sema::ActOnParenOrParenListExpr independent of what the cast type was.

llvm-svn: 134274
2011-07-01 22:22:54 +00:00
Argyrios Kyrtzidis 7451d1cd00 [ARC] When casting from a pointer to an objective-c object with known ownership, if the
cast type has no ownership specified, implicitly "transfer" the ownership of the cast'ed type
to the cast type:

id x;
static_cast<NSString**>(&x); // Casting as (__strong NSString**).

This currently only works for C++ named casts, C casts to follow.

llvm-svn: 134273
2011-07-01 22:22:50 +00:00
Argyrios Kyrtzidis 774506918c Introduce Declarator::ObjCCatchContext, this will result in correct error for 'auto' in obj-c catch.
llvm-svn: 134271
2011-07-01 22:22:40 +00:00
Richard Trieu 94942b32a3 For code such as:
int f(int x) {
  if (int foo = f(bar)) {}
  return 0;
}

Clang produces the following error messages:

paren_imbalance.cc:2:19: error: use of undeclared identifier 'bar'
  if (int foo = f(bar)) {}
                  ^
paren_imbalance.cc:2:26: error: expected ')'
  if (int foo = f(bar)) {}
                        ^
paren_imbalance.cc:2:6: note: to match this '('
  if (int foo = f(bar)) {}
     ^

The second error is incorrect.  This patch will stop Clang from producing an error on parenthesis imbalance during error recovery when there isn't one.

llvm-svn: 134258
2011-07-01 20:54:02 +00:00
Richard Smith cd1c055528 Fix AST representations of alias-declarations which define tag types. Inside classes, the tag types need to have an associated access specifier, and inside function definitions, they need to be included in the declarations of the DeclStmt. These issues manifested as assertions during template instantiation, and also in a WIP constexpr patch.
llvm-svn: 134250
2011-07-01 19:46:12 +00:00
Argyrios Kyrtzidis 3ff13579f9 Introduce Declarator::CXXNewContext and remove 'AutoAllowedInTypeName' parameter
from Sema::GetTypeForDeclarator. No functionality change.

llvm-svn: 133987
2011-06-28 03:01:23 +00:00
Douglas Gregor c15b0cfc1f When deciding how to parse "= something" as part of a member
declaration, determine whether the declaration will end up declaring a
function using semantic criteria (e.g., it will have function type)
rather than purely syntactic criteria (e.g., it has the form of a
function declarator). Fixes <rdar://problem/9670557>.

llvm-svn: 133854
2011-06-25 00:56:27 +00:00
Argyrios Kyrtzidis 3ea4adb841 Allow the fixit for missing ':' in the ?: ternary operator if it is pointing
at the start of a macro instantiation.

llvm-svn: 133801
2011-06-24 17:28:29 +00:00
Argyrios Kyrtzidis c0c5dd2651 Introduce DelayedCleanupPool useful for simplifying clean-up of certain resources that, while their
lifetime is well-known and restricted, cleaning them up manually is easy to miss and cause a leak.

Use it to plug the leaking of TemplateIdAnnotation objects. rdar://9634138.

llvm-svn: 133610
2011-06-22 06:09:49 +00:00
Francois Pichet e878cb6bd1 Handle decltype keyword in Parser::isDeclarationSpecifier.
Fixes PR10154. Found by parsing MFC 2010 code with clang.

llvm-svn: 133380
2011-06-19 08:02:06 +00:00
Benjamin Kramer 8a9cc4fe28 Remove dead variables.
llvm-svn: 133346
2011-06-18 10:34:07 +00:00
John McCall 0c07bee8bd Only accept __bridge_retain in system headers, as Doug suggested.
llvm-svn: 133300
2011-06-17 21:56:12 +00:00
John McCall 0c32925aa0 As a hopefully temporary workaround for a header mistake, treat
__bridge_retain as a synonym for __bridge_retained.

llvm-svn: 133295
2011-06-17 21:23:37 +00:00
John McCall 31168b077c Automatic Reference Counting.
Language-design credit goes to a lot of people, but I particularly want
to single out Blaine Garst and Patrick Beard for their contributions.

Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself,
in no particular order.

llvm-svn: 133103
2011-06-15 23:02:42 +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
David Majnemer bffdbd288a Correct the spelling of instantiation
llvm-svn: 132901
2011-06-13 04:29:15 +00:00
Richard Smith 4a4beec7b0 Don't assert on initialized typedef declarations in classes:
struct {
    typedef int A = 0;
  };

According to the C++11 standard, this is not ill-formed, but does not have any ascribed meaning. We can't reasonably accept it, so treat it as ill-formed.

Also switch C++ from an incorrect 'fields can only be initialized in constructors' diagnostic for this case to C's 'illegal initializer (only variables can be initialized)'

llvm-svn: 132890
2011-06-12 11:43:46 +00:00
Richard Smith 938f40b5aa Implement support for C++11 in-class initialization of non-static data members.
llvm-svn: 132878
2011-06-11 17:19:42 +00:00
Douglas Gregor 33823727c8 Implement Objective-C Related Result Type semantics.
Related result types apply Cocoa conventions to the type of message
sends and property accesses to Objective-C methods that are known to
always return objects whose type is the same as the type of the
receiving class (or a subclass thereof), such as +alloc and
-init. This tightens up static type safety for Objective-C, so that we
now diagnose mistakes like this:

t.m:4:10: warning: incompatible pointer types initializing 'NSSet *'
with an
      expression of type 'NSArray *' [-Wincompatible-pointer-types]
  NSSet *array = [[NSArray alloc] init];
         ^       ~~~~~~~~~~~~~~~~~~~~~~
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:72:1:
note: 
      instance method 'init' is assumed to return an instance of its
      receiver
      type ('NSArray *')
- (id)init;
^

It also means that we get decent type inference when writing code in
Objective-C++0x:

  auto array = [[NSMutableArray alloc] initWithObjects:@"one",  @"two",nil];
  //    ^ now infers NSMutableArray* rather than id

llvm-svn: 132868
2011-06-11 01:09:30 +00:00
Fariborz Jahanian c3bcde088f Restore 'atomic' as an attribute of objc
properties.

llvm-svn: 132866
2011-06-11 00:45:12 +00:00
Fariborz Jahanian 5d5cf1905c Remove 'atomic' as a property attribute keyword.
It is not a sanctioned keyword and is assumed as default.
// rdar://8790791

llvm-svn: 132753
2011-06-08 16:40:09 +00:00
Sebastian Redl 3da3489e49 Parse C++0x generalized initializers.
llvm-svn: 132662
2011-06-05 12:23:16 +00:00
Tanya Lattner 55808c1026 Add support for builtin astype:
__builtin_astype(): Used to reinterpreted as another data type of the same size using for both scalar and vector data types.
Added test case.

llvm-svn: 132612
2011-06-04 00:47:47 +00:00
Benjamin Kramer f546f411b0 Silence sign compare warning.
llvm-svn: 132146
2011-05-26 21:32:30 +00:00
Richard Trieu 61384cb8bd Add a fix-it and better error recovery for improperly nested namespaces. This will give a better error message for cases such as "namespace foo::bar::baz {}" and a suggested fix-it of "namespace foo { namespace bar { namespace baz {} } }"
llvm-svn: 132138
2011-05-26 20:11:09 +00:00
Francois Pichet 8f981d5964 Add support for Microsoft __if_exists, __if_not_exists extension at class scope.
Example:

typedef int TYPE;
class C {
  __if_exists(TYPE) {
     TYPE a;
  }
  __if_not_exists(TYPE) {
     this will never be parsed.
  }
};

llvm-svn: 132052
2011-05-25 10:19:49 +00:00
Alexis Hunt e852b100e2 Implement a new type node, UnaryTransformType, designed to represent a
type that turns one type into another. This is used as the basis to
implement __underlying_type properly - with TypeSourceInfo and proper
behavior in the face of templates.

llvm-svn: 132017
2011-05-24 22:41:36 +00:00
Alexis Hunt 61ae8d395e Implement explicit specialization of explicitly-defaulted constructors.
The general out-of-line case (including explicit instantiation mostly
works except that the definition is being lost somewhere between the AST
and CodeGen, so the definition is never emitted.

llvm-svn: 131933
2011-05-23 23:14:04 +00:00
Alexis Hunt 4a2570792c Implement __underlying_type for libc++.
llvm-svn: 131633
2011-05-19 05:37:45 +00:00
Alexis Hunt d9a5cc13cf Implement the __is_trivially_copyable type trait
llvm-svn: 131270
2011-05-13 00:31:07 +00:00
Alexis Hunt 5a7fa250ab Properly parse the 'default' and 'delete' keywords.
They are actually grammatically considered definitions and parsed
accordingly.

This fixes the outstanding bugs regarding defaulting functions after
their declarations.

We now really nicely diagnose the following construct (try it!)

int foo() = delete, bar;

Still todo: Defaulted functions other than default constructors
            Test cases (including for the above construct)

llvm-svn: 131228
2011-05-12 06:15:49 +00:00
Francois Pichet 3abc9b8b79 In Microsoft mode, allow pure specifier (=0) on inline functions declared at class scope.
This removes 2 errors when parsing MFC code with clang

Example:
class A {
    virtual void f() = 0 { }
}

llvm-svn: 131175
2011-05-11 02:14:46 +00:00
Alexis Hunt f479f1b7e4 Rename "hasTrivialConstructor" to "hasTrivialDefaultConstructor" and
modify the semantics slightly to accomodate default constructors (I
hope).

llvm-svn: 131087
2011-05-09 18:22:59 +00:00
Francois Pichet dcf88932a2 Don't fail at parsing __declspec(property(get=get_func_name)). Just skip everything inside property() for now while we wait for the BoostPro people to provide a complete patch.
llvm-svn: 131053
2011-05-07 19:04:49 +00:00