Commit Graph

9738 Commits

Author SHA1 Message Date
Chandler Carruth 65fa1fd18e Add support for '__is_literal_type' spelling of the existing
'__is_literal' type trait for GCC compatibility. At least one relased
version if libstdc++ uses this name for the trait despite it not being
documented anywhere.

llvm-svn: 130078
2011-04-24 02:49:28 +00:00
Chandler Carruth ad7d404732 Begin tracking trivialness of move constructors and move assignment
operators in C++ record declarations.

This patch starts off by updating a bunch of the standard citations to
refer to the draft 0x standard so that the semantics intended for move
varianst is clear. Where necessary these are duplicated so they'll be
available in doxygen.

It adds bit fields to keep track of the state for the move constructs,
and updates all the code necessary to track this state (I think) as
members are declared for a class. It also wires the state into the
various trait-like accessors in the AST's API, and tests that the type
trait expressions now behave correctly in the presence of move
constructors and move assignment operators.

This isn't complete yet due to these glaring FIXMEs:
1) No synthesis of implicit move constructors or assignment operators.
2) I don't think we correctly enforce the new logic for both copy and
   move trivial checks: that the *selected* copy/move
   constructor/operator is trivial. Currently this requires *all* of them
   to be trivial.
3) Some of the trait logic needs to be folded into the fine-grained
   trivial bits to more closely match the wording of the standard. For
   example, many of the places we currently set a bit to track POD-ness
   could be removed by querying other more fine grained traits on
   demand.

llvm-svn: 130076
2011-04-23 23:10:33 +00:00
Chandler Carruth 7ffce73fc8 Teach the AST reader and writer to preserve the __DEPRECATED bit in
language options, and warn when reading an AST with a different value
for the bit.

There doesn't appear to be a good way to test this (commenting out
similar other language options doesn't break anything) but if folks have
suggestions on tests I'm happy to add them.

llvm-svn: 130071
2011-04-23 20:05:38 +00:00
Jay Foad 1a180156b6 Remove unused STL header includes.
llvm-svn: 130068
2011-04-23 19:53:52 +00:00
Chandler Carruth 30483fb188 Move all of the logic for __DEPRECATED to the driver based on comments
from dgregor.

llvm-svn: 130066
2011-04-23 19:48:40 +00:00
Fariborz Jahanian dbbdd2fe50 "note" location of forward class used as receiver of
a 'deprecated' selector in the diagnostics for the
selector. // rdar://9309223

llvm-svn: 130062
2011-04-23 17:27:19 +00:00
Francois Pichet a7d337d196 Remove unnecessary const away cast in LateTemplateParserCallback.
llvm-svn: 130058
2011-04-23 11:52:20 +00:00
Chandler Carruth a3e1f9a02c Implement basic __is_trivial type-trait support, enough to close PR9472.
This introduces a few APIs on the AST to bundle up the standard-based
logic so that programmatic clients have access to exactly the same
behavior.

There is only one serious FIXME here: checking for non-trivial move
constructors and move assignment operators. Those bits need to be added
to the declaration and accessors provided.

This implementation should be enough for the uses of __is_trivial in
libstdc++ 4.6's C++98 library implementation.

Ideas for more thorough test cases or any edge cases missing would be
appreciated. =D

llvm-svn: 130057
2011-04-23 10:47:28 +00:00
Chandler Carruth 7980348fcf Sort the type traits in a few places where they weren't previously
sorted in order to prepare for adding some new ones.

llvm-svn: 130056
2011-04-23 10:47:20 +00:00
Chandler Carruth 61fbf62838 Fix Clang's __DEPRECATED define to be controled by -Wdeprecated. This
matches GCC behavior which libstdc++ uses to limit #warning-based
messages about deprecation.

The machinery involves threading this through a new '-fdeprecated-macro'
flag for CC1. The flag defaults to "on", similarly to -Wdeprecated. We
turn the flag off in the driver when the warning is turned off (modulo
matching some GCC bugs). We record this as a language option, and key
the preprocessor on the option when introducing the define.

A separate flag rather than a '-D' flag allows us to properly represent
the difference between C and C++ builds (only C++ receives the define),
and it allows the specific behavior of following -Wdeprecated without
potentially impacting the set of user-provided macro flags.

llvm-svn: 130055
2011-04-23 09:27:53 +00:00
Chandler Carruth 153329dad7 GCC overloads -Wwrite-strings just to make it extra confusing. While it
changes language semantics in C and ObjC (which Clang has supported for
a while), in C++ it's the name used for Clang's
-Wdeprecated-writable-strings.

Clang's name is at least less overloaded if still confusing (the string
isn't writable, we just allow converting to a non-const pointer without
warning), so I've left it in place and made the GCC name an alias for
compatibility.

With this I've implemented all the aspects of GCC's -Wwrite-strings I've
encountered which didn't work with Clang.

llvm-svn: 130052
2011-04-23 06:54:44 +00:00
Chandler Carruth b009b14971 There were some frustrating problems with the implementation of
-Wwrite-strings. First and foremost, once the positive form of the flag
was passed, it could never be disabled by passing -Wno-write-strings.
Also, the diagnostic engine couldn't in turn use -Wwrite-strings to
control diagnostics (as GCC does) because it was essentially hijacked to
drive the language semantics.

Fix this by giving CC1 a clean '-fconst-strings' flag to enable
const-qualified strings in C and ObjC compilations. Corresponding
'-fno-const-strings' is also added. Then the driver is taught to
introduce '-fconst-strings' in the CC1 command when '-Wwrite-strings'
dominates.

This entire flag is basically GCC-bug-compatibility driven, so we also
match GCC's bug where '-w' doesn't actually disable -Wwrite-strings. I'm
open to changing this though as it seems insane.

llvm-svn: 130051
2011-04-23 06:30:43 +00:00
Argyrios Kyrtzidis bf04231a72 Don't allow reinterpret_cast to reference of vector element and property expression. Thanks goes to Eli Friedman!
llvm-svn: 130036
2011-04-22 23:57:57 +00:00
Francois Pichet dcb3ebeb2c Correctly emit a diagnostic for multiple templated function definitions in -flate-template-parsing mode.
llvm-svn: 130030
2011-04-22 23:20:44 +00:00
Argyrios Kyrtzidis 47a1285a69 reinterpret_cast to reference of a bit-field is not allowed.
Fixes rdar://9202628 & http://llvm.org/PR9564.

llvm-svn: 130024
2011-04-22 22:31:13 +00:00
Douglas Gregor 9750969178 At the end of the translation unit, defining a vtable can introduce
new templates that need to be instantiated and vice-versa. Iterate
until we've instantiated all required templates and defined all
required vtables. Fixed PR9325 / <rdar://problem/9055177>.

llvm-svn: 130023
2011-04-22 22:25:37 +00:00
Francois Pichet 1c229c0472 Add -fdelayed-template-parsing option. Using this option all templated function definitions are parsed at the end of the translation unit only if it is required by an actual instantiation. As such all the symbols of the TU are available during name lookup.
Using this flag is necessary for compatibility with Microsoft template code.
This also provides some parsing speed improvement.

llvm-svn: 130022
2011-04-22 22:18:13 +00:00
Fariborz Jahanian c057794adb Fixes an instance method meta-data generation bug in
ObjC NeXt runtime where method pointer registered in
metadata belongs to an unrelated method. Ast part of this fix,
I turned at @end missing warning (for class
implementations) into an error as we can never
be sure that meta-data being generated is correct.
// rdar://9072317

llvm-svn: 130019
2011-04-22 22:02:28 +00:00
Francois Pichet 9392165a17 For consistency, change suffix from war_ to warn_ for some Microsoft warnings I introduced lately.
llvm-svn: 129986
2011-04-22 08:25:24 +00:00
Francois Pichet e900b10a29 Downgrade error "static declaration of 'foo' follows non-static declaration" to a warning in Microsoft mode.
llvm-svn: 129985
2011-04-22 08:14:00 +00:00
Francois Pichet 0aa6949b3e _declspec is an alias for __declspec.
llvm-svn: 129982
2011-04-22 05:21:17 +00:00
Nick Lewycky 207bce31e1 Wire up the -ftest-coverage and -fprofile-arcs flags to .gcno file emission (at
compile time) and .gcda emission (at runtime). --coverage enables both.

This does not yet add the profile_rt library to the link step if -fprofile-arcs
is enabled when linking.

llvm-svn: 129956
2011-04-21 23:44:07 +00:00
Argyrios Kyrtzidis b77d6f0fd1 Don't hide #warnings in a system header, same as gcc. Fixes rdar://8495837.
llvm-svn: 129951
2011-04-21 23:08:23 +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
Nick Lewycky ed7504e65c Alphabetize this one flag, just to pull it out of my patch.
llvm-svn: 129941
2011-04-21 21:32:34 +00:00
Argyrios Kyrtzidis 446bcf2d4a Use the ArrayFiller to fill out "holes" in the array initializer due to designated initializers,
avoiding to create separate Exprs for each one.

llvm-svn: 129933
2011-04-21 20:03:38 +00:00
Manuel Klimek d861e8b7be Adds a function to run FrontendActions over in-memory code. This is
the first step towards a standalone Clang tool infrastructure.
The plan is to make it easy to build command line tools that run over
the AST of source files in a project outside of the build system.

llvm-svn: 129924
2011-04-21 18:37:41 +00:00
Daniel Dunbar 5a784c8ed1 Driver: Tweak -Xarch diags a bit more, we can't actually differentiate between
unknown and "required more arguments", but only the latter should be feasible in
practice.

llvm-svn: 129919
2011-04-21 17:41:34 +00:00
Daniel Dunbar 6914a98ccd Driver: Improve -Xarch argument diagnostics a bit.
llvm-svn: 129918
2011-04-21 17:32:21 +00:00
Argyrios Kyrtzidis 99fbd4d1d8 Have #pragma message not turn into error by -Werror, by default. Fixes rdar://9308989.
llvm-svn: 129916
2011-04-21 17:11:44 +00:00
Argyrios Kyrtzidis b2ed28ea4b For
double data[20000000] = {0};

we would blow out the memory by creating 20M Exprs to fill out the initializer.

To fix this, if the initializer list initializes an array with more elements than
there are initializers in the list, have InitListExpr store a single 'ArrayFiller' expression
that specifies an expression to be used for value initialization of the rest of the elements.

Fixes rdar://9275920.

llvm-svn: 129896
2011-04-21 00:27:41 +00:00
Bill Wendling d70ca52081 Remove __builtin_ia32_loadup[sd] since clang can represent the actions natively.
llvm-svn: 129891
2011-04-20 23:10:45 +00:00
Justin Holewinski 514cce8e43 PTX: Add PTX intrinsics as builtins and add ptx32 and ptx64 as valid architectures for triples, e.g. ptx32-unknown-unknown
llvm-svn: 129870
2011-04-20 19:34:15 +00:00
Douglas Gregor d645931066 Fix a crash-on-invalid involving non-identifier names in a member
access expression that appears to be a property reference. Fixes
<rdar://problem/8985943>.

llvm-svn: 129865
2011-04-20 18:19:55 +00:00
Ted Kremenek 23324124e4 Rename 'CXTUMemoryUsage…' to 'CXTUResourceUsage…'.
llvm-svn: 129857
2011-04-20 16:41:07 +00:00
Douglas Gregor 49f754f423 Teach SourceManager::getSLocEntry() that it can fail due to problems
during deserialization from  a precompiled header, and update all of
its callers to note when this problem occurs and recover (more)
gracefully. Fixes <rdar://problem/9119249>.

llvm-svn: 129839
2011-04-20 00:21:03 +00:00
Argyrios Kyrtzidis 1618023018 We regard a function as 'unused' from the codegen perspective, so our warnings diverge from
gcc's unused warnings which don't get emitted if the function is referenced even in an unevaluated context
(e.g. in templates, sizeof, etc.). Also, saying that a function is 'unused' because it won't get codegen'ed
is somewhat misleading.

- Don't emit 'unused' warnings for functions that are referenced in any part of the user's code.
- A warning that an internal function/variable won't get emitted is useful though, so introduce
  -Wunneeded-internal-declaration which will warn if a function/variable with internal linkage is not
  "needed" ('used' from the codegen perspective), e.g:

  static void foo() { }

  template <int>
  void bar() {
    foo();
  }

test.cpp:1:13: warning: function 'foo' is not needed and will not be emitted
static void foo() { }
            ^

Addresses rdar://8733476.

llvm-svn: 129794
2011-04-19 19:51:10 +00:00
Peter Collingbourne 133587f08b Add a new expression classification, CL_AddressableVoid
CL_AddressableVoid is the expression classification used for void
expressions whose address can be taken, i.e. the result of [], *
or void variable references in C, as opposed to things like the
result of a void function call.

llvm-svn: 129783
2011-04-19 18:51:51 +00:00
Ted Kremenek 11d1a42e84 Report memory usage for global code completion results in CXTUMemoryUsage.
llvm-svn: 129733
2011-04-18 23:42:53 +00:00
Ted Kremenek 83f642e54a Add libclang API to query how much memory is used by a CXTranslationUnit. This is a WIP. Currently we report
the amount used for expressions, types, identifiers, and selectors.

llvm-svn: 129730
2011-04-18 22:47:10 +00:00
Ted Kremenek db571c6e44 Add ASTContext::getTotalMemory() to allow clients to query how much memory is bump allocated for declarations, statements, and types.
llvm-svn: 129729
2011-04-18 22:47:07 +00:00
Ted Kremenek 1c2239e9b1 Add SelectorTable::getTotalMemory() to allow clients to query how much memory is used by selectors.
llvm-svn: 129728
2011-04-18 22:47:04 +00:00
Daniel Dunbar 10d0868efb Driver: Support -fno-lto.
llvm-svn: 129712
2011-04-18 19:44:09 +00:00
Argyrios Kyrtzidis 0e993c3249 Introduce Rewriter::IncreaseIndentation() which increase indentations for the lines between the given source range.
To determine what the indentation should be, a SourceLocation 'parentIndent' parameter is used that should be at
a source location with an indentation one degree lower than the given range.

llvm-svn: 129628
2011-04-16 01:03:33 +00:00
Douglas Gregor 46ce91a964 Initial work to improve documentation for Clang's diagnostics, from Matthieu Monrocq
llvm-svn: 129614
2011-04-15 22:04:17 +00:00
Douglas Gregor 39d1a0973d Forbid the use of C++ new/delete to allocate/free objects within an
address space. I could see that this functionality would be useful,
but not in its current form (where the address space is ignored):
rather, we'd want to encode the address space into the parameter list
passed to operator new/operator delete somehow, which would require a
bunch more semantic analysis.

llvm-svn: 129593
2011-04-15 19:46:20 +00:00
Douglas Gregor b472e93af7 Implement appropriate semantics for C++ casting and conversion when
dealing with address-space- and GC-qualified pointers. Previously,
these qualifiers were being treated just like cvr-qualifiers (in some
cases) or were completely ignored, leading to uneven behavior. For
example, const_cast would allow conversion between pointers to
different address spaces.

The new semantics are fairly simple: reinterpret_cast can be used to
explicitly cast between pointers to different address spaces
(including adding/removing addresss spaces), while
static_cast/dynamic_cast/const_cast do not tolerate any changes in the
address space. C-style casts can add/remove/change address spaces
through the reinterpret_cast mechanism. Other non-CVR qualifiers
(e.g., Objective-C GC qualifiers) work similarly.

As part of this change, I tweaked the "casts away constness"
diagnostic to use the term "casts away qualifiers". The term
"constness" actually comes from the C++ standard, despite the fact
that removing "volatile" also falls under that category. In Clang, we
also have restrict, address spaces, ObjC GC attributes, etc., so the
more general "qualifiers" is clearer.

llvm-svn: 129583
2011-04-15 17:59:54 +00:00
Michael J. Spencer 6826eb816a Add 3DNow! Intrinsics.
llvm-svn: 129570
2011-04-15 15:07:13 +00:00
Richard Smith dda56e4b4a Support for C++11 (non-template) alias declarations.
llvm-svn: 129567
2011-04-15 14:24:37 +00:00
Ted Kremenek 1551d55295 Improve diagnostics on GNU attributes by warning about attributes that should have no arguments or parameters. Patch by Michael Han!
llvm-svn: 129560
2011-04-15 05:49:29 +00:00