Commit Graph

6772 Commits

Author SHA1 Message Date
Douglas Gregor 7eeb59752a When AST merging for record declarations fails, warn about the
incompatibility and show where the structural differences are. For
example:

struct1.c:36:8: warning: type 'struct S7' has incompatible definitions
in different translation units
struct S7 { int i : 8; unsigned j : 8; } x7;
       ^
struct1.c:36:33: note: bit-field 'j' with type 'unsigned int' and length 8 here
struct S7 { int i : 8; unsigned j : 8; } x7;
                                ^
struct2.c:33:33: note: bit-field 'j' with type 'unsigned int' and length 16 here
struct S7 { int i : 8; unsigned j : 16; } x7;
                                ^

There are a few changes to make this work:
  - ASTImporter now has only a single Diagnostic object, not multiple
  diagnostic objects. Otherwise, having a warning/error printed via
  one Diagnostic and its note printed on the other Diagnostic could
  cause the note to be suppressed.
  - Implemented import functionality for IntegerLiteral (along with
  general support for statements and expressions)

llvm-svn: 95900
2010-02-11 19:21:55 +00:00
Eli Friedman f5d476efb2 Add builtins from PR5255. Implementations coming soon.
llvm-svn: 95894
2010-02-11 19:02:42 +00:00
Anders Carlsson 5bd8d19291 More vtable layout dumper improvements. Handle destructors, dump the complete function type of the member functions (using PredefinedExpr::ComputeName.
llvm-svn: 95887
2010-02-11 18:20:28 +00:00
Benjamin Kramer 15d8225b59 Remove noisy semicolon.
llvm-svn: 95872
2010-02-11 11:33:47 +00:00
Ted Kremenek d31b2637ab Patch by Cristian Draghici:
Enhance the printf format string checking when using the format
specifier flags ' ', '0', '+' with the 'p' or 's' conversions (since
they are nonsensical and undefined).  This is similar to GCC's
checking.

Also warning when a precision is used with the 'p' conversin
specifier, since it has no meaning.

llvm-svn: 95869
2010-02-11 09:27:41 +00:00
Anders Carlsson 5d40c6f658 Check in the beginnings of my new vtable layout builder idea.
Right now, it's off by default but can be tested by passing -fdump-vtable-layouts to clang -cc1. This option will cause all vtables that will normally be emitted as part of codegen to also be dumped using the new layout code.

I've also added a very simple new vtable layout test case.

llvm-svn: 95865
2010-02-11 08:02:13 +00:00
Ted Kremenek 510ee2594e Use the allocator associated with ASTContext to allocate the args
array associated with NonNullAttr.  This fixes yet another leak when
ASTContext uses a BumpPtrAllocator.

Fixes: <rdar://problem/7637150>
llvm-svn: 95863
2010-02-11 07:31:47 +00:00
Ted Kremenek da4e0d350c Have ~ASTContext() delete StoredDeclsMap (internal to DeclContext) by
storing the set of StoredDeclsMaps in an internal vector of void*.
This isn't an ideal solution, but for the time being this fixes a
major memory leak with these DenseMaps not being freed.

Fixes: <rdar://problem/7634755>
llvm-svn: 95861
2010-02-11 07:12:28 +00:00
Ted Kremenek 7f4945aa9c Remove use of 'std::string' from Attr objects, using instead a byte
array allocated using the allocator in ASTContext.  This addresses
these strings getting leaked when using a BumpPtrAllocator (in
ASTContext).

Fixes: <rdar://problem/7636765>
llvm-svn: 95853
2010-02-11 05:28:37 +00:00
Daniel Dunbar aeea8ac3d8 Driver: Add -rewrite-objc, which is an interface to clang -cc1 -rewrite-objc.
llvm-svn: 95849
2010-02-11 03:16:21 +00:00
Douglas Gregor 4a62bdfb2a Remove another redundant ASTContext parameter
llvm-svn: 95843
2010-02-11 01:30:34 +00:00
Douglas Gregor d505812422 Eliminate a bunch of unnecessary ASTContexts from members functions of
Decl subclasses. No functionality change.

llvm-svn: 95841
2010-02-11 01:19:42 +00:00
Fariborz Jahanian 13b9782cc0 Diagnose when user provided getter is being used as lvalue
using property dot-syntax. Fixes radar 7628953.

llvm-svn: 95838
2010-02-11 01:11:34 +00:00
Douglas Gregor 0a5a2216e2 Eliminate the ASTContext parameter from RecordDecl::getDefinition()
and CXXRecordDecl::getDefinition(); it's totally unnecessary. No
functionality change.

llvm-svn: 95836
2010-02-11 01:04:33 +00:00
Douglas Gregor 5c73e918c5 Implement basic AST merging for classes, structs, and unions in C.
llvm-svn: 95833
2010-02-11 00:48:18 +00:00
Charles Davis bbc0aa5166 Add support for the force_align_arg_pointer attribute. This is an x86-specific
attribute, so it uses Anton's new target-specific attribute support. It's
supposed to ensure that the stack is 16-byte aligned, but since necessary
support is lacking from LLVM, this is a no-op for now.

llvm-svn: 95820
2010-02-10 23:06:52 +00:00
Douglas Gregor bb7930c17e Implement basic support for merging function declarations across
translation units.

llvm-svn: 95794
2010-02-10 19:54:31 +00:00
Daniel Dunbar 3241d400c8 Switch to using -fsjlj-exceptions instead of hard-coding it. Notably, this fixes
calls to the UnwindResumeOrRethrow function for C++/Obj-C exception handling,
for Darwin ARM.

llvm-svn: 95787
2010-02-10 18:49:11 +00:00
Daniel Dunbar 925152c2d0 clang -cc1: Add -fsjlj-exceptions, which requires far too much button pushing.
llvm-svn: 95785
2010-02-10 18:48:44 +00:00
John McCall 5b0829a321 Improve access control diagnostics. Perform access control on member-pointer
conversions.  Fix an access-control bug where privileges were not considered
at intermediate points along the inheritance path.  Prepare for friends.

llvm-svn: 95775
2010-02-10 09:31:12 +00:00
Douglas Gregor 811663eb11 Implement basic support for importing source locations from one AST
into another AST, including their include history. Here's an example
error that involves a conflict merging a variable with different types
in two translation units (diagnosed in the third AST context into
which everything is merged).

/Volumes/Data/dgregor/Projects/llvm/tools/clang/test/ASTMerge/Inputs/var2.c:3:5:
error: external variable 'x2' declared with incompatible types in
different translation units ('int' vs. 'double')
int x2;
    ^
In file included from
/Volumes/Data/dgregor/Projects/llvm/tools/clang/test/ASTMerge/Inputs/var1.c:3:
/Volumes/Data/dgregor/Projects/llvm/tools/clang/test/ASTMerge/Inputs/var1.h:1:8:
note: declared here with type 'double'
double x2;
       ^

Although we maintain include history, we do not maintain macro
instantiation history across a merge. Instead, we map down to the
spelling location (for now!).

llvm-svn: 95732
2010-02-10 00:15:17 +00:00
Douglas Gregor e4c83e4e2e Complain about types and declarations that we don't know how to import.
llvm-svn: 95706
2010-02-09 22:48:33 +00:00
Douglas Gregor 639cccc4c0 Move the diagnostic argument formatting function out of Sema and make
it available within the AST library, of which Sema is one client. No
functionality change.

llvm-svn: 95701
2010-02-09 22:26:47 +00:00
Fariborz Jahanian 4587803919 Implement synthesizing properties by default.
This is a non-fragile-abi feature only. Since it
breaks existing code, it is currently placed under
-fobjc-nonfragile-abi2 option for test purposes only
until further notice. WIP.

llvm-svn: 95685
2010-02-09 19:31:38 +00:00
Douglas Gregor 62d311fdf4 Introduce a testbed for merging multiple ASTs into a single AST
context with the AST importer. WIP, still useless but at least it has
a test.

llvm-svn: 95683
2010-02-09 19:21:46 +00:00
Douglas Gregor 92354b6b55 Implement a specific diagnostic when a class template partial
specialization does not use any of its template parameters, then
recover far more gracefully. Fixes PR6181.

llvm-svn: 95629
2010-02-09 00:37:32 +00:00
Douglas Gregor 4b8fd6d3d3 Clean up the CIndex interface to diagnostic ranges. Thanks, Daniel!
llvm-svn: 95602
2010-02-08 23:11:56 +00:00
Douglas Gregor 408bb74ae6 Note that a CXIndex cannot be destroyed until after all of its translation units have been destroyed
llvm-svn: 95598
2010-02-08 23:03:06 +00:00
Douglas Gregor f85bee621b Eliminate a pointer of storage in each ObjCInterfaceType and
ObjCObjectPointerType AST node by allocating the list of protocols
after the type node itself. No functionality change.

llvm-svn: 95597
2010-02-08 22:59:26 +00:00
Douglas Gregor bd683973c1 Warn when cases are missing from a switch on a value of enumeration
type (-Wswitch), from Michal! 

llvm-svn: 95592
2010-02-08 22:24:16 +00:00
Douglas Gregor 586d0f926c Keep track of whether a tag was defined in a declarator vs. being
defined by itself, from Enea Zaffanella!

llvm-svn: 95586
2010-02-08 22:07:33 +00:00
Douglas Gregor 3aed6cdd5e Implement basic importing and merging of variable declarations within
the AST importer. This doesn't actually do anything (yet), because we
don't have driver logic for merging ASTs.

llvm-svn: 95570
2010-02-08 21:09:39 +00:00
Sebastian Redl b0e3e1bf67 When placing an annotation token over an existing annotation token, make sure that the new token's range extends to the end of the old token. Assert that in AnnotateCachedTokens. Fixes PR6248.
llvm-svn: 95555
2010-02-08 19:35:18 +00:00
Benjamin Kramer eaabbd8b46 Reapply r95546, no intended change in performance or functionality.
llvm-svn: 95552
2010-02-08 18:38:55 +00:00
Ted Kremenek ac5ab79555 Revert 95546 since it changed the algorithmic characteristics of the convention lookup.
llvm-svn: 95547
2010-02-08 16:45:01 +00:00
Benjamin Kramer 30949dd9f9 Simplify code with StringRef.
3 files changed, 76 insertions(+), 153 deletions(-)

llvm-svn: 95546
2010-02-08 16:39:00 +00:00
Ted Kremenek 57f0989c16 Revert 95541.
llvm-svn: 95545
2010-02-08 16:18:51 +00:00
Douglas Gregor f65bbb31e8 Cache imported types
llvm-svn: 95543
2010-02-08 15:18:58 +00:00
Zhongxing Xu 500f49fe25 Rename: GRState::getSVal(Stmt*) => getExprVal(),
GRState::getSVal(MemRegion*) => Load().

llvm-svn: 95541
2010-02-08 09:30:02 +00:00
Zhongxing Xu b02d4a0d11 Unify the implementation of getLValueElement of store managers.
It's more sophisticated than the original one of BasicStore. But it does
matter. 

llvm-svn: 95536
2010-02-08 08:17:02 +00:00
Zhongxing Xu f7f0cdc517 Unify the implementation of getLValueIvar and getLValueField of store managers.
llvm-svn: 95535
2010-02-08 07:58:06 +00:00
Zhongxing Xu 08515a5242 Move common methods to the base StoreManager class.
llvm-svn: 95534
2010-02-08 07:10:35 +00:00
Zhongxing Xu 8ffee4d5f8 ASTContext is now a reference member of StoreManager.
llvm-svn: 95531
2010-02-08 06:00:22 +00:00
Sam Weinig e83b3aca0b Roll r95513 back in.
llvm-svn: 95515
2010-02-07 06:32:43 +00:00
Sam Weinig e911058bb5 Roll out r95513, it seems to have broken self hosting.
llvm-svn: 95514
2010-02-07 05:26:25 +00:00
Sam Weinig db3758c40d Add PCH support for CXXBoolLiteralExpr and CXXNullPtrLiteralExpr.
llvm-svn: 95513
2010-02-07 04:44:10 +00:00
Anders Carlsson a7bcade229 Add attributes to namespace decls.
llvm-svn: 95510
2010-02-07 01:09:23 +00:00
Anders Carlsson fcd764a168 Add support for threadsafe statics, and make them the default (matching gcc).
Daniel, I'd appreciate a review of the driver/cc1 parts.

llvm-svn: 95508
2010-02-06 23:23:06 +00:00
Anders Carlsson 0da714a3e2 Implement a warning diagnostic for weak vtables. Fixes PR6116.
llvm-svn: 95472
2010-02-06 02:27:10 +00:00
John McCall ab26cfa58d Standardize the parsing of function type attributes in a way that
follows (as conservatively as possible) gcc's current behavior:  attributes
written on return types that don't apply there are applied to the function
instead, etc.  Only parse CC attributes as type attributes, not as decl attributes;
don't accepet noreturn as a decl attribute on ValueDecls, either (it still
needs to apply to other decls, like blocks).  Consistently consume CC/noreturn
information throughout codegen;  enforce this by removing their default values
in CodeGenTypes::getFunctionInfo().

llvm-svn: 95436
2010-02-05 21:31:56 +00:00
Douglas Gregor c90dedbda0 Oops, thanks Clang
llvm-svn: 95429
2010-02-05 21:07:53 +00:00
Douglas Gregor 96e578d29d Initial skeleton of an AST "importer", which will take AST elements from
one context and import them into another context, merging them
according to language-specific rules. This is a skeleton. It doesn't
work, it isn't testable, but I want it in version control.

llvm-svn: 95395
2010-02-05 17:54:41 +00:00
Fariborz Jahanian a7e1dcdc0e Some clean up of replacement text API no longer needed by
my recent changes.

llvm-svn: 95391
2010-02-05 16:43:40 +00:00
Chandler Carruth bc50da6360 Revert the unused TST_pixel entry from r95335 as it is not listed in the Sema
switch, triggering warnings.

llvm-svn: 95381
2010-02-05 07:38:55 +00:00
Zhongxing Xu ad0ef84040 More GRState* -> Store changes.
llvm-svn: 95365
2010-02-05 05:34:29 +00:00
Zhongxing Xu 0d081f373a Remove unused parameter.
llvm-svn: 95364
2010-02-05 05:24:20 +00:00
Zhongxing Xu f668204a6a More GRState* -> Store changes.
llvm-svn: 95362
2010-02-05 05:18:47 +00:00
Zhongxing Xu 7fcd8acbf8 More GRState* -> Store changes.
llvm-svn: 95360
2010-02-05 05:06:13 +00:00
Zhongxing Xu c7b9f950d7 More GRState* -> Store changes.
llvm-svn: 95357
2010-02-05 03:01:53 +00:00
Zhongxing Xu bd96bf1e78 Change LazyCompoundVal to a <Store, MemRegion*> pair. We really don't need to
spread GRState* everywhere.

llvm-svn: 95354
2010-02-05 02:26:30 +00:00
Ted Kremenek 2f2692f8ca Rename -cc1 option '-checker-cfref' to '-analyzer-check-objc-mem'.
llvm-svn: 95348
2010-02-05 02:06:54 +00:00
Ted Kremenek b6e400c87c Rename -cc1 option '-warn-objc-missing-dealloc' to '-analyzer-check-objc-missing-dealloc'.
llvm-svn: 95347
2010-02-05 01:59:21 +00:00
Ted Kremenek 61b506aa8f Rename -cc1 option '-warn-objc-methodsigs' to '-analyzer-check-objc-methodsigs'.
llvm-svn: 95346
2010-02-05 01:57:44 +00:00
Ted Kremenek 2d8ef71ae6 Rename -cc1 option '-warn-objc-unused-ivars' to '-analyzer-check-objc-unused-ivars'.
llvm-svn: 95345
2010-02-05 01:55:01 +00:00
Ted Kremenek d519b83757 Rename -cc1 option '-warn-dead-stores' to '-analyzer-check-dead-stores'.
llvm-svn: 95343
2010-02-05 01:52:40 +00:00
Ted Kremenek ec5b3d45c1 Rename -cc1 option '-warn-security-syntactic' to '-analyzer-check-security-syntactic'.
llvm-svn: 95342
2010-02-05 01:50:36 +00:00
John Thompson 2233460de6 First stage of adding AltiVec support
llvm-svn: 95335
2010-02-05 00:12:22 +00:00
John McCall 67da35c832 Extract a common structure for holding information about the definition
of a C++ record.  Exposed a lot of problems where various routines were
silently doing The Wrong Thing (or The Acceptable Thing in The Wrong Order)
when presented with a non-definition.  Also cuts down on memory usage.

llvm-svn: 95330
2010-02-04 22:26:26 +00:00
Ted Kremenek 1de1707bfc Move ParseFormatString() and FormatStringHandler back into the analyze_printf namespace.
llvm-svn: 95324
2010-02-04 20:46:58 +00:00
Ted Kremenek a0032da389 Convert flags in FormatSpecifier to be bitfields instead of doing
direct bit manipulation.  This is is less error prone, and fixes a bug
in the handling of the LeadingZeroes flag as pointed out by Cristian
Draghici.

llvm-svn: 95298
2010-02-04 07:27:39 +00:00
John McCall cddbad000d Allow calling convention attributes to apply to types. Patch by Chip Davis!
llvm-svn: 95291
2010-02-04 05:44:44 +00:00
Zhongxing Xu 319deb83d2 Cast evaluation no longer touch GRState.
llvm-svn: 95290
2010-02-04 04:56:43 +00:00
John McCall d061b4429e Mangle member expressions. Also invented.
llvm-svn: 95284
2010-02-04 02:56:29 +00:00
Zhongxing Xu 4f8b9899bb Now that CastRetrievedVal returns SVal, there is no need to use CastResult.
llvm-svn: 95279
2010-02-04 02:39:47 +00:00
John McCall 09de8ecd88 Add mangling support for calls, sizeof/alignof, constructor calls,
float literals, and unresolved lookups (which required hand-wavey extensions).

llvm-svn: 95273
2010-02-04 01:42:13 +00:00
Sebastian Redl 2b37272c11 In some contexts, type declarations cannot occur. Pass this information down to ParseClassSpecifier, to make its decision easier. Fixes PR6200.
llvm-svn: 95255
2010-02-03 21:21:43 +00:00
Daniel Dunbar 45858d2d59 Revert "Numerous changes to selector handling:", this breaks a whole bunch of
working code, for no apparent reason.

llvm-svn: 95244
2010-02-03 20:11:42 +00:00
Douglas Gregor 7dc5c17d92 When a function or variable somehow depends on a type or declaration
that is in an anonymous namespace, give that function or variable
internal linkage.

This change models an oddity of the C++ standard, where names declared
in an anonymous namespace have external linkage but, because anonymous
namespace are really "uniquely-named" namespaces, the names cannot be
referenced from other translation units. That means that they have
external linkage for semantic analysis, but the only sensible
implementation for code generation is to give them internal
linkage. We now model this notion via the UniqueExternalLinkage
linkage type. There are several changes here:

  - Extended NamedDecl::getLinkage() to produce UniqueExternalLinkage
    when the declaration is in an anonymous namespace.
  - Added Type::getLinkage() to determine the linkage of a type, which
    is defined as the minimum linkage of the types (when we're dealing
    with a compound type that is not a struct/class/union).
  - Extended NamedDecl::getLinkage() to consider the linkage of the
    template arguments and template parameters of function template
    specializations and class template specializations.
  - Taught code generation to rely on NamedDecl::getLinkage() when
    determining the linkage of variables and functions, also
    considering the linkage of the types of those variables and
    functions (C++ only). Map UniqueExternalLinkage to internal
    linkage, taking out the explicit checks for
    isInAnonymousNamespace().

This fixes much of PR5792, which, as discovered by Anders Carlsson, is
actually the reason behind the pass-manager assertion that causes the
majority of clang-on-clang regression test failures. With this fix,
Clang-built-Clang+LLVM passes 88% of its regression tests (up from
67%). The specific numbers are:

LLVM:
  Expected Passes    : 4006
  Expected Failures  : 32
  Unsupported Tests  : 40
  Unexpected Failures: 736

Clang:
  Expected Passes    : 1903
  Expected Failures  : 14
  Unexpected Failures: 75

Overall:
  Expected Passes    : 5909
  Expected Failures  : 46
  Unsupported Tests  : 40
  Unexpected Failures: 811

Still to do:
  - Improve testing
  - Check whether we should allow the presence of types with
  InternalLinkage (in addition to UniqueExternalLinkage) given
  variables/functions internal linkage in C++, as mentioned in
  PR5792. 
  - Determine how expensive the getLinkage() calls are in practice;
  consider caching the result in NamedDecl.
  - Assess the feasibility of Chris's idea in comment #1 of PR5792.

llvm-svn: 95216
2010-02-03 09:33:45 +00:00
Zhongxing Xu 5df3f53616 Add skeleton of flat store manager.
llvm-svn: 95214
2010-02-03 09:10:32 +00:00
Sam Weinig a16b0dd1ae Implement Doug's suggestion. Eliminate the Stmts pointer from CXXTryStmt and instead allocate the statements after the object.
llvm-svn: 95199
2010-02-03 03:56:39 +00:00
Daniel Dunbar c434394d18 Driver: Add -[no-]integrated-as for clang.
- Requires backend support, which only exists for i386--darwin currently.

No 'as' required:
--
ddunbar@ozzy:tmp$ cat t.c
int main() { return 42; }
ddunbar@ozzy:tmp$ clang -m32 -integrated-as t.c


ddunbar@ozzy:tmp$ ./a.out; echo $?
42
ddunbar@ozzy:tmp$
--

The random extra whitespace is how you know its working! :)

llvm-svn: 95194
2010-02-03 03:07:56 +00:00
Sam Weinig ebcea988c2 Remove the SmallVector from CXXTryStmt.
llvm-svn: 95190
2010-02-03 02:09:59 +00:00
David Chisnall 92b762e256 Numerous changes to selector handling:
- Don't use GlobalAliases with non-0 GEPs (GNU runtime) - this was unsupported and LLVM will be generating errors if you do it soon.  This also simplifies the code generated by the GNU runtime a bit.  

- Make GetSelector() return a constant (GNU runtime), not a load of a store of a constant.

- Recognise @selector() expressions as valid static initialisers (as GCC does).

- Add methods to GCObjCRuntime to emit selectors as constants (needed for using @selector() expressions as constants.  These need implementing for the Mac runtimes - I couldn't figure out how to do this, they seem to require a load.

- Store an ObjCMethodDecl in an ObjCSelectorExpr so that we can get at the type information for the selector.  This is needed for generating typed selectors from @selector() expressions (as GCC does).  Ideally, this information should be stored in the Selector, but that would be an invasive change.  We should eventually add checks for common uses of @selector() expressions.  Possibly adding an attribute that can be applied to method args providing the types of a selector so, for example, you'd do something like this:

- (id)performSelector: __attribute__((selector_types(id, SEL, id)))(SEL)
           withObject: (id)object;

Then, any @selector() expressions passed to the method will be check to ensure that it conforms to this signature.  We do this at run time on the GNU runtime already, but it would be nice to do it at compile time on all runtimes.

- Made @selector() expressions emit type info if available and the runtime supports it.

Someone more familiar with the Mac runtime needs to implement the GetConstantSelector() function in CGObjCMac.  This currently just assert()s.

llvm-svn: 95189
2010-02-03 02:09:30 +00:00
Daniel Dunbar 92db0fbe5a clang -cc1: Wire up -emit-obj, for emitting object files.
llvm-svn: 95182
2010-02-03 01:18:43 +00:00
John McCall 2adddcae7e Remove abstract expression kinds from the StmtClass enum. Update a few users
appropriately.  Call out a few missing cases in the expression mangler.

llvm-svn: 95176
2010-02-03 00:55:45 +00:00
Fariborz Jahanian 08d614d92e Fix DeclContext of an objective-c @catch variable
declaration. Fixes radar 7590273.

llvm-svn: 95164
2010-02-03 00:01:43 +00:00
Daniel Dunbar ffa70e8b27 Driver/Darwin: Don't error/warn on conflicting deployment targets. Apparently
this is still a popular thing to do.

llvm-svn: 95093
2010-02-02 17:31:12 +00:00
John McCall 1acbbb5a4c Extract a common base class between UnresolvedLookupExpr and
UnresolvedMemberExpr and employ it in a few places where it's useful.

llvm-svn: 95072
2010-02-02 06:20:04 +00:00
Chris Lattner 0b8ecb511c this is reasonably complete by now.
llvm-svn: 95069
2010-02-02 05:23:01 +00:00
John McCall fb7ad0f57a Improve the diagnostic used when an incompatible overload set is passed
as an argument during overload resolution.

llvm-svn: 95057
2010-02-02 02:42:52 +00:00
Chris Lattner cf25141d14 Implement PR6180, substantially improving the diagnostics we get from
forgetting a ';' at the end of a struct.  For something like:

class c {
}
void foo() {}

we now produce:

t.cc:3:2: error: expected ';' after class
}
 ^
 ;

instead of:

t.cc:4:1: error: cannot combine with previous 'class' declaration specifier
void foo() {}
^
t.cc:2:7: error: 'class c' can not be defined in the result type of a function
class c {
      ^

GCC produces:

t.cc:4: error: new types may not be defined in a return type
t.cc:4: note: (perhaps a semicolon is missing after the definition of ‘c’)
t.cc:4: error: two or more data types in declaration of ‘foo’

I *think* I got the follow set right, but if I forgot anything, we'll start 
getting spurious "expected ';' after class" errors, let me know if you see
any.

llvm-svn: 95042
2010-02-02 01:23:29 +00:00
Douglas Gregor 6791a0d43b Improve handling of enumerator values for C and C++, including:
- In C++, prior to the closing '}', set the type of enumerators
    based on the type of their initializer. Don't perform unary
    conversions on the enumerator values.
  - In C++, handle overflow when an enumerator has no initializer and
    its value cannot be represented in the type of the previous
    enumerator.
  - In C, handle overflow more gracefully, by complaining and then
    falling back to the C++ rules.
  - In C, if the enumerator value is representable in an int, convert the
    expression to the type 'int'.

Fixes PR5854 and PR4515.

llvm-svn: 95031
2010-02-01 23:36:03 +00:00
Daniel Dunbar 98188414ef Driver/Darwin: Darwin uses -fobjc-legacy-dispatch on ARM.
llvm-svn: 95006
2010-02-01 21:07:43 +00:00
Daniel Dunbar 2e3f2c805e Driver/Frontend: Add support for -fobjc-legacy-dispatch, not yet used.
llvm-svn: 95004
2010-02-01 21:07:25 +00:00
Chris Lattner 5b5d2db3f6 Don't explicitly force utf strings into the __TEXT,__ustring
by setting the section of the generated global.  This is an
optimization done by the code generator, and the code being
removed didn't handle the case when the string contained an
embedded nul (which the code generator does correctly 
handle).  This is rdar://7589850

llvm-svn: 95003
2010-02-01 20:59:08 +00:00
Sebastian Redl 5ca7984bb4 In C++, an initializer on a variable doesn't necessarily mean it's the definition. With that in mind, rename getDefinition to getAnyInitializer (to distinguish it from getInit) and reimplement it in terms of isThisDeclarationADefinition. Update all code to use this new function.
llvm-svn: 94999
2010-02-01 20:16:42 +00:00
John McCall 8b9ed55bfb Note that an overload candidate was non-viable because template argument
deduction failed.  Right now there's a very vague diagnostic for most cases
and a good diagnostic for incomplete deduction.

llvm-svn: 94988
2010-02-01 18:53:26 +00:00
Sam Weinig deb55d5123 Fix for PR5185. C99 [*] VLA notation should be disallowed in function definitions.
llvm-svn: 94972
2010-02-01 05:02:49 +00:00
John McCall 760af170ff Access checking for implicit user-defined conversions.
llvm-svn: 94971
2010-02-01 03:16:54 +00:00
Sebastian Redl 35351a9554 Add VarDecl::isThisDeclarationADefinition(), which properly encapsulates the logic for when a variable declaration is a (possibly tentativ) definition. Add a few functions building on this, and shift C tentative definition handling over to this new functionality. This shift also kills the Sema::TentativeDefinitions map and instead simply stores all declarations in the renamed list. The correct handling for multiple tentative definitions is instead shifted to the final walk of the list.
llvm-svn: 94968
2010-01-31 22:27:38 +00:00
Anders Carlsson 8abde4b447 Diagnose binding a non-const reference to a vector element.
llvm-svn: 94963
2010-01-31 17:18:49 +00:00
Chandler Carruth 724a8a1fef Fix PR6159 and several other problems with value-dependent non-type template
arguments. This both prevents meaningless checks on these arguments and ensures
that they are represented as an expression by the instantiation.

Cleaned up and added standard text to the relevant test case. Also started
adding tests for *rejected* cases. At least one FIXME here where (I think) we
allow something we shouldn't. More to come in the area of rejecting crazy
arguments with decent diagnostics. Suggestions welcome for still better
diagnostics on these errors!

llvm-svn: 94953
2010-01-31 10:01:20 +00:00
Douglas Gregor 7ae2d7758f Rework base and member initialization in constructors, with several
(necessarily simultaneous) changes:

  - CXXBaseOrMemberInitializer now contains only a single initializer
    rather than a set of initialiation arguments + a constructor. The
    single initializer covers all aspects of initialization, including
    constructor calls as necessary but also cleanup of temporaries
    created by the initializer (which we never handled
    before!).

  - Rework + simplify code generation for CXXBaseOrMemberInitializers,
    since we can now just emit the initializer as an initializer.

  - Switched base and member initialization over to the new
    initialization code (InitializationSequence), so that it

  - Improved diagnostics for the new initialization code when
    initializing bases and members, to match the diagnostics produced
    by the previous (special-purpose) code.

  - Simplify the representation of type-checked constructor initializers in
    templates; instead of keeping the fully-type-checked AST, which is
    rather hard to undo at template instantiation time, throw away the
    type-checked AST and store the raw expressions in the AST. This
    simplifies instantiation, but loses a little but of information in
    the AST.

  - When type-checking implicit base or member initializers within a
    dependent context, don't add the generated initializers into the
    AST, because they'll look like they were explicit.

  - Record in CXXConstructExpr when the constructor call is to
  initialize a base class, so that CodeGen does not have to infer it
  from context. This ensures that we call the right kind of
  constructor.

There are also a few "opportunity" fixes here that were needed to not
regress, for example:

  - Diagnose default-initialization of a const-qualified class that
    does not have a user-declared default constructor. We had this
    diagnostic specifically for bases and members, but missed it for
    variables. That's fixed now.

  - When defining the implicit constructors, destructor, and
    copy-assignment operator, set the CurContext to that constructor
    when we're defining the body.

llvm-svn: 94952
2010-01-31 09:12:51 +00:00
Anders Carlsson 98323d29b6 Remove the SmallVectors from AsmStmt. Fixes PR6105.
llvm-svn: 94926
2010-01-30 23:19:41 +00:00
Anders Carlsson 9a020f9a3a Use IdentifierInfo * instead of std::string for the AsmStmt names.
llvm-svn: 94925
2010-01-30 22:25:16 +00:00
Daniel Dunbar 6b03ecef0d ASTUnit: Ensure the CompilerInvocation object used in LoadFromCommandLine is
live as long as the ASTUnit. This is useful for clients which want to maintain
pointers to the LangOptions object which ultimately lives in the
CompilerInvocation, although it would be nice to make all of this ownership
stuff more explicit and obvious.

llvm-svn: 94924
2010-01-30 21:47:16 +00:00
Daniel Dunbar 6824225465 CompilerInstance: Change to not contain the CompilerInvocation object.
This allows clients to install their own CompilerInvocation object, which is
important for clients that may wish to create references to things like
LangOptions whose lifetime will extend past that of the CompilerInstance.

llvm-svn: 94923
2010-01-30 21:47:07 +00:00
Anders Carlsson 66de081f39 Even more AsmStmt cleanup.
llvm-svn: 94921
2010-01-30 20:38:10 +00:00
Anders Carlsson 087bc13d96 More asm cleanup.
llvm-svn: 94920
2010-01-30 20:05:21 +00:00
Anders Carlsson 96fe0b5b96 Combine AsmStmt::setOutputsAndInputs and AsmStmt::setClobbers.
llvm-svn: 94918
2010-01-30 19:34:25 +00:00
Anders Carlsson c7c5baa482 Yay for more StringRefs.
llvm-svn: 94917
2010-01-30 19:12:25 +00:00
Anders Carlsson 0b0a122fde StringRef-ize the TargetInfo::ConstraintInfo constructor.
llvm-svn: 94916
2010-01-30 18:33:31 +00:00
Daniel Dunbar 19b70bd46c Recognize 'q' as a format length modifier (from BSD).
llvm-svn: 94894
2010-01-30 15:49:20 +00:00
Benjamin Kramer 842bf17366 Use StringRef instead of returning a temporary std::string.
This fixes a really nasty bug in Darwin::getDarwinArchName where we were going
StringRef -> temporary std::string -> StringRef (and return the dead StringRef).
The StringRefs from Triple live as long as the Triple itself, that should be
long enough.

Hopefully 2 of 4 MSVC buildbot failures are gone now.

llvm-svn: 94892
2010-01-30 15:01:47 +00:00
Benjamin Kramer f1e1e9596c Silence clang++ warning.
llvm-svn: 94878
2010-01-30 12:15:41 +00:00
Ted Kremenek c3bdff7c8c Add basic type checking of format string conversion specifiers and their arguments. Thanks to Cristian Draghici for his help with this patch!
llvm-svn: 94864
2010-01-30 00:49:51 +00:00
Ted Kremenek 79db7b7b17 Per a suggestion from Cristian Draghici, add a method to FormatSpecifier that returns the expected type of the matching data argument. It isn't complete, but should handle several of the important cases.
llvm-svn: 94851
2010-01-29 22:59:32 +00:00
Ted Kremenek 8d9842d43f Switch Sema over to using the new implementation of format string
checking.  It passes all existing tests, and the diagnostics have been
refined to provide better range information (we now highlight
individual format specifiers) and more precise wording in the
diagnostics.

llvm-svn: 94837
2010-01-29 20:55:36 +00:00
Ted Kremenek 23a71a1cdf Enhancements to the alternate (WIP) format string checking:
- Add ConversionSpecifier::consumesDataArgument() as a helper method
  to determine if a conversion specifier requires a matching argument.
- Add support for glibc-specific '%m' conversion
- Add an extra callback to HandleNull() for locations within the
  format specifier that have a null character

llvm-svn: 94834
2010-01-29 20:29:53 +00:00
Douglas Gregor d1e08648c6 Fix reference-binding when we have a reference to const volatile type;
previously, we were allowing this to bind to a temporary. Now, we
don't; add test-cases and improve diagnostics.

llvm-svn: 94831
2010-01-29 19:39:15 +00:00
Benjamin Kramer 37aa4508e2 Fix typo found by clang++. Yay for -Wuninitialized.
llvm-svn: 94810
2010-01-29 15:58:21 +00:00
Anders Carlsson 385ab187e6 Add getters.
llvm-svn: 94803
2010-01-29 06:34:33 +00:00
Anders Carlsson 5d8645b150 Simplify EmitLValueForField - we can get whether the field is part of a union or not from the FieldDecl (through its DeclContext).
llvm-svn: 94798
2010-01-29 05:05:36 +00:00
Ted Kremenek c22f78ddfd Alternate format string checking: issue warnings for incomplete format specifiers.
In addition, move ParseFormatString() and FormatStringHandler() from
the clang::analyze_printf to the clang namespace.  Hopefully this will
resolve some link errors on Linux.

llvm-svn: 94794
2010-01-29 03:16:21 +00:00
Ted Kremenek 94af575e9c Alternate format string checking: issue a warning for invalid conversion specifiers.
llvm-svn: 94792
2010-01-29 02:40:24 +00:00
Anders Carlsson ba6c437d52 Add an CXXBindReferenceExpr (not used just yet).
llvm-svn: 94791
2010-01-29 02:39:32 +00:00
John McCall 180ef09371 Do a little magic and a little greasework to make it much more efficient
to cast a DeclContext down to a specific implementation class.

There are still lots of calls to Decl::castFromDeclContext left, mostly
arising from DeclContext::getParent().

llvm-svn: 94786
2010-01-29 01:45:37 +00:00
Ted Kremenek d5fd0fac38 Alternate format string checking: warn of '%n' as being potentially insecure.
llvm-svn: 94782
2010-01-29 01:35:25 +00:00
Ted Kremenek 5739de77fa Add precision/field width checking to AlternateCheckPrintfString().
llvm-svn: 94774
2010-01-29 01:06:55 +00:00
Douglas Gregor 60b11f6dfd When printing diagnostics in c-index-test, also print source ranges
and fix-it information, so we can see everything in one place. Along
the way, fix a few bugs with deserialization and query of diagnostics
in CIndex.

llvm-svn: 94768
2010-01-29 00:41:11 +00:00
John McCall 2cb941642e Access control for surrogate function calls. Required a moderately gross hack
to get the access bits set properly in conversion sets.

llvm-svn: 94744
2010-01-28 07:38:46 +00:00
Douglas Gregor ac0605e927 Introduce serialization and deserialization of diagnostic information
so that CIndex can report diagnostics through the normal mechanisms
even when executing Clang in a separate process. This applies both
when performing code completion and when using ASTs as an intermediary
for clang_createTranslationUnitFromSourceFile().

The serialized format is not perfect at the moment, because it does
not encapsulate macro-instantiation information. Instead, it maps all
source locations back to the instantiation location. However, it does
maintain source-range and fix-it information. To get perfect fidelity
from the serialized format would require serializing a large chunk of
the source manager; at present, it isn't clear if this code will live
long enough for that to matter.

llvm-svn: 94740
2010-01-28 06:00:51 +00:00
Ted Kremenek fee0e96c82 Add position of conversion specifier character to 'ConversionSpecifier'.
llvm-svn: 94739
2010-01-28 02:46:17 +00:00
Ted Kremenek 08ad1cceb3 Rename namespace clang::printf to clang::analyze_printf to avoid problems where the reference to 'printf' is ambiguous.
llvm-svn: 94733
2010-01-28 02:02:59 +00:00
Fariborz Jahanian 81310810bd Fixes a rewrite bug rewriting nested ivars reference.
(Radar 7583971).

llvm-svn: 94724
2010-01-28 01:41:20 +00:00
Ted Kremenek bcbdaea703 Allow HandleFormatSpecifier() to indicate that no more processing of the format string is desired.
llvm-svn: 94715
2010-01-28 01:00:59 +00:00
Douglas Gregor ba965fb2a7 Switch the remaining diagnostic printing in CIndex over to the
diagnostic callback mechanism, so all diagnostics now go through that
callback. Also, eliminate the displayDiagnostics flag to
clang_createIndex(), since it is no longer necessary: the client
determines whether to display diagnostics or not.

llvm-svn: 94714
2010-01-28 00:56:43 +00:00
Ted Kremenek c06ead62f0 Add '@' conversion specifier.
llvm-svn: 94713
2010-01-28 00:55:28 +00:00
Douglas Gregor 4f9c376570 Implement a diagnostics callback for the C interface to Clang, so that
clients can format diagnostics as they wish rather than having to
parse standard error. All of the important parts of the front end's
diagnostics are exposed: text, severity, location, source ranges, and
fix-its. The diagnostics callback is now available with
clang_createTranslationUnitFromSource() and
clang_createTranslationUnit().

As part of this change, CXSourceLocation and CXSourceRange got one
pointer larger, since we need to hold on to the SourceManager and
LangOptions structures in the source location. This is the minimum
amount of information needed for the functions that operate on source
locations and ranges (as implemented now). Previously we held on to
the ASTContext, but the diagnostics callback can end up with source
locations when there is no ASTContext (or preprocessor).

Still to do:
  - Code completion needs to support the diagnostics callback, once we
  have the ability to (de-)serialize diagnostics.
  - Eliminate the "displayDiagnostics" argument to createIndex; we'll
  always pass diagnostics to the callback and let it deal with display.

llvm-svn: 94709
2010-01-28 00:27:43 +00:00
Ted Kremenek a2e77b41f3 Add skeleton for a more structured way to analyzing pring format
strings than what we currently have in Sema.  This is both an
experiment and a WIP.

The idea is simple: parse the format string incrementally,
constructing a well-structure representation of each format specifier.
Each format specifier is then handed back one-by-one to a client via a
callback.  Malformed format strings are also handled with callbacks.
The idea is to separate the parsing of the format string from the
emission of diagnostics.  Currently what we have in Sema for handling
format strings is a mongrel of both that is hard to follow and
difficult to modify (I can apply this label since I'm the original
author of that code).

This is in libAnalysis as it is reasonable generic and can potentially
be used both by libSema and libChecker.

Comments welcome.

llvm-svn: 94702
2010-01-27 23:43:25 +00:00
Ted Kremenek e9918356b2 Move more naming conventions logic out of the retain/release checker to CocoaConventions.h.
llvm-svn: 94682
2010-01-27 18:00:17 +00:00
Ken Dyck 160146eba2 Change the return type of ASTContext::getDeclAlignInBytes() to CharUnits and,
now that the "InBytes" part of the name is implied by the return type, rename
it to getDeclAlign().

llvm-svn: 94681
2010-01-27 17:10:57 +00:00
Chandler Carruth f6442e7b2e Silence a GCC warning about uninitialized variables. The first user of this
showed up with a primitive type.

llvm-svn: 94674
2010-01-27 10:28:04 +00:00
Ted Kremenek db1832d928 Start pulling out pieces of the monolithic retain/release checker into
reusable and modular API pieces.

Start by pulling the logic for deriving the Cocoa naming convention
into a separate API, header, and source file.

llvm-svn: 94662
2010-01-27 06:13:48 +00:00
Anders Carlsson 673d1401c5 It's not Explicit anymore.
llvm-svn: 94657
2010-01-27 03:27:53 +00:00
John McCall 58cc69d4c1 Implement access control for overloaded functions. Suppress access control
diagnostics in "early" lookups, such as during typename checks and when building
unresolved lookup expressions.

llvm-svn: 94647
2010-01-27 01:50:18 +00:00
Daniel Dunbar b473083fcd Support -marm by treating it as an alias for -mno-thumb.
llvm-svn: 94644
2010-01-27 01:06:14 +00:00
Daniel Dunbar b92d12622c Driver/Darwin: Disallow -m{macosx,iphoneos}-version-min as -Xarch arguments.
llvm-svn: 94636
2010-01-27 00:56:31 +00:00
Ted Kremenek 7ad29c72e3 Add const version of ObjCMethodDecl::getCanonicalDecl().
llvm-svn: 94633
2010-01-27 00:37:54 +00:00
Ted Kremenek e36bceb97d Teach RegionStore to handle initialization of incomplete arrays in structures using a compound value. Fixes <rdar://problem/7515938>.
llvm-svn: 94622
2010-01-26 23:51:00 +00:00