Nick Lewycky [Fri, 8 Nov 2013 23:00:12 +0000 (23:00 +0000)]
Remove an incorrect optimization inside Clang's IRGen. Its check to determine
whether we can safely lower a conditional operator to select was insufficient.
I've left a large comment in place to explaining the sort of problems that this
transform can encounter in clang in the hopes of discouraging others from
reimplementing it wrongly again in the future. (The test should also help with
that, but it's easy to work around any single test I might add and think that
your particular implementation doesn't miscompile any code.)
Reid Kleckner [Fri, 8 Nov 2013 21:28:00 +0000 (21:28 +0000)]
Make -fdump-vtable-layouts print to stdout, not stderr
This makes it consistent with -fdump-record-layouts, which was moved to
outs() in r186219. My reasoning for going with stdout is that when one
of these options is present, the layouts are really a program output,
and shouldn't be interleaved with diagnostics, which are on stderr.
Daniel Jasper [Fri, 8 Nov 2013 19:56:28 +0000 (19:56 +0000)]
clang-format: Improve formatting of operators forced to new lines.
Before:
unsigned ContentSize =
sizeof(int16_t) // DWARF ARange version number
+
sizeof(int32_t) // Offset of CU in the .debug_info section
+
sizeof(int8_t) // Pointer Size (in bytes)
+
sizeof(int8_t); // Segment Size (in bytes)
After:
unsigned ContentSize =
sizeof(int16_t) // DWARF ARange version number
+ sizeof(int32_t) // Offset of CU in the .debug_info section
+ sizeof(int8_t) // Pointer Size (in bytes)
+ sizeof(int8_t); // Segment Size (in bytes)
Alp Toker [Fri, 8 Nov 2013 08:07:19 +0000 (08:07 +0000)]
clang-format: Write files atomically
Switch clang-format over to Rewriter::overwriteChangedFiles().
The previous implementation was attempting to stream back directly to the
original file and failing if it was already memory mapped by MemoryBuffer,
an operation unsupported by Windows.
MemoryBuffer generally mmaps files larger than the physical page size so
this will have been difficult to reproduce consistently.
This change also reduces flicker in code editors and IDEs on all platforms
when reformatting in-place.
Note that other incorrect uses of MemoryBuffer exist in LLVM/clang and
will need a similar fix.
A test should be added for Windows when libFormat performance issues are
fixed (it takes longer than a day to format a 1MB file at present!)
Daniel Jasper [Fri, 8 Nov 2013 06:45:35 +0000 (06:45 +0000)]
Add .clang-format without column limit to subdirectory tests/.
A column limit in the test folder can lead to trouble as the RUN, CHECK,
etc. comments can potentially be broken over multiple lines changing
their meaning. Without column limit, clang-format will simply keep the
test author's line breaks.
NAKAMURA Takumi [Fri, 8 Nov 2013 05:16:50 +0000 (05:16 +0000)]
clang/test/CXX/drs/dr1xx.cpp: Add explicit triple x86_64-unknown-unknown to satisfy check7a and check8a since r194240.
For i686 targets and LLP64 targets, we can see;
error: 'error' diagnostics seen but not expected:
File clang/test/CXX/drs/dr1xx.cpp Line 761: 'check7a' declared as an array with a negative size
File clang/test/CXX/drs/dr1xx.cpp Line 765: 'check8a' declared as an array with a negative size
2 errors generated.
NAKAMURA Takumi [Fri, 8 Nov 2013 04:00:53 +0000 (04:00 +0000)]
StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp: Tweak ContainerNonEmptyMap with "int" instead of "bool", to appease building since r194235.
In ADT/ImmutableSet, ImutProfileInfo<bool> cannot be matched to ImutProfileInteger.
I didn't have idea it'd the right way if PROFILE_INTEGER_INFO(bool) could be added there.
Douglas Gregor [Fri, 8 Nov 2013 02:04:24 +0000 (02:04 +0000)]
Objective-C++ ARC: Improve the conversion to a const __unsafe_unretained reference.
Under ARC++, a reference to a const Objective-C pointer is implicitly
treated as __unsafe_unretained, and can be initialized with (e.g.) a
__strong lvalue. Make sure this behavior does not break template
argument deduction and (related) that partial ordering still prefers a
'T* const&' template over a 'T const&' template when this case kicks
in. Fixes <rdar://problem/14467941>.
Jordan Rose [Fri, 8 Nov 2013 01:15:39 +0000 (01:15 +0000)]
[analyzer] Add IdenticalExprChecker, to find copy-pasted code.
This syntactic checker looks for expressions on both sides of comparison
operators that are structurally the same. As a special case, the
floating-point idiom "x != x" for "isnan(x)" is left alone.
Currently this only checks comparison operators, but in the future we could
extend this to include logical operators or chained if-conditionals.
Jordan Rose [Fri, 8 Nov 2013 01:15:35 +0000 (01:15 +0000)]
[analyzer] Track whether an ObjC for-in loop had zero iterations.
An Objective-C for-in loop will have zero iterations if the collection is
empty. Previously, we could only detect this case if the program asked for
the collection's -count /before/ the for-in loop. Now, the analyzer
distinguishes for-in loops that had zero iterations from those with at
least one, and can use this information to constrain the result of calling
-count after the loop.
In order to make this actually useful, teach the checker that methods on
NSArray, NSDictionary, and the other immutable collection classes don't
change the count.
Jordan Rose [Fri, 8 Nov 2013 01:15:30 +0000 (01:15 +0000)]
[analyzer] Specialize "loop executed 0 times" for for-in and for-range loops.
The path note that says "Loop body executed 0 times" has been changed to
"Loop body skipped when range is empty" for C++11 for-range loops, and to
"Loop body skipped when collection is empty" for Objective-C for-in loops.
ObjectiveC migrator. Fixes an obscure bug where
NS_RETURNS_INNER_POINTER ends up unintentionally
on the @property under -objcmt-migrate-all
// rdar://15396636
Douglas Gregor [Thu, 7 Nov 2013 22:55:02 +0000 (22:55 +0000)]
Modules: Teach the preprocessor to recognize 'import' only after an '@'.
The preprocessor currently recognizes module declarations to load a
module based on seeing the 'import' keyword followed by an
identifier. This sequence is fairly unlikely in C (one would need a
type named 'import'), but is more common in Objective-C (where a
variable named 'import' can cause problems). Since import declarations
currently require a leading '@', recognize that in the preprocessor as
well. Fixes <rdar://problem/15084587>.
Douglas Gregor [Thu, 7 Nov 2013 22:34:54 +0000 (22:34 +0000)]
Re-instate contextual conversion to Objective-C pointers in message sends.
When performing an Objective-C message send to a value of class type,
perform a contextual conversion to an Objective-C pointer type. We've
had this for a long time, but it recently regressed. Fixes
<rdar://problem/15234703>.
Richard Smith [Thu, 7 Nov 2013 20:07:17 +0000 (20:07 +0000)]
PR17800: When performing pack expansion, we must always rebuild the AST nodes
to avoid breaking AST invariants by reusing Stmt nodes within the same
function.
Daniel Jasper [Thu, 7 Nov 2013 17:43:07 +0000 (17:43 +0000)]
clang-format: Remove old hack that mainly made incorrect tests pass.
As a side-effect, constructors definitions will correctly be recognized
and formatted as function declarations. Tests will be added in a
follow-up patch actually using the correct recognition.
Faisal Vali [Thu, 7 Nov 2013 16:57:56 +0000 (16:57 +0000)]
Remove an unnecessary condition that I added hastily: Unsigned numbers are obviously >= 0 ;)
Also - others have complained about some white space issues - sorry about that - continues to be a pain point for me - will try and see what I can do with clang-format this evening after work - as a short term fix, if anyone can email me the files that they have already identified with issues, it would help me speed up a focused fix. sorry.
Faisal Vali [Thu, 7 Nov 2013 05:17:06 +0000 (05:17 +0000)]
This patch implements capturing of variables within generic lambdas.
Both Richard and I felt that the current wording in the working paper needed some tweaking - Please see http://llvm-reviews.chandlerc.com/D2035 for additional context and references to core-reflector messages that discuss wording tweaks.
What is implemented is what we had intended to specify in Bristol; but, recently felt that the specification might benefit from some tweaking and fleshing.
As a rough attempt to explain the semantics: If a nested lambda with a default-capture names a variable within its body, and if the enclosing full expression that contains the name of that variable is instantiation-dependent - then an enclosing lambda that is capture-ready (i.e. within a non-dependent context) must capture that variable, if all intervening nested lambdas can potentially capture that variable if they need to, and all intervening parent lambdas of the capture-ready lambda can and do capture the variable.
Of note, 'this' capturing is also currently underspecified in the working paper for generic lambdas. What is implemented here is if the set of candidate functions in a nested generic lambda includes both static and non-static member functions (regardless of viability checking - i.e. num and type of parameters/arguments) - and if all intervening nested-inner lambdas between the capture-ready lambda and the function-call containing nested lambda can capture 'this' and if all enclosing lambdas of the capture-ready lambda can capture 'this', then 'this' is speculatively captured by that capture-ready lambda.
Hopefully a paper for the C++ committee (that Richard and I had started some preliminary work on) is forthcoming.
This essentially makes generic lambdas feature complete, except for known bugs. The more prominent ones (and the ones I am currently aware of) being:
- generic lambdas and init-captures are broken - but a patch that fixes this is already in the works ...
- nested variadic expansions such as:
auto K = [](auto ... OuterArgs) {
vp([=](auto ... Is) {
decltype(OuterArgs) OA = OuterArgs;
return 0;
}(5)...);
return 0;
};
auto M = K('a', ' ', 1, " -- ", 3.14);
currently cause crashes. I think I know how to fix this (since I had done so in my initial implementation) - but it will probably take some work and back & forth with Doug and Richard.
A warm thanks to all who provided feedback - and especially to Doug Gregor and Richard Smith for their pivotal guidance: their insight and prestidigitation in such matters is boundless!
Now let's hope this commit doesn't upset the buildbot gods ;)
Add the fact that Clang too is planning to start using C++11 (in some
limited ways) after the next release. See the lengthy discussions (which
are on-going) and the corresponding commit to LLVM's release notes.
Nothing is actually changing at this point, this is just further
spreading the plan.
David Majnemer [Wed, 6 Nov 2013 23:31:56 +0000 (23:31 +0000)]
[-fms-extensions] Add support for __FUNCDNAME__
Summary:
Similar to __FUNCTION__, MSVC exposes the name of the enclosing mangled
function name via __FUNCDNAME__. This implementation is very naive and
unoptimized, it is expected that __FUNCDNAME__ would be used rarely in
practice.
Introduce ClangTool::buildASTs, and buildASTFromCode.
These allow clients to retrieve persistent AST objects (ASTUnits) which
can be used in an ad-hoc manner after parsing.
To accommodate this change, the code for processing a CompilerInvocation
using a FrontendAction has been factored out to FrontendActionFactory, and
a new base class, ToolAction, has been introduced, allowing the tool to do
arbitrary things with each CompilerInvocation. This change was necessary
because ASTUnit does not use the FrontendAction interface directly.
This change also causes the FileManager in ClangTool to use shared ownership.
This will become necessary because ASTUnit takes shared ownership of
FileManager (ClangTool's FileManager is currently unused by ASTUnit; this
is a FIXME). As shown in the tests, any client of ToolInvocation will
need to be modified to use shared ownership for FileManager.
Richard Smith [Wed, 6 Nov 2013 19:31:51 +0000 (19:31 +0000)]
Add a limit to the length of a sequence of 'operator->' functions we will
follow when building a class member access expression. Based on a patch by
Rahul Jain!
Richard Smith [Wed, 6 Nov 2013 02:19:10 +0000 (02:19 +0000)]
More constant evaluation cleanup, and fix an issue where we'd override an
earlier 'non-constant' diagnostic with a later one if the earlier one was from
a side-effect we thought we could evaluate past.
ObjectiveC migrator. Please annotation of properties with
NS_RETURNS_INNER_POINTER under -objcmt-returns-innerpointer-property
flag (off by default), as older compilers do not support such annotations.
// rdar://15396636
Richard Smith [Tue, 5 Nov 2013 22:18:15 +0000 (22:18 +0000)]
Refactor constant expression handling and make a couple of tweaks to make it a
bit more robust against future changes. This includes a slight diagnostic
improvement: if we know we're only trying to form a constant expression, take
the first diagnostic which shows the expression is not a constant expression,
rather than preferring the first one which makes the expression unfoldable.
With this patch -Wwrite-strings is still implemented with the terrible
hack of passing -fconst-strings to -cc1, but at least the driver uses
the regular warning checking code path.
Since we don't support a warning that is DefaultIgnore in one language
but not in another, this patch creates a dummy C only warning in the same
group as the existing one to get the desired effect.
James Dennett [Tue, 5 Nov 2013 19:37:38 +0000 (19:37 +0000)]
Documentation tweaks: Fix a typo in a reference to the C++ standard,
another typo in a comment, and update formatting of some comments to
use Doxygen \brief annotations instead of repeating the name of the
documented entity.
Daniel Jasper [Tue, 5 Nov 2013 19:10:03 +0000 (19:10 +0000)]
clang-format: Allow line merging and partial formatting of nested blocks
Before, clang-format would always format entire nested blocks, which
can be unwanted e.g. for long DEBUG({...}) statements. Also
clang-format would not allow to merge lines in nested blocks (e.g. to
put "if (a) return;" on one line in Google style).
This is the first step of several refactorings mostly focussing on the
additional functionality (by reusing the "format many lines" code to
format the children of a nested block). The next steps are:
* Pull out the line merging into its own class.
* Seperate the formatting of many lines from the formatting of a single
line (and the analysis of the solution space).