Tom Care [Fri, 18 Jun 2010 03:02:16 +0000 (03:02 +0000)]
Printf format strings: Added some more tests and fixed some minor bugs.
- Precision toStrings shouldn't print a dot when they have no value.
- Length of char length modifier is now returned correctly.
- Added several fixit tests.
Note: fixit tests are currently broken due to a bug in HighlightRange. Marking as XFAIL for now.
M test/Sema/format-strings-fixit.c
M include/clang/Analysis/Analyses/PrintfFormatString.h
M lib/Analysis/PrintfFormatString.cpp
Douglas Gregor [Thu, 17 Jun 2010 23:14:26 +0000 (23:14 +0000)]
Given Decl::isUsed() a flag indicating when to consider the "used"
attribute as part of the calculation. Sema::MarkDeclReferenced(), and
a few other places, want only to consider the "used" bit to determine,
e.g, whether to perform template instantiation. Fixes a linkage issue
with Boost.Serialization.
objective-C++ IRGen: property reference as an
lvalue when performing a derived-to-base conversion.
Fixes radar 7501812. Added an executable test to
llvm-test suite.
Zhanyong Wan [Thu, 17 Jun 2010 20:56:31 +0000 (20:56 +0000)]
Improves RecursiveASTVisitor:
* refactors code in DEF_TRAVERSE_DECL() into
TraverseDeclContextHelper() to reduce code bloat and facilitate
reuse.
* makes the order of traversing a FunctionDecl (including its
subclasses)'s children more natural: before the function parameters
are visited after the function body; now they are visited after the
function type and before the function body.
* fixes a double count for function return type and arguments.
Tom Care [Thu, 17 Jun 2010 19:00:27 +0000 (19:00 +0000)]
Bug 7377: Fixed several bad printf format string bugs.
- Added warning for undefined behavior when using field specifier
- Added warning for undefined behavior when using length modifier
- Fixed warnings for invalid flags
- Added warning for ignored flags
- Added fixits for the above warnings
- Fixed accuracy of detecting several undefined behavior conditions
- Receive normal warnings in addition to security warnings when using %n
- Fix bug where '+' flag would remain on unsigned conversion suggestions
Summary of changes:
- Added expanded tests
- Added/expanded warnings
- Added position info to OptionalAmounts for fixits
- Extracted optional flags to a wrapper class with position info for fixits
- Added several methods to validate a FormatSpecifier by component, each checking for undefined behavior
- Fixed conversion specifier checking to conform to C99 standard
- Added hooks to detect the invalid states in CheckPrintfHandler::HandleFormatSpecifier
Note: warnings involving the ' ' (space) flag are temporarily disabled until whitespace highlighting no longer triggers assertions. I will make a post about this on cfe-dev shortly.
M test/Sema/format-strings.c
M include/clang/Basic/DiagnosticSemaKinds.td
M include/clang/Analysis/Analyses/PrintfFormatString.h
M lib/Analysis/PrintfFormatString.cpp
M lib/Sema/SemaChecking.cpp
Douglas Gregor [Thu, 17 Jun 2010 16:03:49 +0000 (16:03 +0000)]
When pushing a copy of the TypeLoc information for a dependent
template specialization type, copy the location information but use
the new type. Fixes PR7385.
Douglas Gregor [Thu, 17 Jun 2010 15:46:20 +0000 (15:46 +0000)]
Use UnaryOperator as the representation of dependent expressions when
no overloaded operators were found in scope, mirroring what we already
do for BinaryOperator.
Some fixes to type-visiting -- a few places where the type-name was
explicitly typed in the source, but we weren't recursing on it. One
is new <type>, the other is <type>() (eg int()).
I also fixed the initializer parsing to parse on the syntactic
initializer list, not the semantic. Usually they'll be identical, so
this won't affect much in practice, but keeps the AST as a syntax-tree
visitor.
Make sure parens/braces/brackets are correctly balanced.
In a line like:
(;
the semicolon leaves Parser:ParenCount unbalanced (it's 1 even though we stopped looking for a right paren).
This may affect later parsing and result in bad recovery for parsing errors.
Ted Kremenek [Thu, 17 Jun 2010 04:21:37 +0000 (04:21 +0000)]
Tweak stack address checker to report multiple cases where globals may reference stack memory.
Also refactor the diagnostics so that we print out the kind of stack memory returned.
Nate Begeman [Thu, 17 Jun 2010 04:17:01 +0000 (04:17 +0000)]
Generate arm_neon.inc in include/clang/Basic, which provides:
1. builtins definitions for BuiltinsARM.def
2. intrinsic validation code for SemaChecking
Unsure as to whether this is the best way to handle the make dependencies or not.
Ted Kremenek [Thu, 17 Jun 2010 00:59:17 +0000 (00:59 +0000)]
Per conversation with Doug, remove two assertions in ParseLexedMethodDefs() that
didn't indicate violated invariants but that we weren't recovering well.
Ted Kremenek [Thu, 17 Jun 2010 00:24:44 +0000 (00:24 +0000)]
Rework StackAddrLeakChecker to find stores of stack memory addresses to global variables
by inspecting the Store bindings instead of iterating over all the global variables
in a translation unit. By looking at the store directly, we avoid cases where we cannot
directly load from the global variable, such as an array (which can result in an assertion failure)
and it also catches cases where we store stack addresses to non-scalar globals.
Also, but not iterating over all the globals in the translation unit, we maintain cache
locality, and the complexity of the checker becomes restricted to the complexity of the
analyzed function, and doesn't scale with the size of the translation unit.
Ted Kremenek [Thu, 17 Jun 2010 00:24:42 +0000 (00:24 +0000)]
Implement RegionStoreManager::iterBindings(). This implementation only returns the base region in
the binding key instead of the region + offset. It isn't clear if this is the best semantics, but most
clients will likely only care about simple bindings, or bindings to a particular variable. We can
refine later if necessary.
Douglas Gregor [Wed, 16 Jun 2010 23:45:56 +0000 (23:45 +0000)]
When parsing cached C++ method declarations/definitions, save the
"previous token" location at the end of the class definition. This
eliminates a badly-placed error + Fix-It when the ';' following a
class definition is missing. Fixes <rdar://problem/8066414>.
Sean Hunt [Wed, 16 Jun 2010 23:43:53 +0000 (23:43 +0000)]
Implement first TD-based usage of attributes.
Currently, there are two effective changes:
- Attr::Kind has been changed to attr::Kind, in a separate namespace
rather than the Attr class. This is because the enumerator needs to
be visible to parse.
- The class definitions for the C++0x attributes other than aligned are
generated by TableGen.
The specific classes generated by TableGen are controlled by an array in
TableGen (see the accompanying commit to the LLVM repository). I will be
expanding the amount of code generated as I develop the new attributes system
while initially keeping it confined to these attributes.
Douglas Gregor [Wed, 16 Jun 2010 23:00:59 +0000 (23:00 +0000)]
When we see a 'template' disambiguator that marks the next identifier
(or operator-function-id) as a template, but the context is actually
non-dependent or the current instantiation, allow us to use knowledge
of what kind of template it is, e.g., type template vs. function
template, for further syntactic disambiguation. This allows us to
parse properly in the presence of stray "template" keywords, which is
necessary in C++0x and it's good recovery in C++98/03.
Douglas Gregor [Wed, 16 Jun 2010 22:31:08 +0000 (22:31 +0000)]
Fix the recently-added warning about 'typename' and 'template'
disambiguation keywords outside of templates in C++98/03. Previously,
the warning would fire when the associated nested-name-specifier was
not dependent, but that was a misreading of the C++98/03 standard:
now, we complain only when we're outside of any template.
Douglas Gregor [Wed, 16 Jun 2010 21:09:37 +0000 (21:09 +0000)]
Canonicalize template template parameters when canonicalizing a
template name that refers to such a parameter. It's amazing that this
problem didn't surface earlier. Fixes PR7387.
Douglas Gregor [Wed, 16 Jun 2010 16:26:47 +0000 (16:26 +0000)]
Downgrade the error when using a typedef in the nested-name-specifier
of an explicit instantiation to an ExtWarn, since nobody else seems to
diagnose this problem.
Douglas Gregor [Wed, 16 Jun 2010 16:03:14 +0000 (16:03 +0000)]
If a non-dependent base class initializer fails to match any direct or
virtual base class, but the class still has dependent base classes,
then don't diagnose the failed match as an error: the right base class
might magically appear. Fixes PR7259.
John McCall [Wed, 16 Jun 2010 08:42:20 +0000 (08:42 +0000)]
Fix a point of semantics with using declaration hiding: method templates
introduced by using decls are hidden even if their template parameter lists
or return types differ from the "overriding" declaration.
Propagate using shadow declarations around more effectively when looking up
template-ids. Reperform lookup for template-ids in member expressions so that
access control is properly set up.
Fix some number of latent bugs involving template-ids with totally invalid
base types. You can only actually get these with a scope specifier, since
otherwise the template-id won't parse as a template-id.
Douglas Gregor [Wed, 16 Jun 2010 00:35:25 +0000 (00:35 +0000)]
Give Type::isIntegralType() an ASTContext parameter, so that it
provides C "integer type" semantics in C and C++ "integral type"
semantics in C++.
Note that I still need to update isIntegerType (and possibly other
predicates) using the same approach I've taken for
isIntegralType(). The two should have the same meaning, but currently
don't (!).
Douglas Gregor [Wed, 16 Jun 2010 00:17:44 +0000 (00:17 +0000)]
Introduce Type::isIntegralOrEnumerationType(), to cover those places
in C++ that involve both integral and enumeration types. Convert all
of the callers to Type::isIntegralType() that are meant to work with
both integral and enumeration types over to
Type::isIntegralOrEnumerationType(), to prepare to eliminate
enumeration types as integral types.
Jeffrey Yasskin [Tue, 15 Jun 2010 23:50:08 +0000 (23:50 +0000)]
Describe a gcc compatibility problem that occurs when a template calls a
function defined between its declaration and an instantiation, and that
function isn't findable through ADL.
Patch adds support for copying of those
objective-c++ class objects which have GC'able objc object
pointers and need to use ObjC's objc_memmove_collectable
API (radar 8070772).
Douglas Gregor [Tue, 15 Jun 2010 21:38:40 +0000 (21:38 +0000)]
Update equality and relationship comparisons of pointers to reflect
C++ semantics, eliminating an extension diagnostic that doesn't match
C++ semantics (ordered comparison with NULL) and tightening some
extwarns to errors in C++ to match GCC and maintain conformance in
SFINAE contexts. Fixes <rdar://problem/7941392>.
Chris Lattner [Tue, 15 Jun 2010 18:06:43 +0000 (18:06 +0000)]
Remove a dead argument to ProcessUCNEscape.
Fix string concatenation to treat escapes in concatenated strings that
are wide because of other string chunks to process the escapes as wide
themselves. Before we would warn about and miscompile the attached testcase.
This fixes rdar://8040728 - miscompile + warning: hex escape sequence out of range
Daniel Dunbar [Tue, 15 Jun 2010 17:48:49 +0000 (17:48 +0000)]
Break Frontend's dependency on Rewrite, Checker and CodeGen in shared library configuration
Currently, all AST consumers are located in the Frontend library,
meaning that in a shared library configuration, Frontend has a
dependency on Rewrite, Checker and CodeGen. This is suboptimal for
clients which only wish to make use of the frontend. CodeGen in
particular introduces a large number of unwanted dependencies.
This patch breaks the dependency by moving all AST consumers with
dependencies on Rewrite, Checker and/or CodeGen to their respective
libraries. The patch therefore introduces dependencies in the other
direction (i.e. from Rewrite, Checker and CodeGen to Frontend).
After applying this patch, Clang builds correctly using CMake and
shared libraries ("cmake -DBUILD_SHARED_LIBS=ON").
N.B. This patch includes file renames which are indicated in the
patch body.
Changes in this revision of the patch:
- Fixed some copy-paste mistakes in the header files
- Modified certain aspects of the coding to comply with the LLVM
Coding Standards
Sean Hunt [Tue, 15 Jun 2010 02:36:48 +0000 (02:36 +0000)]
MinGW requires that wint_t be defined in stddef.h. In order to accomodate, we
won't define it unless specifically requested via the use of __need_wint_t.
Douglas Gregor [Mon, 14 Jun 2010 23:15:08 +0000 (23:15 +0000)]
Add name mangling for address spaces. We use the vendor-extension
mangling for types, where the <source-name> is ASxxx (xxx is the
address-space number).