Anna Zaks [Thu, 21 Jun 2012 20:36:11 +0000 (20:36 +0000)]
[analyzer] Do not step into statements while collecting function decls.
CallGraph's recursive visitor only needs to collect declarations; their
bodies will be processed later on. RecursiveASTVisitor will recurse on
the bodies if the definition is provided along with declaration.
Optimize, by not recursing on any of the statements.
David Blaikie [Thu, 21 Jun 2012 18:51:10 +0000 (18:51 +0000)]
PR13165: False positive when initializing member data pointers with NULL.
This now correctly covers, I believe, all the pointer types:
* 'any' pointers (both function and data normal pointers and ObjC object pointers)
* member pointers (both function and data)
* block pointers
John McCall [Thu, 21 Jun 2012 17:46:38 +0000 (17:46 +0000)]
Adjust this code so that it strictly honors
TargetSimulatroVersionFromDefines if present; this also makes
it easier to chain things correctly. Noted by an internal
review.
Chandler Carruth [Thu, 21 Jun 2012 09:51:42 +0000 (09:51 +0000)]
Clang side of a refactoring of the CMake unit test build strategy.
The fundamental change is to put a CMakeLists.txt file in the unittest
directory, with a single test binary produced from it. This has several
advantages.
Among other fundamental advantages, we start to get the checking logic
for when a file is missing from the CMake build, and this caught one
missing file already! More fun details in the LLVM commit corresponding
to this one.
Note that the LLVM commit and this one most both be applied, or neither.
Sorry for any skew issues.
Alexey Samsonov [Thu, 21 Jun 2012 08:22:39 +0000 (08:22 +0000)]
Improve support for -g options accepted by Clang:
1. Accept flags -g[0-3], -ggdb[0-3], -gdwarf-[2-4] and collapse them to simple -g (except -g0/-ggdb0).
2. Produce driver error on unsupported formats (-gcoff, -gstabs, -gvms) and options (-gtoggle).
3. Recognize and ignore flags -g[no-]strict-dwarf, -g[no-]record-gcc-switches.
Jordan Rose [Thu, 21 Jun 2012 05:54:55 +0000 (05:54 +0000)]
Pretend that enum constants have enum type when inferring a block return type.
In C, enum constants have the type of the enum's underlying integer type,
rather than the type of the enum. (This is not true in C++.) This leads to
odd warnings when returning enum constants directly in blocks with inferred
return types. The easiest way out of this is to pretend that, like C++, enum
constants have enum type when being returned from a block.
Jordan Rose [Thu, 21 Jun 2012 05:54:50 +0000 (05:54 +0000)]
Don't warn for -Wstatic-in-inline if the used function is also inline.
Also, don't warn if the used function is __attribute__((const)), in which case
it's not supposed to use global variables anyway.
The inline-in-inline thing is a heuristic, and one that's possibly incorrect
fairly often because the function being inlined could definitely use global
variables. However, even some C standard library functions are written using
other (trivial) static-inline functions in the headers, and we definitely don't
want to be warning on that (or on anything that /uses/ these trivial inline
functions). So we're using "inlined" as a marker for "fairly trivial".
(Note that __attribute__((pure)) does /not/ guarantee safety like ((const),
because ((const)) does not guarantee that global variables are not being used,
and the warning is about globals not being shared across TUs.)
Chandler Carruth [Thu, 21 Jun 2012 02:04:39 +0000 (02:04 +0000)]
Simplify the Clang unittest function in the CMake build, and make it
match the LLVM implemenation. This also simplifies the name management
and splits the custom library management out from the unittest specific
management. It finally drops the dependency on parsing cmake arguments.
Richard Smith [Thu, 21 Jun 2012 01:08:35 +0000 (01:08 +0000)]
If an object (such as a std::string) with an appropriate c_str() member function
is passed to a variadic function in a position where a format string indicates
that c_str()'s return type is desired, provide a note suggesting that the user
may have intended to call the c_str() member.
Factor the non-POD-vararg checking out of DefaultVariadicArgumentPromotion and
move it to SemaChecking in order to facilitate this. Factor the call checking
out of function call checking and block call checking, and extend it to cover
constructor calls too.
Dmitri Gribenko [Thu, 21 Jun 2012 00:28:14 +0000 (00:28 +0000)]
RawCommentList::addComment: fix the assertion so it actually checks that new comment is after the last one (change Comments[0] to Comments.back()), and handle the case of two consecutive comments, e.g. /** *//* */. There is already a testcase for that (but it didn't trigger the assert because the assert itself was wrong).
objective-c: Normally, a property cannot be both 'readonly' and having a
"write" attribute (copy/retain/etc.). But, property declaration in
primary class and protcols are tentative as they may be overridden
into a 'readwrite' property in class extensions. Postpone diagnosing
such warnings until the class implementation is seen.
// rdar://11656982
John McCall [Wed, 20 Jun 2012 21:58:02 +0000 (21:58 +0000)]
Introduce ObjCRuntime::hasWeakClassImport() and use it in the appropriate
places. I've turned this off for the GNU runtimes --- I don't know if
they support weak class import, but it's easy enough for them to opt in.
James Dennett [Wed, 20 Jun 2012 21:55:51 +0000 (21:55 +0000)]
Documentation cleanup:
* Escape < characters in Doxygen comments as needed;
* Add \code...\endcode around code examples;
* Remove an incorrect use of Doxygen's \arg command.
Added test with sizeof conditions (relies on to-be-implemented functionality of CFG, discussion: http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120507/057370.html)
Jordan Rose [Wed, 20 Jun 2012 21:09:10 +0000 (21:09 +0000)]
Reword -Winternal-linkage-in-inline, and rename it to -Wstatic-in-inline.
Now that this is a C-only warning, we can use "static" instead of "internal
linkage", which is a term developers are probably more familiar with.
This makes for a better warning message. The warning name was changed to match,
since "internal linkage" is not mentioned in the warning text anymore.
James Dennett [Wed, 20 Jun 2012 21:03:59 +0000 (21:03 +0000)]
Documentation cleanup:
* Many fixes for \brief summaries (adding some, and making others shorter);
* Don't try to explicit tell Doxygen a namespace name (and particularly
don't get it wrong);
* Typo fix: instantitions -> instantiations;
* Slightly more use of \pre for documenting preconditions.
Anna Zaks [Wed, 20 Jun 2012 20:57:49 +0000 (20:57 +0000)]
[analyzer] Do not walk the types for call graph construction.
Similar to r156661. This should be beneficial performance wise and
hopefully, resolve a RecursiveASTVisitor crash that we are seeing in the
wild, but are incapable of reproducing.
Anna Zaks [Wed, 20 Jun 2012 20:57:46 +0000 (20:57 +0000)]
[analyzer] Malloc: cleanup, disallow free on relinquished memory.
This commits sets the grounds for more aggressive use after free
checking. We will use the Relinquished sate to denote that someone
else is now responsible for releasing the memory.
Jordan Rose [Wed, 20 Jun 2012 18:50:06 +0000 (18:50 +0000)]
Remove -Winternal-linkage-in-inline in C++.
It's very easy for anonymous external linkage to propagate in C++ through
return types and parameter types. Likewise, it's possible that a template
containing an inline function is only used with parameters that have internal
linkage. Actually diagnosing where the internal linkage comes from is fairly
difficult (both to locate and then to print nicely). Finally, since we only
have one translation unit available, we can't even prove that any of this
violates the ODR.
This warning needs better-defined behavior in C++ before it can really go in.
Rewording of the C warning (which /is/ specified by C99) coming shortly.
Chad Rosier [Wed, 20 Jun 2012 18:28:37 +0000 (18:28 +0000)]
[ms-style asm] Change the fatal error to an extension warning. Apparently, this
error was asserting on anything that included Windows.h. MS-style inline asm is
still dropped, but at least now we're not completely silent about it.
Benjamin Kramer [Wed, 20 Jun 2012 18:11:18 +0000 (18:11 +0000)]
Don't circumvent the debug info type cache when emitting info for EnumConstantDecl.
CreateEnumType doesn't participate in caching so the descriptor for the enum
gets recomputed for every reference of an element of an enum, only to get
discarded when it gets turned into an MDNode.
Chandler Carruth [Wed, 20 Jun 2012 09:53:52 +0000 (09:53 +0000)]
Fix a big layering violation introduced by r158771.
That commit added a new library just to hold the RawCommentList. I've
started a discussion on the commit thread about whether that is really
meritted -- it certainly doesn't seem necessary at this stage.
However, the immediate problem is that the AST library has a hard
dependency on the Comment library, but the dependencies were set up
completely backward. In addition to the layering violation, this had an
unfortunate effect if scattering the Comments library dependency
throughout the build system, but inconsistently so -- several parts of
the CMake dependencies were missing and only showed up due to transitive
deps or the fact that the target wasn't being built by tho bots.
It turns out that the Comments library can't (currently) be a well
formed layer *below* the AST library either, as it has an API that
accepts an ASTContext. That parameter is currently unused, so maybe that
was a mistake?
Anyways, it really seems like this is logically part of the AST --
that's the whole point of the ASTContext providing access to it as far
as I can tell -- so I've merged it into the AST library to solve the
immediate layering violation problems and remove some of the churn from
our library dependencies.
Ted Kremenek [Wed, 20 Jun 2012 07:03:37 +0000 (07:03 +0000)]
Revert "Provide a -no-pedantic to cancel out -pedantic." This needs to be designed
a bit further. We may wish to just have -Wno flags to silence warnings, and not have a -no-pedantic.
John McCall [Wed, 20 Jun 2012 06:18:46 +0000 (06:18 +0000)]
Restructure how the driver communicates information about the
target Objective-C runtime down to the frontend: break this
down into a single target runtime kind and version, and compute
all the relevant information from that. This makes it
relatively painless to add support for new runtimes to the
compiler. Make the new -cc1 flag, -fobjc-runtime=blah-x.y.z,
available at the driver level as a better and more general
alternative to -fgnu-runtime and -fnext-runtime. This new
concept of an Objective-C runtime also encompasses what we
were previously separating out as the "Objective-C ABI", so
fragile vs. non-fragile runtimes are now really modelled as
different kinds of runtime, paving the way for better overall
differentiation.
As a sort of special case, continue to accept the -cc1 flag
-fobjc-runtime-has-weak, as a sop to PLCompatibilityWeak.
I won't go so far as to say "no functionality change", even
ignoring the new driver flag, but subtle changes in driver
semantics are almost certainly not intended.
Jordan Rose [Wed, 20 Jun 2012 05:34:32 +0000 (05:34 +0000)]
[analyzer] Move failing 'new' test cases back into new.cpp instead of XFAILing.
Per Anna's comment, this is a better way to handle "to-do list"-type failures.
This way we'll know if any of the features get fixed; in an XFAIL file, /all/
the cases have to be fixed before lit would tell us anything.
Jordan Rose [Wed, 20 Jun 2012 01:32:01 +0000 (01:32 +0000)]
[analyzer] Invalidate placement args; return the pointer given to placement new
The default global placement new just returns the pointer it is given.
Note that other custom 'new' implementations with placement args are not
guaranteed to do this.
In addition, we need to invalidate placement args, since they may be updated by
the allocator function. (Also, right now we don't properly handle the
constructor inside a CXXNewExpr, so we need to invalidate the placement args
just so that callers know something changed!)
This invalidation is not perfect because CallOrObjCMessage doesn't support
CXXNewExpr, and all of our invalidation callbacks expect that if there's no
CallOrObjCMessage, the invalidation is happening manually (e.g. by a direct
assignment) and shouldn't affect checker-specific metadata (like malloc state);
hence the malloc test case in new-fail.cpp. But region values are now
properly invalidated, at least.
The long-term solution to this problem is to rework CallOrObjCMessage into
something more general, rather than the morass of branches it is today.
James Dennett [Wed, 20 Jun 2012 00:56:32 +0000 (00:56 +0000)]
Documentation cleanup:
* Escaped # and < characters in Doxygen comments as needed;
* Removed a Doxygen comment in HeaderSearch.cpp that was redundant with
the corresponding comment in the header file.
James Dennett [Wed, 20 Jun 2012 00:50:53 +0000 (00:50 +0000)]
Documentation cleanup:
* Escape < characters in Doxygen comments as needed;
* Demote one Doxygen comment to a regular comment to fix a Doxygen warning.
Kaelyn Uhrain [Wed, 20 Jun 2012 00:36:03 +0000 (00:36 +0000)]
Add the PCH file name to the message about not being able to read the PCH.
Also add a couple of unit tests to check the invalid-PCH error messages
to satisfy PR4568 and for the assertion (introduced in r149918 and fixed
in r158769) that would cause clang to crash when given an empty PCH.
Dmitri Gribenko [Wed, 20 Jun 2012 00:34:58 +0000 (00:34 +0000)]
Structured comment parsing, first step.
* Retain comments in the AST
* Serialize/deserialize comments
* Find comments attached to a certain Decl
* Expose raw comment text and SourceRange via libclang
Sean Hunt [Tue, 19 Jun 2012 23:57:03 +0000 (23:57 +0000)]
Reapply r158700 and fixup patches, minus one hunk that slipped through and
caused a crash in an obscure case. On the plus side, it caused me to catch
another bug by inspection.
Tanya Lattner [Tue, 19 Jun 2012 23:09:52 +0000 (23:09 +0000)]
Extend the support for cl-std to include 1.2.
Add error checking for the static qualifier which is now allowed in certain situations for OpenCL 1.2. Use the CL version to turn on this feature.
Added test case for 1.2 static storage class feature.
objective-c: warn when autosynthesizing a property which has same
name as an existing ivar since this is common source of error
when people remove @synthesize to take advantage of autosynthesis.
// rdar://11671080
Richard Smith [Tue, 19 Jun 2012 21:28:35 +0000 (21:28 +0000)]
Fix -Wc++11-narrowing warnings for narrowing negative values to larger unsigned
types to actually includes the value, rather than saying <uninitialized>.
objc-arc: captured block variable accessed in its block literal
initializer need be null initialized before initializer takes
hold, just like any other initialized retainable object pointer.
// rdar://11016025
Meador Inge [Tue, 19 Jun 2012 18:17:30 +0000 (18:17 +0000)]
Revert predefined decl tracking.
r158085 added some logic to track predefined declarations. The main reason we
had predefined declarations in the input was because the __builtin_va_list
declarations were injected into the preprocessor input. As of r158592 we
explicitly build the __builtin_va_list declarations. Therefore the predefined
decl tracking is no longer needed.
Chad Rosier [Tue, 19 Jun 2012 17:48:02 +0000 (17:48 +0000)]
[driver] Make the crash diagnostic message more visable. Bug reports are being
filed, but still missing the preprocessed source and associated run script.
rdar://11684107
Sean Hunt [Tue, 19 Jun 2012 03:39:03 +0000 (03:39 +0000)]
Improve the specification of spellings in Attr.td.
Note that this is mostly a structural patch that handles the change from the old
spelling style to the new one. One consequence of this is that all AT_foo_bar
enum values have changed to not be based off of the first spelling, but rather
off of the class name, so they are now AT_FooBar and the like (a straw poll on
IRC showed support for this). Apologies for code churn.
Most attributes have GNU spellings as a temporary solution until everything else
is sorted out (such as a Keyword spelling, which I intend to add if someone else
doesn't beat me to it). This is definitely a WIP.
I've also killed BaseCheckAttr since it was unused, and I had to go through
every attribute anyway.
[objcmt] When checking whether the subscripting methods are declared use
ObjCInterfaceDec::lookupInstanceMethod to make sure we check categories as well
and update related tests.
Rafael Espindola [Tue, 19 Jun 2012 01:26:10 +0000 (01:26 +0000)]
Add a -fuse-init-array option to cc1 and map to the UseInitArray target
option. On the driver, check if we are using libraries from gcc 4.7 or newer
and if so pass -fuse-init-array to the frontend.
The crtbegin*.o files in gcc 4.7 no longer call the constructors listed in
.ctors, so we have to use .init_array.
Kaelyn Uhrain [Tue, 19 Jun 2012 00:37:47 +0000 (00:37 +0000)]
Improve the error message when a function overload candidate is rejected
because it expects a reference and receives a non-l-value.
For example, given:
int foo(int &);
template<int x> void b() { foo(x); }
clang will now print "expects an l-value for 1st argument" instead of
"no known conversion from 'int' to 'int &' for 1st argument". The change
in wording (and associated code to detect the case) was prompted by
comment #5 in PR3104, and should be the last bit of work needed for the
bug.
Ted Kremenek [Tue, 19 Jun 2012 00:37:39 +0000 (00:37 +0000)]
Sink definition of IBOutlet, IBOutletCollection, and IBAction into
the compiler predefines buffer. These are essentially part of
the Objective-C language.
Jordan Rose [Mon, 18 Jun 2012 23:58:49 +0000 (23:58 +0000)]
Change -Winternal-linkage-in-inline from ExtWarn to Warning in C++.
Per post-commit review, it's not appropriate to use ExtWarn in C++, because
we can't prove that the inline function will actually be defined in more than
one place (and thus we can't prove that this violates the ODR).
This removes the warning entirely from uses in the main source file in C++.
Jordan Rose [Mon, 18 Jun 2012 22:09:19 +0000 (22:09 +0000)]
Support -Winternal-linkage-in-inline in C++ code.
This includes treating anonymous namespaces like internal linkage, and allowing
const variables to be used even if internal. The whole thing's been broken out
into a separate function to avoid nested ifs.
Jordan Rose [Mon, 18 Jun 2012 21:31:37 +0000 (21:31 +0000)]
Add new tool 'diag-build' for showing enabled warnings in a project.
diag-build acts as a wrapper for 'diagtool show-enabled', in the same way
that scan-build acts as a wrapper for the static analyzer. The common case is
simple: use 'diag-build make' or 'diag-build xcodebuild' to list the warnings
enabled for the first compilation command we see. Other build systems require
you to manually specify "dry-run" and "use $CC and $CXX"; if there is a build
system you are interested in, please add it to the switch statement.
diag-build is fairly stupid right now, but it serves its basic purpose.
Hopefully it can grow to meet any additional requirements.