Store first and last newline position in the token text for string literals and comments.
Summary:
Store first and last newline position in the token text for string literals and
comments to avoid doing .find('\n') for each possible solution.
Pavel Labath [Mon, 2 Sep 2013 09:09:15 +0000 (09:09 +0000)]
[analyzer] Add very limited support for temporary destructors
This is an improved version of r186498. It enables ExprEngine to reason about
temporary object destructors. However, these destructor calls are never
inlined, since this feature is still broken. Still, this is sufficient to
properly handle noreturn temporary destructors.
Now, the analyzer correctly handles expressions like "a || A()", and executes the
destructor of "A" only on the paths where "a" evaluted to false.
Temporary destructor processing is still off by default and one has to
explicitly request it by setting cfg-temporary-dtors=true.
Switch the default mode for clang-format to '-file'. Make 'LLVM' the
fallback syntax used when we fail to find a '.clang-format' file. Adjust
variable names appropriately.
Update the editor integration pieces that specify a '-style' option to
specify it as '-style=file'. I left the functionality in place because
even if the preferred method is to use '.clang-format' files, this way
if someone needs to clobber the style in their editor we show how to do
so in these examples.
Also check in a '.clang-format' file for Clang to ensure that separate
checkouts and builds of Clang from LLVM can still get the nice
formatting. =] This unfortunately required nuking the test for the
absence of a '.clang-format' file as now the directory happening to be
under your clang source tree will cause there to always be a file. ;]
Richard Trieu [Sat, 31 Aug 2013 03:50:47 +0000 (03:50 +0000)]
The diagnostic err_init_conversion_failed uses the enum
InitializedEntity::EntityKind as an index for one of its %select. Over time,
EntityKind has been expanded, but the diagnostic text has not been updated.
This adds additional text to the %select to cover the new enum values. A
comment has been added to the end of the enum regarding this situation. This
fixes the crasher in PR17043.
ObjectiveC migrator: If we find a method that returns a C pointer
of some sort (but not an object, block pointer or CF pointers),
and is not annotated with the objc_returns_inner_pointer attribute,
we should suggest NS_RETURNS_INNER_POINTER annotation for these methods.
Consumed analysis: add 'consumable' class attribute.
Patch by chris.wailes@gmail.com
Adds the 'consumable' attribute that can be attached to classes. This replaces
the previous method of scanning a class's methods to see if any of them have
consumed analysis attributes attached to them. If consumed analysis attributes
are attached to methods of a class that isn't marked 'consumable' a warning
is generated.
Jordan Rose [Fri, 30 Aug 2013 19:17:26 +0000 (19:17 +0000)]
[analyzer] Treat the rvalue of a forward-declared struct as Unknown.
This will never happen in the analyzed code code, but can happen for checkers
that over-eagerly dereference pointers without checking that it's safe.
UnknownVal is a harmless enough value to get back.
Fixes an issue added in r189590, caught by our internal buildbot.
ObjectiveC migrator: infer NS_ENUM even when user
specified NSUInteger as the followup typedef.
With this change, NS_OPTIONS is only inferred
based on looking up how enumerators are speficied
(if they her hexadecimal, power of 2, or have
bitwise constant expressions).
Samuel Benzaquen [Fri, 30 Aug 2013 15:09:52 +0000 (15:09 +0000)]
Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.
Summary:
Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.
This change reduces the number of sections in Registry.cpp.o by a little over 10%.
Daniel Jasper [Fri, 30 Aug 2013 10:36:58 +0000 (10:36 +0000)]
clang-format: Enable formatting of protocol buffer definitions.
Almost by accident, clang-format seems to be able to format protocol
buffer definitions (https://code.google.com/p/protobuf/).
The only change is that a space is required between numeric constants
and opening square brackets (for default values). While this might in
theory be used for array subscripts (int val = 4[MyArray]), I have not
seen this pattern in practice much. If this is wrong, we can make this
smarter in the future.
Hans Wennborg [Fri, 30 Aug 2013 09:42:06 +0000 (09:42 +0000)]
Revert r188531: "Windows ToolChain: add VS bin dir to PogramPaths"
This never really worked. Even if we find and execute link.exe in the VS bin dir
this way, link.exe wouldn't find the DLLs it needs, libraries, etc.
It also causes trouble when the user has multiple versions of VS installed,
one of them is in the path, but this code finds the other one (PR17041).
Revert until we can fix this properly.
> Windows ToolChain: add VS bin dir to PogramPaths
>
> We have a lot of fancy logic to find Visual Studio, which is currently used
> to set the system header include paths.
>
> Use the same code to set the ProgramPaths, which is used for finding programs
> such as link.exe. Previously, Clang would just search PATH for link.exe,
> but now it should find it if it's able to find Visual Studio.
Pavel Labath [Fri, 30 Aug 2013 08:52:28 +0000 (08:52 +0000)]
Sema: avoid reuse of Exprs when synthesizing operator=
Summary:
Previously, Sema was reusing parts of the AST when synthesizing an assignment
operator, turning it into a AS-dag. This caused problems for the static
analyzer, which assumed an expression appears in the tree only once.
Here I make sure to always create a fresh Expr, when inserting something into
the AST, fixing PR16745 in the process.
Richard Smith [Thu, 29 Aug 2013 23:59:27 +0000 (23:59 +0000)]
Be lazier when loading KeyFunctions from PCH/modules. We don't need to load
these in eagerly if we're not actually processing a translation unit. The added
laziness here also avoids us loading in parts of a CXXRecordDecl earlier than an
upcoming class template specialization merging patch would like.
Ideally, we should mark the vtable as used when we see a definition for the key
function, rather than having a separate pass over dynamic classes at the end of
the TU. The existing approach is pretty bad for PCH/modules, since it forcibly
loads the declarations of all key functions in all imported modules, whether or
not those key functions are defined.
Eli Friedman [Thu, 29 Aug 2013 23:44:43 +0000 (23:44 +0000)]
Adjust clang for change to APFloat::toString.
I changed the diagnostic printing code because it's probably better
to cut off a digit from DBL_MAX than to print something like
1.300000001 when the user wrote 1.3.
Manman Ren [Thu, 29 Aug 2013 23:19:58 +0000 (23:19 +0000)]
Debug Info: generate a unique identifier for C++ struct, class, union, and enum.
We use CXX mangler to generate unique identifier for external C++ struct,
union, class and enum. Types with unique identifier are added to retained
types by DIBuilder.
Testing cases are updated to reflect the unique identifier generated for types.
The order of MDNodes is changed because of retained types and testing cases
are updated accordingly.
Testing case debug-info-uuid.cpp now emits error with Itanium mangler, since
uuid is not yet handled in Itanium mangler. And it will check for the error
message.
Manman Ren [Thu, 29 Aug 2013 20:48:48 +0000 (20:48 +0000)]
Debug Info: this reverts commit r189600.
We had further discussions on how to retain types, whether to do it in front end
or in DIBuilder. And we agree to do it in DIBuilder so front ends
generating unique identifier do not need to worry about retaining them.
Manman Ren [Thu, 29 Aug 2013 18:51:51 +0000 (18:51 +0000)]
Debug Info: generate a unique identifier for C++ struct, class, union, and enum.
We use CXX mangler to generate unique identifier for external C++ struct,
union, class and enum. Types with unique identifier are added to RetainedTypes
to make sure they are treated as used even when all uses are replaced with
the identifiers.
A single type can be added to RetainedTypes multiple times. For example, both
createForwardDecl and createLimitedType can add the same type to RetainedTypes.
A set is used to avoid duplication when updating AllRetainTypes in DIBuilder.
Testing cases are updated to reflect the unique identifier generated for types.
The order of MDNodes is changed because of retained types and testing cases
are updated accordingly.
Testing case debug-info-uuid.cpp now emits error with Itanium mangler, since
uuid is not yet handled in Itanium mangler.
We choose to update RetainedTypes in clang, then at finalize(), we update
AllRetainTypes in DIBuilder. The other choice is to update AllRetainTypes
in DIBuilder when creating a DICompositeType with unique identifier. This
option requires using ValueHandle for AllRetainTypes in DIBuilder since
the created DICompositeType can be modified later on by setContainingType etc.
Consumed analysis: improve handling of conditionals.
Patch by chris.wailes@gmail.com.
* The TestedVarsVisitor was folded into the ConsumedStmtVisitor.
* The VarTestResult class was updated to allow these changes.
* The PropagationInfo class was updated for the same reasons.
* Correctly handle short-circuiting of Boolean operations.
* Blocks are now marked as unreachable when we can statically prove we will
never branch to them.
* Unreachable blocks are skipped by the analysis.
Pavel Labath [Thu, 29 Aug 2013 16:06:04 +0000 (16:06 +0000)]
[analyzer] Fix handling of "empty" structs with base classes
Summary:
RegionStoreManager had an optimization which replaces references to empty
structs with UnknownVal. Unfortunately, this check didn't take into account
possible field members in base classes.
To address this, I changed this test to "is empty and has no base classes". I
don't consider it worth the trouble to go through base classes and check if all
of them are empty.
Samuel Benzaquen [Thu, 29 Aug 2013 15:39:26 +0000 (15:39 +0000)]
Fix tests to be more specific.
The environments can inject some declaration in every translation unit,
which can match very generic matchers, thus failing the tests.
Summary:
Fix tests to be more specific.
The environments can inject some declaration in every translation unit,
which can match very generic matchers, thus failing the tests.
Manuel Klimek [Thu, 29 Aug 2013 15:21:40 +0000 (15:21 +0000)]
Fixes various problems with accounting for tabs in the original code.
We now count the original token's column directly when lexing the
tokens, where we already have all knowledge about where lines start.
Before this patch, formatting:
void f() {
\tg();
\th();
}
would incorrectly count the \t's as 1 character if only the line
containing h() was reformatted, and thus indent h() at offset 1.
Craig Topper [Thu, 29 Aug 2013 06:06:18 +0000 (06:06 +0000)]
Make getDiagnosticsInGroup helper method a static function in the cpp file and move the WarningOption struct into an anonymous namespace instead of clang namespace since it no longer needs to be forward declared in the header.
Craig Topper [Thu, 29 Aug 2013 05:18:04 +0000 (05:18 +0000)]
Move individual group name strings from the OptionTable into one big char array. Then only store offsets into it in the OptionTable. Saves about 4K from the clang binary and removes 400 relocation entries from DiagnosticIDs.o.
Renato Golin [Wed, 28 Aug 2013 23:56:07 +0000 (23:56 +0000)]
use the last passed -munaligned-access / -mno-unaligned-access
Passing inconsistent munaligned-access / mno-unaligned-access
flags, intentionally resulted in a warning and the flag
no-unaligned-access being used.
Gcc does, at least in practice, use the last flag in such a
case. This patch updates clang behaviour accordingly; use the
last flag or base alignment behaviour on the target (which
llvm will do if no flag is explicitly passed)
David Majnemer [Wed, 28 Aug 2013 23:48:32 +0000 (23:48 +0000)]
Sema: Subst type default template args earlier
Summary:
We would not perform substitution at an appropriate point, allowing strange
results to appear. We would accepts things that we shouldn't or mangle things incorrectly. Note that this hasn't fixed the other cases like
template-template parameters or non-type template parameters.
ObjectiveC migrator. This patch infers readonly properties for no-parameter
instance methods returning non-void. This will be quite noisy. So, it is
placed under a new migrator flag -objcmt-migrate-readonly-property.
Rafael Espindola [Wed, 28 Aug 2013 23:17:47 +0000 (23:17 +0000)]
Look for libstdc++ first on the clang install directory.
When sysroot is not set, look for libstdc++ first on the clang install
directory. Before this change if clang was installed alongside a gcc with
the same version as the system one we would select the system libstdc++.
Unfortunately this is hard to test as only the non-sysroot case is changed.
Aaron Ballman [Wed, 28 Aug 2013 23:13:26 +0000 (23:13 +0000)]
Mode is now handled as a non-inheritable attribute, and CUDADevice & CUDAHost are now handled as inheritable attributes. In all three cases, this makes the processing behavior more consistent with the declared behavior in Attr.td.
ObjectiveC migrator: In suggesting 'instancetype' use clang's
hasRelatedResultType() as it knows of methods which have
related result type by default. Such methods do not need
a redundant 'instancetype'.
Manman Ren [Wed, 28 Aug 2013 21:20:28 +0000 (21:20 +0000)]
Debug Info: update interface for CreateEnumType and getOrCreateRecordFwdDecl.
Both functions will take a Type pointer instead of a Decl pointer. This helps
with follow-up type uniquing patches, which need the Type pointer to call
CXX mangler to generate unique identifiers.
Manman Ren [Wed, 28 Aug 2013 21:19:31 +0000 (21:19 +0000)]
Debug Info testing case: update uuid testing case to check against Itanium.
Right now, the output for Itanium vs. Microsoft is the same. Once we start
calling mangler to get the unique identifier, this testing case will require
support for uuid mangling.
For methods where clang automatically infers instancetype from the selector
(e.g., all -init* methods), no need to suggest "instancetype" because it
is redundant.
Eli Friedman [Wed, 28 Aug 2013 20:35:38 +0000 (20:35 +0000)]
Handle -D arguments ending in a backslash.
We translate these into #define directives; to preserve gcc-compatible
semantics (where the expanded macro includes the backslash), we add
an extra "\\\n" to the end of the synthesized "#define".
Samuel Benzaquen [Wed, 28 Aug 2013 18:42:04 +0000 (18:42 +0000)]
Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
Summary:
Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
These function require some late binding behavior for the type conversions, thus changes in VariadicValue's MatcherList.
Second try. This time with a fix for C++11 builds.
Manman Ren [Wed, 28 Aug 2013 18:31:02 +0000 (18:31 +0000)]
Debug Info testing case: move uuid-related testing to a separate file.
Seperate the parts related to uuid from debug-info-template.cpp to
debug-info-uuid.cpp since Itanium mangler does not have support for mangling
uuid yet.
Remove -fms-extensions from RUN line of debug-info-template.cpp.
RUN line of debug-info-uuid.cpp has -fms-extensions and -cxx-abi microsoft.
David Blaikie [Wed, 28 Aug 2013 17:27:13 +0000 (17:27 +0000)]
PR16995: Failing to associate static members with their enclosing class
In the transition from declaration (with some members) to definition, we
were overwriting the list of members with the empty list when attaching
template parameters.
The fix is in llvm::DICompositeType::addMember (along with asserts that
cause this bug to be covered by existing Clang test cases), including
adding some asserts to catch this sort of issue which found issues fixed
in this commit.
Jordan Rose [Wed, 28 Aug 2013 17:07:04 +0000 (17:07 +0000)]
[analyzer] Add support for testing the presence of weak functions.
When casting the address of a FunctionTextRegion to bool, or when adding
constraints to such an address, use a stand-in symbol to represent the
presence or absence of the function if the function is weakly linked.
This is groundwork for possible simple availability testing checks, and
can already catch mistakes involving inverted null checks for
weakly-linked functions.
Currently, the implementation reuses the "extent" symbols, originally created
for tracking the size of a malloc region. Since FunctionTextRegions cannot
be dereferenced, the extent symbol will never be used for anything else.
Still, this probably deserves a refactoring in the future.
This patch does not attempt to support testing the presence of weak
/variables/ (global variables), which would likely require much more of
a change and a generalization of "region structure metadata", like the
current "extents", vs. "region contents metadata", like CStringChecker's
"string length".
Daniel Jasper [Wed, 28 Aug 2013 10:03:58 +0000 (10:03 +0000)]
clang-format: Improve token breaking behavior.
Two changes:
* Don't add an extra penalty on breaking the same token multiple times.
Generally, we should prefer not to break, but once we break, the
normal line breaking penalties apply.
* Slightly increase the penalty for breaking comments. In general, the
author has put some thought into how to break the comment and we
should not overwrite this unnecessarily.
Tim Northover [Wed, 28 Aug 2013 09:46:34 +0000 (09:46 +0000)]
ARM: use vqdmull and vqadds/vqsubs to implement vqdmlal/vqdmlsl
The NEON intrinsics vqdmlal and vqdmlsl are really just combinations of a
saturating-doubling-multiply (vqdmull) and a saturating add/sub, so now that
LLVM can spot those patterns Clang should emit them instead of specialised
intrinsics.
Feature already tested by existing ARM NEON intrinsics tests.
Daniel Jasper [Wed, 28 Aug 2013 09:07:32 +0000 (09:07 +0000)]
clang-format: Fix infinite loop in macro special case.
If escaped newlines are aligned right
(FormatStyle.AlignEscapedNewlinesLeft == false), and a line contained
too many characters to fit into the column limit, this would result in
a (virtually) endless loop creating a negative number of spaces.
Instead, allow the escaped newlines to be pushed past the column limit
in this case.
Daniel Jasper [Wed, 28 Aug 2013 08:04:23 +0000 (08:04 +0000)]
clang-format: Fix corner case in ObjC interface definitions.
In
@implementation ObjcClass
- (void)method;
{
}
@end
the ObjC compiler seems to accept the superfluous comma after "method",
but clang-format used to assert on the subsequent "{".
Pavel Labath [Wed, 28 Aug 2013 08:04:08 +0000 (08:04 +0000)]
[analyzer] Assume new returns non-null even under -fno-exceptions
Summary:
-fno-exceptions does not implicitly attach a nothrow specifier to every operator
new. Even in this mode, non-nothrow new must not return a null pointer. Failure
to allocate memory can be signalled by other means, or just by killing the
program. This behaviour is consistent with the compiler - even with
-fno-exceptions, the generated code never tests for null (and would segfault if
the opeator actually happened to return null).