Removing on behalf of Jorge Moya. This test is broken on
Windows due to it actually being able to resolve the path. There
is an actual Windows-specific bug somewhere, but we already have
sufficient test coverage of this with a different test, so removing
this was the approach suggested by Jorge.
Eric Christopher [Thu, 20 Sep 2018 17:21:56 +0000 (17:21 +0000)]
r342177 introduced a hint in cases where an #included file is not found. It tries to find a suggestion by removing leading or trailing non-alphanumeric characters and checking if a matching file exists, then it reports an error like:
include-likely-typo.c:3:10: error: '<empty_file_to_include.h>' file not found, did you mean 'empty_file_to_include.h'?
^~~~~~~~~~~~~~~~~~~~~~~~~~~
"empty_file_to_include.h"
1 error generated.
However, if a hint is not found, the error message will show only the trimmed name we use to look for a hint, so:
will result in:
include-leading-nonalpha-no-suggest.c:3:10: fatal error: 'non_existing_file_to_include.h' file not found
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
where the name reported after "fatal error:" doesn't match what the user wrote.
unsigned long long builtin_unpack_vector_int128 (vector int128_t, int);
vector int128_t builtin_pack_vector_int128 (unsigned long long, unsigned long long);
Thread Safety Analysis: warnings for attributes without arguments
Summary:
When thread safety annotations are used without capability arguments,
they are assumed to apply to `this` instead. So we warn when either
`this` doesn't exist, or the class is not a capability type.
This is based on earlier work by Josh Gao that was committed in r310403,
but reverted in r310698 because it didn't properly work in template
classes. See also D36237.
The solution is not to go via the QualType of `this`, which is then a
template type, hence the attributes are not known because it could be
specialized. Instead we look directly at the class in which we are
contained.
Additionally I grouped two of the warnings together. There are two
issues here: the existence of `this`, which requires us to be a
non-static member function, and the appropriate annotation on the class
we are contained in. So we don't distinguish between not being in a
class and being static, because in both cases we don't have `this`.
I had locally changed the test to add an explicit triple to figure out the issue
with the SCEI buildbots, and that hid the error. This now works with and
without the explicit triple.
Sema: handle `wint_t` more carefully for printf checking
In the case that `win_t` is an `unsigned short` (e.g. on Windows), we would
previously incorrectly diagnose the conversion because we would immediately
promote the argument type from `wint_t` (aka `unsigned short`) to `int` before
checking if the type matched. This should repair the Windows hosted bots.
Windows uses `unsigned short` for `wint_t`. Correct the type definition as
vended by the compiler. This type is defined in corecrt.h and is
unconditionally typedef'ed. cl does not have an equivalent to `__WINT_TYPE__`
which is why this was never detected.
Thread safety analysis: Fix crash for function pointers
For function pointers, the FunctionDecl of the callee is unknown, so
getDirectCallee will return nullptr. We have to catch that case to avoid
crashing. We assume there is no attribute then.
Add a callback for `__has_include` and use it for dependency scanning.
This adds a preprocessor callback for the `__has_include` and
`__has_include_next` directives.
Successful checking for the presence of a header should add it to the list of
header dependencies so this overrides the callback in the dependency scanner.
[MS] Defer dllexport inline friend functions like other inline methods
This special case was added in r264841, but the code breaks our
invariants by calling EmitTopLevelDecl without first creating a
HandlingTopLevelDeclRAII scope.
This fixes the PCH crash in https://crbug.com/884427. I was never able
to make a satisfactory reduction, unfortunately. I'm not very worried
about this regressing since this change makes the code simpler while
passing the existing test that shows we do emit dllexported friend
function definitions. Now we just defer their emission until the tag is
fully complete, which is generally good.
Move the floating point argument handling into the RenderFloatingPointOptions
helper. This relocation just puts the floating point related options into a
single location.
Stephen Hines [Tue, 18 Sep 2018 18:34:33 +0000 (18:34 +0000)]
Fix logic around determining use of frame pointer with -pg.
Summary:
As part of r342165, I rewrote the logic to check whether
-fno-omit-frame-pointer was passed after a -fomit-frame-pointer
argument. This CL switches that logic to use the consolidated
shouldUseFramePointer() function. This fixes a potential issue where -pg
gets used with -fomit-frame-pointer on a platform that must always retain
frame pointers.
[Modules] Add platform and environment features to requires clause
Allows module map writers to add build requirements based on
platform/os. This helps when target features and language dialects
aren't enough to conditionalize building a module, among other things,
it allow module maps for different platforms to live in the same file.
Sam McCall [Tue, 18 Sep 2018 08:40:41 +0000 (08:40 +0000)]
[CodeComplete] Add completions for filenames in #include directives.
Summary:
The dir component ("somedir" in #include <somedir/fo...>) is considered fixed.
We append "foo" to each directory on the include path, and then list its files.
Completions are of the forms:
#include <somedir/fo^
foo.h>
fox/
The filter is set to the filename part ("fo"), so fuzzy matching can be
applied to the filename only.
No fancy scoring/priorities are set, and no information is added to
CodeCompleteResult to make smart scoring possible. Could be in future.
Thread safety analysis: Run more tests with capability attributes [NFC]
Summary:
We run the tests for -Wthread-safety-{negative,verbose} with the new
attributes as well as the old ones. Also put the macros in a header so
that we don't have to copy them all around.
The warn-thread-safety-parsing.cpp test checks for warnings depending on
the actual attribute name, so it can't undergo the same treatment.
George Karpenkov [Mon, 17 Sep 2018 20:46:53 +0000 (20:46 +0000)]
[analyzer] ExplodedGraph printing fixes
Fixes a number of issues:
- Global variables are not used for communication
- Trait should be defined on a graph, not on a node
- Defining the trait on a graph allows us to use a correct allocator,
no longer crashing while printing trimmed graphs
Shuai Wang [Mon, 17 Sep 2018 20:10:56 +0000 (20:10 +0000)]
[analyzer] Treat std::{move,forward} as casts in ExprMutationAnalyzer.
Summary:
This is a follow up of D52008 and should make the analyzer being able to handle perfect forwardings in real world cases where forwardings are done through multiple layers of function calls with `std::forward`.
Summary:
The init expression of a VarDecl is overwritten in the "To" context if we
import a VarDecl without an init expression (and with a definition). Please
refer to the added tests, especially InitAndDefinitionAreInDifferentTUs. This
patch fixes the malfunction by importing the whole Decl chain similarly as we
did that in case of FunctionDecls. We handle the init expression similarly to
a definition, alas only one init expression will be in the merged ast.
Summary:
Merged the recently added `err_attribute_argument_negative` diagnostic
with existing `err_attribute_requires_positive_integer` diagnostic:
the former allows only strictly positive integer, while the latter
also allows zero.
scan-build: Using '/usr/lib/llvm-7/bin/clang' for static analysis
scan-build: Emitting reports for this run to '/tmp/scan-build-2018-09-16-214531-8410-1'.
foo.c:3:3: warning: Value stored to 'x' is never read
x = 1; // warn
^ ~
1 warning generated.
scan-build: File '/tmp/foo.c' deleted: part of an ignored directory.
scan-build: 0 bugs found.
```
Kelvin Li [Sat, 15 Sep 2018 13:54:15 +0000 (13:54 +0000)]
[OPENMP] Move OMPClauseReader/Writer classes to ASTReader/Writer (NFC)
Move declarations for OMPClauseReader, OMPClauseWriter to ASTReader.h
and ASTWriter.h and move implementation to ASTReader.cpp and
ASTWriter.cpp. This change helps generalize the serialization of
OpenMP clauses and will be used in the future implementation of new
OpenMP directives (e.g. requires).
Shuai Wang [Fri, 14 Sep 2018 20:07:18 +0000 (20:07 +0000)]
[analyzer] Handle forwarding reference better in ExprMutationAnalyzer.
Summary:
We used to treat an `Expr` mutated whenever it's passed as non-const
reference argument to a function. This results in false positives in
cases like this:
```
int x;
std::vector<int> v;
v.emplace_back(x); // `x` is passed as non-const reference to `emplace_back`
```
In theory the false positives can be suppressed with
`v.emplace_back(std::as_const(x))` but that's considered overly verbose,
inconsistent with existing code and spammy as diags.
This diff handles such cases by following into the function definition
and see whether the argument is mutated inside.
Hans Wennborg [Fri, 14 Sep 2018 15:18:30 +0000 (15:18 +0000)]
[clang-cl] Fix PR38934: failing to dllexport class template member w/ explicit instantiation and PCH
The code in ASTContext::DeclMustBeEmitted was supposed to handle this,
but didn't take into account that synthesized members such as operator=
might not get marked as template specializations, because they're
synthesized on the instantiation directly when handling the class-level
dllexport attribute.
Louis Dionne [Fri, 14 Sep 2018 14:07:16 +0000 (14:07 +0000)]
[clang] Make sure attributes on member classes are applied properly
Summary:
Attributes on member classes of class templates and member class templates
of class templates are not currently instantiated. This was discovered by
Richard Smith here:
This commit makes sure that attributes are instantiated properly. This
commit does not fix the broken behavior for member partial and explicit
specializations of class templates.
Sam McCall [Fri, 14 Sep 2018 12:47:38 +0000 (12:47 +0000)]
[VFS] vfs::directory_iterator yields path and file type instead of full Status
Summary:
Most callers I can find are using only `getName()`. Type is used by the
recursive iterator.
Now we don't have to call stat() on every listed file (on most platforms).
Exceptions are e.g. Solaris where readdir() doesn't include type information.
On those platforms we'll still stat() - see D51918.
The result is significantly faster (stat() can be slow).
My motivation: this may allow us to improve clang IO on large TUs with long
include search paths. Caching readdir() results may allow us to skip many stat()
and open() operations on nonexistent files.
[Driver] Fix missing MultiArch include dir on powerpcspe
On powerpc-linux-gnuspe, the header files are located in their
own include directory named /usr/lib/powerpc-linux-gnuspe,
so add this directory to PPCMultiarchIncludeDirs.
Sam McCall [Fri, 14 Sep 2018 12:24:09 +0000 (12:24 +0000)]
[Tooling] JSONCompilationDatabasePlugin infers compile commands for missing files
Summary:
See the existing InterpolatingCompilationDatabase for details on how this works.
We've been using this in clangd for a while, the heuristics seem to work well.
[analyzer][UninitializedObjectChecker] New flag to ignore records based on it's fields
Based on a suggestion from @george.karpenkov.
In some cases, structs are used as unions with a help of a tag/kind field.
This patch adds a new string flag (a pattern), that is matched against the
fields of a record, and should a match be found, the entire record is ignored.
For more info refer to http://lists.llvm.org/pipermail/cfe-dev/2018-August/058906.html
and to the responses to that, especially http://lists.llvm.org/pipermail/cfe-dev/2018-August/059215.html.
Since I plan to add a number of new flags, it made sense to encapsulate
them in a new struct, in order not to pollute FindUninitializedFields's
constructor with new boolean options with super long names.
This revision practically reverts D50508, since FindUninitializedFields
now accesses the pedantic flag anyways.
Some of the comments are incorrect, imprecise, or simply nonexistent.
Since I have a better grasp on how the analyzer works, it makes sense
to update most of them in a single swoop.
I tried not to flood the code with comments too much, this amount
feels just right to me.
Summary:
Before this change, we only emit the XRay attributes in LLVM IR when the
-fxray-instrument flag is provided. This may cause issues with thinlto
when the final binary is being built/linked with -fxray-instrument, and
the constitutent LLVM IR gets re-lowered with xray instrumentation.
With this change, we can honour the "never-instrument "attributes
provided in the source code and preserve those in the IR. This way, even
in thinlto builds, we retain the attributes which say whether functions
should never be XRay instrumented.
Richard Trieu [Fri, 14 Sep 2018 01:15:28 +0000 (01:15 +0000)]
[ODRHash] Fix early exit that skipped code.
There is a bit of code at the end of AddDeclaration that should be run on
every exit of the function. However, there was an early exit beforehand
that could be triggered, which causes a small amount of data to skip the
hashing, leading to false positive mismatch. Use a separate function so
that this code is always run.
[Sema] Remove location from implicit capture init expr
A lambda's closure is initialized when the lambda is declared. For
implicit captures, the initialization code emitted from EmitLambdaExpr
references source locations *within the lambda body* in the function
containing the lambda. This results in a poor debugging experience: we
step to the line containing the lambda, then into lambda, out again,
over and over, until every capture's field is initialized.
To improve stepping behavior, assign the starting location of the lambda
to expressions which initialize an implicit capture within it.
Richard Smith [Thu, 13 Sep 2018 21:10:08 +0000 (21:10 +0000)]
Diagnose likely typos in #include directives.
Summary:
When someone writes
#include "<some_file>"
or
#include " some_file "
the compiler returns "file not fuond..." with fonts and quotes that may
make it hard to see there are excess quotes or surprising bytes in the
filename. Assuming that files are usually logically named and start and
end with an alphanumeric character, we can check for the file's
existence by stripping the non-alphanumeric leading or trailing
characters. If the file is found, emit a non-fatal error with a
FixItHint.
Stephen Hines [Thu, 13 Sep 2018 19:50:02 +0000 (19:50 +0000)]
Support -fno-omit-frame-pointer with -pg.
Summary:
Previously, any instance of -fomit-frame-pointer would make it such that
-pg was an invalid flag combination. If -fno-omit-frame-pointer is
passed later on the command line (such that it actually takes effect),
-pg should be allowed.
Erich Keane [Thu, 13 Sep 2018 16:58:24 +0000 (16:58 +0000)]
[NFC]Refactor MultiVersion Resolver Emission to combine types
Previously, both types (plus the future target-clones) of
multiversioning had a separate ResolverOption structure and emission
function. This patch combines the two, at the expense of a slightly
more expensive sorting function.
[OPENMP] Fix PR38903: Crash on instantiation of the non-dependent
declare reduction.
If the declare reduction construct with the non-dependent type is
defined in the template construct, the compiler might crash on the
template instantition. Reworked the whole instantiation scheme for the
declare reduction constructs to fix this problem correctly.
Oliver Stannard [Thu, 13 Sep 2018 10:25:36 +0000 (10:25 +0000)]
[AArch64] Enable return address signing for static ctors
Functions generated by clang and included in the .init_array section (such as
static constructors) do not follow the usual code path for adding
target-specific function attributes, so we have to add the return address
signing attribute here too, as is currently done for the sanitisers.
Tri Vo [Wed, 12 Sep 2018 23:45:04 +0000 (23:45 +0000)]
[AArch64] Support reserving x1-7 registers.
Summary: Reserving registers x1-7 is used to support CONFIG_ARM64_LSE_ATOMICS in Linux kernel. This change adds support for reserving registers x1 through x7.