Richard Smith [Sun, 12 May 2013 23:39:32 +0000 (23:39 +0000)]
Downgrade C++14 "Clarifying memory allocation". We perform non-conforming
optimizations -- in particular, globalopt will remove calls to ::operator
new(size_t) that did not come from new-expressions.
Richard Smith [Sun, 12 May 2013 23:17:59 +0000 (23:17 +0000)]
Fix stack overflow in linkage computation when a function with a deduced return
type returns a lambda defined within itself. The computation of linkage for the
function looked at the linkage of the lambda, and vice versa.
This is solved by not checking whether an 'auto' in a function return type
deduces to a type with unique external linkage. We don't need this check,
because the type deduced for 'auto' doesn't affect whether two
otherwise-identical declarations would name different functions, so we don't
need to give an ostensibly external-linkage function internal linkage for this
reason. (We also don't need unique-external linkage in C++11 onwards at all,
but that's not implemented yet.)
Richard Smith [Sun, 12 May 2013 17:32:42 +0000 (17:32 +0000)]
C++1y: support for 'switch' statements in constexpr functions. This is somewhat
inefficient; we perform a linear scan of switch labels to find the one matching
the condition, and then walk the body looking for that label. Both parts should
be straightforward to optimize.
Richard Smith [Sat, 11 May 2013 05:45:24 +0000 (05:45 +0000)]
C++1y deduced return types: when we deduce a return type for a function which
we loaded from PCH, if we're building another PCH, create an update record to
patch the return type of the earlier declaration.
We could support the GCC extension DW_TAG_GNU_template_parameter_pack if
we're feeling adventurous, at some point - but I don't think GDB's doing
anything useful with it yet anyway.
Douglas Gregor [Fri, 10 May 2013 22:15:13 +0000 (22:15 +0000)]
[Modules] When things go horribly wrong when reading a module, point at the module cache.
Sometimes people hack on their system headers. In such cases, they'll
need to delete their module cache, but may not know where it is. Add a
note to show them where it is.
David Blaikie [Fri, 10 May 2013 21:53:14 +0000 (21:53 +0000)]
PR14992: Debug Info: Support more non-type template parameters
* Provide DW_TAG_template_value_parameter for pointers, function
pointers, member pointers, and member function pointers (still missing
support for template template parameters which GCC encodes as a
DW_TAG_GNU_template_template_param)
* Provide values for all but the (member & non-member) function pointer case.
Simple constant integer values for member pointers (offset within the
object) and address for the value pointer case. GCC doesn't provide a
value for the member function pointer case so I'm not sure how, if at
all, GDB supports encoding that. & non-member function pointers should
follow shortly in a subsequent patch.
* Null pointer value encodings of all of these types, including
correctly encoding null data member pointers as -1.
In this case, when we call systemFunction, we know (because it's a system
function) that it won't free 'p'. However, we /don't/ know whether or not
it will /change/ 'p', so the analyzer is forced to invalidate 'p', wiping
out any bindings it contains. But now the malloc'd region looks like a
leak, since there are no more bindings pointing to it, and we'll get a
spurious leak warning.
The fix for this is to notice when something is becoming inaccessible due
to invalidation (i.e. an imperfect model, as opposed to being explicitly
overwritten) and stop tracking it at that point. Currently, the best way
to determine this for a call is the "indirect escape" pointer-escape kind.
In practice, all the patch does is take the "system functions don't free
memory" special case and limit it to direct parameters, i.e. just the
arguments to a call and not other regions accessible to them. This is a
conservative change that should only cause us to escape regions more
eagerly, which means fewer leak warnings.
This isn't perfect for several reasons, the main one being that this
example is treated the same as the one above:
Currently, "addresses accessible by offsets of the starting region" and
"addresses accessible through bindings of the starting region" are both
considered "indirect" regions, hence this uniform treatment.
Another issue is our longstanding problem of not distinguishing const and
non-const bindings; if in the first example systemFunction's parameter were
a char * const *, we should know that the function will not overwrite 'p',
and thus we can safely report the leak.
Daniel Jasper [Fri, 10 May 2013 13:00:49 +0000 (13:00 +0000)]
Always format entire macro definitions.
Thereby, the macro is consistently formatted (including the trailing
escaped newlines) even if clang-format is invoked only on single lines
of the macro.
Summary:
Adds actual config file reading to the clang-format utility.
Configuration file name is .clang-format. It is looked up for each input file
in its parent directories starting from immediate one. First found .clang-format
file is used. When using standard input, .clang-format is searched starting from
the current directory.
Added -dump-config option to easily create configuration files.
Hans Wennborg [Fri, 10 May 2013 10:08:40 +0000 (10:08 +0000)]
Add support for __wchar_t in -fms-extensions mode.
MSVC provides __wchar_t. This is the same as the built-in wchar_t type
from C++, but it is also available with -fno-wchar and in C.
The commit changes ASTContext to have two different types for this:
- WCharTy is the built-in type used for wchar_t in C++ and __wchar_t.
- WideCharTy is the type of a wide character literal. In C++ this is
the same as WCharTy, and in C it is an integer type compatible with
the type in <stddef.h>.
Daniel Jasper [Fri, 10 May 2013 07:59:58 +0000 (07:59 +0000)]
Fix bug when formatting overloaded operators.
Before, the actual operator of an overloaded operator declaration was
handled as a binary operator an thus, clang-format could not find valid
formattings for many examples, e.g.:
Richard Smith [Fri, 10 May 2013 04:31:10 +0000 (04:31 +0000)]
C++1y auto return type: when a function contains no 'return' statements at all,
substitute 'void' into the return type rather than replacing it with 'void', so
that we maintain the 'auto' type sugar.
Adrian Prantl [Thu, 9 May 2013 23:16:27 +0000 (23:16 +0000)]
Debug Info: Fix a problem that resulted in missing DW_AT_specifications
for C++ constructors.
If the DIType for a class was generated by
CGDebugInfo::createContextChain(), the cache contains only a
limited DIType wihtout any declarations. Since EmitFunctionStart()
needs to find the canonical declaration for each method, we
construct the complete type before emitting any method.
David Blaikie [Thu, 9 May 2013 22:43:45 +0000 (22:43 +0000)]
Debug Info: include address-of ('&') operator and qualified names in template argument lists
This fixes several (7 out of 16) cases of PR14492 in the GDB 7.5 test
suite. It seems GDB was bailing out whenever it had even the slightest
problem with the template argument list (& I assume it didn't like
seeing template value parameters that were just simple names - perhaps
assuming that lone names must be types, not values)
David Blaikie [Thu, 9 May 2013 21:32:04 +0000 (21:32 +0000)]
DebugInfo: Simply & constrain test(s) for PR9600/PR9608
Both these tests were ultimately fixed by the check for
"isIncompleteType" & neither test case was really reduced to a minimal
form. On doing so it becomes apparent that the problem wasn't specific
to templates at all, so I've moved the test case to a more appropriate
test file and added FileCheck verification to it (to show the forward
declaration of the array element type as well as the array alignment and
size being 0 since it cannot be computed). That's about as far down this
rabbithole as I'm willing to go today, so the rest of the un-FileChecked
tests in test/CodeGenCXX/debug-info.cpp will have to go another day
without actually testing anything other than the fact that they don't
crash.
& improve the actually interesting test case in
test/CodeGenCXX/debug-info-templates.cpp which was my original goal (in
preparation for expanding it/fixing some related bugs in non-type
template parameters)
David Blaikie [Thu, 9 May 2013 20:48:12 +0000 (20:48 +0000)]
Debug Info: Remove unnecessary check for dependent array types
This was added, untested (though the relevant crash was tested), in
r128725/PR9600. Removing it doesn't cause failures & nothing I can
imagine could cause this check to ever return 'true' (we should never be
dealing with dependent types here). The subsequent change to check
"isIncompleteType" (r128855/PR9608) makes a lot more sense.
Ben Langmuir [Thu, 9 May 2013 19:17:11 +0000 (19:17 +0000)]
CodeGen for CapturedStmts
EmitCapturedStmt creates a captured struct containing all of the captured
variables, and then emits a call to the outlined function. This is similar in
principle to EmitBlockLiteral.
GenerateCapturedFunction actually produces the outlined function. It is based
on GenerateBlockFunction, but is much simpler. The function type is determined
by the parameters that are in the CapturedDecl.
Some changes have been added to this patch that were reviewed as part of the
serialization patch and moving the parameters to the captured decl.
[doc parsing]: So, in this patch, single character
'commands' will not go through typo fixit logic,
preserving the old behavior (no typo, no diagnostics).
// rdar://12381408
Richard Smith [Thu, 9 May 2013 07:14:00 +0000 (07:14 +0000)]
Implement C++1y constant initializer rules: in a constant initializer for an
object x, x's subobjects can be constructed by constexpr constructor even if
they are of non-literal type, and can be read and written even though they're
not members of a constexpr object or temporary.
Nico Weber [Wed, 8 May 2013 23:47:40 +0000 (23:47 +0000)]
Objective-C: Correctly encode 'retain' and 'copy' for readonly properties.
clang would omit 'C' for 'copy' properties and '&' for 'retain' properties if
the property was also 'readonly'. Fix this, which makes clang match gcc4.2's
behavior.
[modules] When building a module, make sure we don't serialize out HeaderFileInfo for headers not belonging to the module.
After r180934 we may initiate module map parsing for modules not related to the module what we are building,
make sure we ignore the header file info of headers from such modules.
documentation parsing. Patch to do typo correction for
documentation commands. Patch was reviewed, along with
great suggestions for improvement, by Doug.
// rdar://12381408
Daniel Jasper [Wed, 8 May 2013 14:12:04 +0000 (14:12 +0000)]
Improve line breaking in binary expressions.
If the LHS of a binary expression is broken, clang-format should also
break after the operator as otherwise:
- The RHS can be easy to miss
- It can look as if clang-format doesn't understand operator precedence
Reid Kleckner [Wed, 8 May 2013 13:44:39 +0000 (13:44 +0000)]
Forward #pragma comment(lib/linker) through as flags metadata
Summary:
Most of this change is wiring the pragma all the way through from the
lexer, parser, and sema to codegen. I considered adding a Decl AST node
for this, but it seemed too heavyweight.
Mach-O already uses a metadata flag called "Linker Options" to do this
kind of auto-linking. This change follows that pattern.
LLVM knows how to forward the "Linker Options" metadata into the COFF
.drectve section where these flags belong. ELF support is not
implemented, but possible.
This is related to auto-linking, which is http://llvm.org/PR13016.
The reason for the change is that:
a) we are not sure which is better
b) it is a really rare edge case
c) it simplifies the code
d) it currently causes problems with memoization
David Blaikie [Wed, 8 May 2013 06:01:46 +0000 (06:01 +0000)]
Debug Info: Using declarations/DW_TAG_imported_declaration of variables, types, and functions.
Basic support is implemented here - it still doesn't account for
declared-but-not-defined variables or functions. It cannot handle out of
order (declared, 'using', then defined) cases for variables, but can
handle that for functions (& can handle declared, 'using'd, and not
defined at all cases for types).