Chris Lattner [Mon, 25 Apr 2011 20:42:40 +0000 (20:42 +0000)]
don't use compound literals in MM macros, since they will be instantiated
into user code which may warn about them with -pedantic. Patch by Jonathan Sauer!
Chris Lattner [Mon, 25 Apr 2011 20:37:58 +0000 (20:37 +0000)]
fix PR9474, a crash with -fshort-enum and C++ templates: when instantiating
the enum decl, we need to use an integer type the same size as the enumerator,
which may not be the promoted type with packed enums.
Douglas Gregor [Mon, 25 Apr 2011 15:05:41 +0000 (15:05 +0000)]
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.
Remove some more hard CR-LF lines. These were particularly weird as they were
only a few lines of the file. Also set their properties to have explicitly
native eol sytle.
John Wiegley [Mon, 25 Apr 2011 06:54:41 +0000 (06:54 +0000)]
t/clang/expr-traits
Patch authored by David Abrahams.
These two expression traits (__is_lvalue_expr, __is_rvalue_expr) are used for
parsing code that employs certain features of the Embarcadero C++ compiler.
Ken Dyck [Sun, 24 Apr 2011 17:02:38 +0000 (17:02 +0000)]
Replace calls to ASTContext::getTypeInfo() with calls to
ASTContext::getTypeSize() when only the size part is used. No change in
functionality intended.
Ken Dyck [Sun, 24 Apr 2011 16:40:29 +0000 (16:40 +0000)]
Eliminate literal 8s from LayoutBitField(), converting variables to
CharUnits or replacing the 8s with char align. No change in functionality
intended.
Sebastian Redl [Sun, 24 Apr 2011 16:28:06 +0000 (16:28 +0000)]
Synthesizing the definition of an implicit member is an AST modification, so notify any mutation listeners of it. This fixes a crasher in chained PCH, where an implicit destructor in a PCH gets a definition in a chained PCH, which is then lost. However, any further use of the destructor would cause its definition to be regenerated in the final file, hiding the bug.
Sebastian Redl [Sun, 24 Apr 2011 16:27:54 +0000 (16:27 +0000)]
On reading DeclContexts from PCH, check for visible updates even if the context was empty in the original version. Also, if there are any, tell the context that it has external visible decls. This fixes the problem that a namespace that was empty in the initial PCH (could also happen if the initial PCH didn't include any std header but caused implicit creation of namespace std, e.g. due to implicit declaration of a virtual destructor) never found any declaration declared in *any* chained PCH. Very ugly when the chained PCH includes all that std stuff, as the errors were effectively the same as not including std headers.
Sebastian Redl [Sun, 24 Apr 2011 16:27:48 +0000 (16:27 +0000)]
Make the invalid declarator recovery when parsing members work the same as when parsing global decls. It's still rather broken (skipping much too far when the declarator belongs to a function definition), but at least not so broken as to mismatch braces. Tested by the removal of the fixme in the template test case.
Sebastian Redl [Sun, 24 Apr 2011 16:27:30 +0000 (16:27 +0000)]
Store the full list of pending instantiations in a chained PCH. Previously we attempted to store only new pending instantiations, but our filter was incorrect, dropping implicit instantiations of class template members. It's just not worth coming up with a complex filter that is correct, when the only cost is PCH files that are a few hundred bytes (at most) larger.
Downgrade unnecessary "typename" from error to warning in Microsoft mode.
This fixes 1 error when parsing MSVC 2008 headers with clang.
Must "return true;" even if it is a warning because the rest of the code path assumes that SS is set to something. The parser will get back on its feet and continue parsing the rest of the declaration correctly so it is not a problem.
John McCall [Sun, 24 Apr 2011 08:43:07 +0000 (08:43 +0000)]
GCC seems to create address-of expression manglings when passing *any*
function as a template argument where a pointer to function is wanted.
Just extend the existing hack.
John McCall [Sun, 24 Apr 2011 08:23:24 +0000 (08:23 +0000)]
Update the mangler for some of the "new" unresolved-name manglings.
I've sent off an email requesting clarification on a few things that
I wasn't sure how to handle.
This also necessitated making prefixes and unresolved-prefixes get
mangled separately.
Douglas Gregor [Sun, 24 Apr 2011 05:37:28 +0000 (05:37 +0000)]
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>.
John McCall [Sun, 24 Apr 2011 03:07:16 +0000 (03:07 +0000)]
The ABI settled on mangling float literals with lowercase hex dumps.
APInt::toString doesn't do those, but it's easy to postprocess that output,
and that's probably better than adding another knob to that method.
Implement most of the remaining logic in __is_literal type trait. This
should now support all of the C++98 types, and all of the C++0x types
Clang supports.
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.
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.
Flesh out these tests just a tad more. This provides targeted
'DerivesHasFoo' types for various non-POD constructs in the base class.
Only __is_pod and __is_trivial are wired up to these, not sure how much
more of this type of exhaustive testing is really interesting.
Test POD and trivial type traits given a class derived from a generic
non-POD type.
It might be nicer to have a Derives* variant for each of HasCons,
HasCopy, etc. Then we could test each of those and also test the __has_*
traits. WIP.
Use a more precise name for some of the types here, and re-group several
of the tests using those types to have a (hopefully) more logical
ordering now that doing so doesn't cause unreadable deltas of counters
changing.
Mechanical change moving all of the test statements away from a pattern
that requires needless noise in every patch (due to numbers changing) or
poorly grouped test cases in order to have strictly increasing numbers.
This will make my subsequent patches much less ugly. =D
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.
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
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.
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.
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.
Douglas Gregor [Fri, 22 Apr 2011 23:49:24 +0000 (23:49 +0000)]
Teach libclang to be more careful around BlockDecls, and don't assume
that a TypeSourceInfo is always available, like we do everywhere else
in libclang. Fixes <rdar://problem/9311140>.
Douglas Gregor [Fri, 22 Apr 2011 22:25:37 +0000 (22:25 +0000)]
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>.
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.
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
Nick Lewycky [Thu, 21 Apr 2011 23:44:07 +0000 (23:44 +0000)]
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.