Akira Hatanaka [Mon, 9 Jan 2012 19:08:06 +0000 (19:08 +0000)]
Move the piece of code up that skips the padding argument. Without this change,
padding insertion will not work if the coerced type is not a structure.
Douglas Gregor [Mon, 9 Jan 2012 18:07:24 +0000 (18:07 +0000)]
When deserializing an anonymous namespace from a module, do not attach
the anonymous namespace to its parent. Semantically, this means that
the anonymous namespaces defined in one module are distinct from the
anonymous namespaces defined in another module.
Douglas Gregor [Mon, 9 Jan 2012 17:30:44 +0000 (17:30 +0000)]
Implement redeclaration merging for namespaces defined in distinct
modules. Teach name lookup into namespaces to search in each of the
merged DeclContexts as well as the (now-primary) DeclContext. This
supports the common case where two different modules put something
into the same namespace.
Douglas Gregor [Mon, 9 Jan 2012 15:36:04 +0000 (15:36 +0000)]
Always allow redefinition of typedefs when modules are enabled. This
is important because it's fairly common for headers (especially system
headers) to want to provide only those typedefs needed for that
particular header, based on some guard macro, e.g.,
#ifndef _SIZE_T
#define _SIZE_T
typedef long size_t;
#endif
which is repeated in a number of headers. The guard macro protects
against duplicate definitions. However, this means that only the first
occurrence of this pattern actually defines size_t, so the submodule
corresponding to this header has the only visible definition. If a
user then imports a different submodule from the same module, size_t
will be known but not visible, and therefore cannot be used.
By allowing redefinition of typedefs, each header that wants to define
size_t can do so independently, so it will be available in the
corresponding submodules.
Anna Zaks [Sat, 7 Jan 2012 16:49:46 +0000 (16:49 +0000)]
[analyzer] Fix use-after-free in HandleTranslationUnit.
A patch by Dmitri Gribenko!
The attached patch fixes a use-after-free in AnalysisConsumer::HandleTranslationUnit. The problem is that
BugReporter's destructor runs after AnalysisManager has been already
deleted. The fix introduces a scope to force correct destruction
order.
A crash happens only when reports have been added in AnalysisConsumer::HandleTranslationUnit's BugReporter. We don't have such checkers in clang so no test.
Douglas Gregor [Sat, 7 Jan 2012 09:11:48 +0000 (09:11 +0000)]
Switch NamespaceDecl from its own hand-rolled redeclaration chain over
to Redeclarable<NamespaceDecl>, so that we benefit from the improveed
redeclaration deserialization and merging logic provided by
Redeclarable<T>. Otherwise, no functionality change.
As a drive-by fix, collapse the "inline" bit into the low bit of the
original namespace/anonymous namespace, saving 8 bytes per
NamespaceDecl on x86_64.
Eli Friedman [Sat, 7 Jan 2012 04:59:52 +0000 (04:59 +0000)]
More lambda work: semantic analysis of capturing 'this'. It's a bit complicated, but we have to be careful about when exactly captures are marked given PotentiallyPotentiallyEvaluated contexts. (Actually, it's not 100% correct yet, but it's close enough for the moment.)
Anna Zaks [Sat, 7 Jan 2012 02:33:10 +0000 (02:33 +0000)]
[analyzer] Add basic format string vulnerability checking.
We already have a more conservative check in the compiler (if the
format string is not a literal, we warn). Still adding it here for
completeness and since this check is stronger - only triggered if the
format string is tainted.
Akira Hatanaka [Sat, 7 Jan 2012 00:25:33 +0000 (00:25 +0000)]
Add field PaddingType to ABIArgInfo which specifies the type of padding that
is inserted before the real argument. Padding is needed to ensure the backend
reads from or writes to the correct argument slots when the original alignment
of a byval structure is unavailable due to flattening.
objc++: more code gen stuff for atomic property api,
currently turned off. // rdar://6137845
Also, fixes a test case which should be nonatomic under
new API.
Ted Kremenek [Fri, 6 Jan 2012 22:09:28 +0000 (22:09 +0000)]
[analyzer] Make the entries in 'Environment' context-sensitive by making entries map from
(Stmt*,LocationContext*) pairs to SVals instead of Stmt* to SVals.
This is needed to support basic IPA via inlining. Without this, we cannot tell
if a Stmt* binding is part of the current analysis scope (StackFrameContext) or
part of a parent context.
This change introduces an uglification of the use of getSVal(), and thus takes
two steps forward and one step back. There are also potential performance implications
of enlarging the Environment. Both can be addressed going forward by refactoring the
APIs and optimizing the internal representation of Environment. This patch
mainly introduces the functionality upon when we want to build upon (and clean up).
Douglas Gregor [Fri, 6 Jan 2012 22:05:37 +0000 (22:05 +0000)]
During name lookup, use redecl_iterator to walk over the redeclaration
chain to determine whether any declaration of the given entity is
visible, eliminating the redundant (and less efficient)
getPreviousDeclaration() implementation.
This tweak uncovered an omission in the handling of
RedeclarableTemplateDecl, where we weren't making sure to search for
additional redeclarations of a template in other module files. Things
would be cleaner if RedeclarableTemplateDecl actually used Redeclarable.
Douglas Gregor [Fri, 6 Jan 2012 17:19:32 +0000 (17:19 +0000)]
When inferring a submodule ID during module creation, look up the
include stack to find the first file that is known to be part of the
module. This copes with situations where the module map doesn't
completely specify all of the headers that are involved in the module,
which can come up when there are very strange #include_next chains
(e.g., with weird compiler/stdlib headers like stdarg.h or float.h).
Douglas Gregor [Fri, 6 Jan 2012 16:59:53 +0000 (16:59 +0000)]
Stash Decl's TopLevelDeclInObjCContainer and ModulePrivate bits
into the two unused lower bits of the NextDeclInContext link, dropping
the number of bits in Decl down to 32, and saving 8 bytes per
declaration on x86-64.
Richard Smith [Fri, 6 Jan 2012 16:39:00 +0000 (16:39 +0000)]
C++11 generalized constant expressions: implement checking and diagnostics for
pointer-arithmetic-related undefined behavior and unspecified results. We
continue to fold such values, but now notice they aren't constant expressions.
Douglas Gregor [Fri, 6 Jan 2012 16:22:39 +0000 (16:22 +0000)]
Introduce a "Hidden" bit into Decl, to track whether that declaration
is hidden from name lookup. The previous hack of tweaking the
ModulePrivate bit when loading a declaration from a hidden submodule
was brittle.
Note that we now have 34 bits in Decl. I'll fix that next.
Improvements to the uninitialized variable warning: Check if the constructor
call is elidable or if the constructor is trivial instead of checking if it
is user declared.
Richard Smith [Fri, 6 Jan 2012 01:31:20 +0000 (01:31 +0000)]
Tweak to r147599 for PR10828: Move the check from the parser into sema, and use
the Semantic Powers to only warn on class types (or dependent types), where the
constructor or destructor could do something interesting.
objc++: sythesize a helper function to be used
for copying atomic properties of c++ objects
with non-trivial copy assignment in setters/getters.
Not yet used. // rdar://6137845
Douglas Gregor [Thu, 5 Jan 2012 22:33:30 +0000 (22:33 +0000)]
Don't seed the ASTWriter's declaration -> ID mapping with the IDs of
each deserialized declaration, since that information is already
available in each declaration.
Douglas Gregor [Thu, 5 Jan 2012 22:27:05 +0000 (22:27 +0000)]
When we deserialize a declaration from a module file, allocate extra
storage for the global declaration ID. Declarations that are parsed
(rather than deserialized) are unaffected, so the number of
declarations that pay this cost tends to be relatively small (since
relatively few declarations are ever deserialized).
This replaces a largish DenseMap within the AST reader. It's not
strictly a win in terms of memory use---not every declaration was
added to that DenseMap in the first place---but it's cleaner to have
this information available for every deserialized declaration, so that
future clients can rely on it.
Douglas Gregor [Thu, 5 Jan 2012 21:55:30 +0000 (21:55 +0000)]
When creating declarations that are deserialized from an module file,
go through a central allocation routine
Decl::AllocateDeserializedDecl(). No actual functionality change (yet).
Richard Smith [Thu, 5 Jan 2012 04:12:21 +0000 (04:12 +0000)]
PR10828: Produce a warning when a no-arguments function is declared in block
scope, when no other indication is provided that the user intended to declare a
function rather than a variable.
Remove some false positives from the existing 'parentheses disambiguated as a
function' warning by suppressing it when the declaration is marked as 'typedef'
or 'extern'.
Add a new warning group -Wvexing-parse containing both of these warnings.
The new warning is enabled by default; despite a number of false positives (and
one bug) in clang's test-suite, I have only found genuine bugs with it when
running it over a significant quantity of real C++ code.
Eli Friedman [Thu, 5 Jan 2012 03:35:19 +0000 (03:35 +0000)]
More lambda work. Tweak the Sema interface slightly. Start adding the pieces to build the lambda class and its call operator. Create an actual scope for the lambda body.
Douglas Gregor [Thu, 5 Jan 2012 01:11:47 +0000 (01:11 +0000)]
When we're performing name lookup for a tag, we still allow ourselves
to see hidden declarations because every tag lookup is effectively a
redeclaration lookup. For example, image that
struct foo;
is declared in a submodule that is known but hasn't been imported. If
someone later writes
struct foo *foo_p;
then "struct foo" is either a reference or a redeclaration. To keep
the redeclaration chains sound, we treat it like a redeclaration for
name-lookup purposes.
Fixes a code gen bug for setter code for a property of
c++ object reference type with trivial copy constructor.
This causes an assert crash and bad code gen. when assert
is off. // rdar://6137845
Douglas Gregor [Thu, 5 Jan 2012 00:04:05 +0000 (00:04 +0000)]
When generating includes for all of the headers we found in an
umbrella directory, skip includes for any headers that are part of an
unavailable module.
Anna Zaks [Wed, 4 Jan 2012 23:54:01 +0000 (23:54 +0000)]
[analyzer] Be less pessimistic about invalidation of global variables
as a result of a call.
Problem:
Global variables, which come in from system libraries should not be
invalidated by all calls. Also, non-system globals should not be
invalidated by system calls.
Solution:
The following solution to invalidation of globals seems flexible enough
for taint (does not invalidate stdin) and should not lead to too
many false positives. We split globals into 3 classes:
* immutable - values are preserved by calls (unless the specific
global is passed in as a parameter):
A : Most system globals and const scalars
* invalidated by functions defined in system headers:
B: errno
* invalidated by all other functions (note, these functions may in
turn contain system calls):
B: errno
C: all other globals (which are not in A nor B)
Douglas Gregor [Wed, 4 Jan 2012 23:32:19 +0000 (23:32 +0000)]
Store the submodules of a module in source order, as they are stored
in the module map. This provides a bit more predictability for the
user, as well as eliminating the need to sort the submodules when
serializing them.
objc: When issuing warning for missing synthesis for
properties in classes declared with objc_suppress_autosynthesis
attribute, pinpoint location of the said class in a note.
Eli Friedman [Wed, 4 Jan 2012 23:13:47 +0000 (23:13 +0000)]
Add an APValue representation for the difference between two address-of-label expressions. Add support to Evaluate and CGExprConstant for generating/handling them. Remove the special-case for such differences in Expr::isConstantInitializer.
With that done, remove a bunch of buggy code from CGExprConstant for handling scalar expressions which is no longer necessary.
Douglas Gregor [Wed, 4 Jan 2012 21:16:09 +0000 (21:16 +0000)]
Add __has_feature(modules) to indicate when modules are available (in
any language variant), and restrict __has_feature(objc_modules) to
mean that we also have the Objective-C @import syntax. I anticipate
__has_feature(cxx_modules) and/or __has_feature(c_modules) for when we
nail down the module syntax for C/C++.
Douglas Gregor [Wed, 4 Jan 2012 17:13:46 +0000 (17:13 +0000)]
Implement declaration merging for non-template functions from
different modules. This implementation is a first approximation of
what we want, using only the function type to determine
equivalence. Later, we'll want to deal with some of the more subtle
issues, including:
- C allows a prototyped declaration and a non-prototyped declaration
to be merged, which we should support
- We may want to ignore the return type when merging, then
complain if the return types differ. Or, we may want to leave it
as it us, so that we only complain if overload resolution
eventually fails.
- C++ non-static member functions need to consider cv-qualifiers
and ref-qualifiers.
- Function templates need to consider the template parameters and
return type.
- Function template specializations will have special rules.
- We can now (accidentally!) end up overloading in C, even without
the "overloadable" attribute, and will need to detect this at some
point.
The actual detection of "is this an overload?" is implemented by
Sema::IsOverload(), which will need to be moved into the AST library
for re-use here. That will be a future refactor.
Douglas Gregor [Wed, 4 Jan 2012 16:44:10 +0000 (16:44 +0000)]
Implement declaration merging for typedefs loaded from disjoint
modules, so long as the typedefs refer to the same underlying
type. This ensures that the typedefs end up in the same redeclaration
chain.
To test this, fix name lookup for C/Objective-C to properly deal with
multiple declarations with the same name in the same scope.