We don't expect useful value there unless it's "ambiguous".
However we use read it for copying and moving, so we need either init the field
add login to avoid reading invalid values. Such reads trigger ubsan errors.
[X86] For lzcnt/tzcnt intrinsics use cttz/ctlz intrinsics with zero_undef flag set to false.
Previously we used a select and the zero_undef=true intrinsic. In -O2 this pattern will get optimized to zero_undef=false. But in -O0 this optimization won't happen. This results in a compare and cmov being wrapped around a tzcnt/lzcnt instruction.
By using the zero_undef=false intrinsic directly without the select, we can improve the -O0 codegen to just an lzcnt/tzcnt instruction.
Roman Lebedev [Wed, 26 Sep 2018 13:08:44 +0000 (13:08 +0000)]
[analyzer] scan-build: if --status-bugs is passed, don't forget about the exit status of the actual build
Summary:
This has been bothering me for a while, but only now i have actually looked into this.
I'm using one CI job for static analysis - clang static analyzers as compilers + clang-tidy via cmake.
And i'd like for the build to fail if at least one of those finds issues.
If clang-tidy finds issues, it will fail the build since the warnings-as-errors is set.
If static analyzer finds anything, since --status-bugs is set, it will fail the build.
But if clang-tidy find anything, but static analyzer does not, the build succeeds :/
Fangrui Song [Wed, 26 Sep 2018 06:28:14 +0000 (06:28 +0000)]
[Frontend] Tidy up -print-decl-contexts conditions
The existing conditions are not consistent. Some have braces and define a temporary Decl while others simply call `<< *cast<XXXDecl>(I)` (mostly the NamedDecl overload of operator<<).
Just use the latter for consistency and brevity.
[analyzer] Fix a crash on casting symbolic pointers to derived classes.
Commit r340984 causes a crash when a pointer to a completely unrelated type
UnrelatedT (eg., opaque struct pattern) is being casted from base class BaseT to
derived class DerivedT, which results in an ill-formed region
Derived{SymRegion{$<UnrelatedT x>}, DerivedT}.
[analyzer] Add a testing facility for testing relationships between symbols.
Tests introduced in r329780 was disabled in r342317 because these tests
were accidentally testing dump infrastructure, when all they cared about was
how symbols relate to each other. So when dump infrastructure changed,
tests became annoying to maintain.
Add a new feature to ExprInspection: clang_analyzer_denote() and
clang_analyzer_explain(). The former adds a notation to a symbol, the latter
expresses another symbol in terms of previously denoted symbols.
It's currently a bit wonky - doesn't print parentheses and only supports
denoting atomic symbols. But it's even more readable that way.
[clang-check-codegen][cfstring] Accept either @ or % for progbits to make ppc64be bots happy.
PPC64BE bots use % instead of @ for directives like progbits. Since CFString tests also
check asm output, they fail on the following:
cfstring3.c:44:19: error: CHECK-ASM-ELF: expected string not found in input
// CHECK-ASM-ELF: .section cfstring,"aw",@progbits
<stdin>:30:2: note: possible intended match here
.section cfstring,"aw",%progbits
Updating that check with a {{[@%]}}progbits regex to make those bots happy.
Reland "[Clang][CodeGen][ObjC]: Fix CoreFoundation on ELF with `-fconstant-cfstrings`"
Relanding rL342883 with more fragmented tests to test ELF-specific
section emission separately from broad-scope CFString tests. Now this
tests the following separately
1). CoreFoundation builds and linkage for ELF while building it.
2). CFString ELF section emission outside CF in assembly output.
3). Broad scope `cfstring3.c` tests which cover all object formats at
bitcode level and assembly level (including ELF).
This fixes non-bridged CoreFoundation builds on ELF targets
that use -fconstant-cfstrings. The original changes from differential
for a similar patch to PE/COFF (https://reviews.llvm.org/D44491) did not
check for an edge case where the global could be a constant which surfaced
as an issue when building for ELF because of different linkage semantics.
This patch addresses several issues with crashes related to CF builds on ELF
as well as improves data layout by ensuring string literals that back
the actual CFConstStrings end up in .rodata in line with Mach-O.
Change itself tested with CoreFoundation on Linux x86_64 but should be valid
for BSD-like systems as well that use ELF as the native object format.
Combine the two constructor overrides into a single ArrayRef constructor
to allow easier brace initializations and simplify how the respective field
is used internally.
[analyzer] NFC: Legalize state manager factory injection.
When a checker maintains a program state trait that isn't a simple list/set/map, but is a combination of multiple lists/sets/maps (eg., a multimap - which may be implemented as a map from something to set of something), ProgramStateManager only contains the factory for the trait itself. All auxiliary lists/sets/maps need a factory to be provided by the checker, which is annoying.
So far two checkers wanted a multimap, and both decided to trick the
ProgramStateManager into keeping the auxiliary factory within itself
by pretending that it's some sort of trait they're interested in,
but then never using this trait but only using the factory.
Make this trick legal. Define a convenient macro.
One thing that becomes apparent once all pieces are put together is that
these two checkers are in fact using the same factory, because the type that
identifies it, ImmutableMap<const MemRegion *, ImmutableSet<SymbolRef>>,
is the same. This situation is different from two checkers registering similar
primitive traits.
[DRIVER][OFFLOAD] Do not invoke unbundler on unsupported file types.
clang-offload-bundler should not be invoked with the unbundling action
when the input file type does not match the action type. For example,
.so files should be unbundled during linking phase and should be linked
only with the host code.
Hans Wennborg [Tue, 25 Sep 2018 14:10:26 +0000 (14:10 +0000)]
[clang-cl] Provide separate flags for all the /O variants
This provides better help text in "clang-cl /?".
Also it cleans things up a bit: previously "/Od" could be handled either
as a separate flag aliased to "-O0", or by the main optimization flag
processing in TranslateOptArg. With this patch, all the flags get
aliased back to /O so they're handled by TranslateOptArg.
Bruno Ricci [Tue, 25 Sep 2018 13:43:25 +0000 (13:43 +0000)]
[AST] Squeeze some bits in LinkageComputer::QueryType
Replace the pair std::pair<const NamedDecl *, unsigned> where the
unsigned represents an LVComputationKind by a PointerIntPair.
This saves a pointer per entry in the map LinkageComputer::CachedLinkageInfo.
Driver: render arguments for the embedded bitcode correctly
When embedding bitcode, only a subset of the arguments should be recorded into
the bitcode compilation commandline. The frontend job is split into two jobs,
one which will generate the bitcode. Ensure that the arguments for the
compilation to bitcode is properly stripped so that the embedded arguments are
the permitted subset.
Richard Smith [Mon, 24 Sep 2018 23:17:44 +0000 (23:17 +0000)]
P0962R1: only use the member form of 'begin' and 'end' in a range-based
for loop if both members exist.
This resolves a DR whereby an errant 'begin' or 'end' member in a base
class could result in a derived class not being usable as a range with
non-member 'begin' and 'end'.
George Karpenkov [Mon, 24 Sep 2018 21:20:30 +0000 (21:20 +0000)]
[analyzer] Prevent crashes in FindLastStoreBRVisitor
This patch is a band-aid. A proper solution would be too change
trackNullOrUndefValue to only try to dereference the pointer when it is
relevant to the problem.
Revert "We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case."
Discussed on cfe-commits (Week-of-Mon-20180820), this change leads to
the generation of invalid IR for OpenCL without giving an error.
Therefore, the conclusion was to revert.
[Clang][CodeGen][ObjC]: Fix CoreFoundation on ELF with `-fconstant-cfstrings`.
[Clang][CodeGen][ObjC]: Fix non-bridged CoreFoundation builds on ELF targets
that use `-fconstant-cfstrings`. The original changes from differential
for a similar patch to PE/COFF (https://reviews.llvm.org/D44491) did not
check for an edge case where the global could be a constant which surfaced
as an issue when building for ELF because of different linkage semantics.
This patch addresses several issues with crashes related to CF builds on ELF
as well as improves data layout by ensuring string literals that back
the actual CFConstStrings end up in .rodata in line with Mach-O.
Change itself tested with CoreFoundation on Linux x86_64 but should be valid
for BSD-like systems as well that use ELF as the native object format.
Michael Kruse [Mon, 24 Sep 2018 06:31:37 +0000 (06:31 +0000)]
Add inherited attributes before parsed attributes.
Currently, attributes from previous declarations ('inherited attributes')
are added to the end of a declaration's list of attributes. Before
r338800, the attribute list was in reverse. r338800 changed the order
of non-inherited (parsed from the current declaration) attributes, but
inherited attributes are still appended to the end of the list.
This patch appends inherited attributes after other inherited
attributes, but before any non-inherited attribute. This is to make the
order of attributes in the AST correspond to the order in the source
code.
David Carlier [Sun, 23 Sep 2018 08:30:17 +0000 (08:30 +0000)]
[CStringSyntaxChecker] Check strlcat sizeof check
Assuming strlcat is used with strlcpy we check as we can if the last argument does not equal os not larger than the buffer.
Advising the proper usual pattern.
Eric Fiselier [Sun, 23 Sep 2018 00:48:05 +0000 (00:48 +0000)]
Fix modules build with shared library.
r341994 caused clangAnalysis to pull all of the AST matchers
library into clang. Due to inline key functions in the headers,
importing the AST matchers library gives a link dependency on the
AST matchers (and thus the AST), which clang should not
have.
This patch works around the issues by excluding the offending
libclangAnalysis header in the modulemap.
Fix codemodels.c test case (only test mcmodel=medium on X86).
aarch64 testing is broken because "medium" is not a valid
code-model on aarch64, and codemodels.c tests that. This fixes
that problem by adding "-triple x86_64-unknown-linux-gnu" to the
test with "-mcode-model moedium".
Richard Trieu [Sat, 22 Sep 2018 01:50:52 +0000 (01:50 +0000)]
Update smart pointer detection for thread safety analysis.
Objects are determined to be smart pointers if they have both a star and arrow
operator. Some implementations of smart pointers have these overloaded
operators in a base class, while the check only searched the derived class.
This fix will also look for the operators in the base class.
Fix codemodels.c test case (only test mcmodel-kernel on x86)
A recent commit I made broke aarch64 testing, because "kernel"
apparently is not a valid code-model on aarch64, and one of my tests
tested that. This fixes the problem (hopefully) by adding "-triple
x86_64-unknown-linux-gnu" to the test build with "-mcodel-model
kernel".
George Karpenkov [Fri, 21 Sep 2018 20:37:20 +0000 (20:37 +0000)]
[analyzer] Process state in checkEndFunction in RetainCountChecker
Modify the RetainCountChecker to perform state "adjustments" in
checkEndFunction, as performing work in PreStmt<ReturnStmt> does not
work with destructors.
The previous version made an implicit assumption that no code runs
after the return statement is executed.
George Karpenkov [Fri, 21 Sep 2018 20:36:01 +0000 (20:36 +0000)]
[analyzer] Fix bug in isInevitablySinking
If the non-sink report is generated at the exit node, it will be
suppressed by the current functionality in isInevitablySinking, as it
only checks the successors of the block, but not the block itself.
Add necessary support for storing code-model to module IR.
Currently the code-model does not get saved in the module IR, so if a
code model is specified when compiling with LTO, it gets lost and is
not propagated properly to LTO. This patch does what is necessary in
the front end to pass the code-model to the module, so that the back
end can store it in the Module .
Bruno Ricci [Fri, 21 Sep 2018 14:03:32 +0000 (14:03 +0000)]
[AST][NFC] DeclarationName.h : add missing parentheses to silence warnings
Some bots are complaining about missing parentheses in assertions added in
r342729: [AST] Various optimizations + refactoring in DeclarationName(Table)
NFC: deduplicate isRepeatedBytePattern from clang to LLVM's isBytewiseValue
Summary:
This code was in CGDecl.cpp and really belongs in LLVM. It happened to have isBytewiseValue which served a very similar purpose but wasn't as powerful as clang's version. Remove the clang version, and augment isBytewiseValue to be as powerful so that clang does the same thing it used to.
Bruno Ricci [Fri, 21 Sep 2018 13:11:39 +0000 (13:11 +0000)]
[AST][NFC] Remove a superfluous enum in ObjCMethodDeclBitfields added in r338641
I originally added this enum to avoid including Basic/IdentifierTable.h
in AST/DeclBase.h. However I did not realise it is already included
transitively by AST/DeclarationName.h. Therefore remove this enum and
explicitly include Basic/IdentifierTable.h
Bruno Ricci [Fri, 21 Sep 2018 12:53:22 +0000 (12:53 +0000)]
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):
1. Store common kinds inline in DeclarationName instead of
DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
conversion function and overloaded operator names is stored in
DeclarationNameExtra. Instead store it inline in DeclarationName.
To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
This also allow us to remove DeclarationNameExtra from CXXSpecialName
and CXXOperatorIdName, which shave off a pointer from CXXSpecialName.
2. Synchronize the enumerations DeclarationName::NameKind,
DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
This makes DeclarationName::getNameKind much more efficient since we can
replace the switch table by a single comparison and an addition.
3. Put the overloaded operator names inline in DeclarationNameTable to remove
an indirection. This increase the size of DeclarationNameTable a little
bit but this is not important since it is only used in ASTContext, and
never copied nor moved from. This also get rid of the last dynamic
allocation in DeclarationNameTable.
Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:
1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
in a namespace detail since these classes are only meant to be used by
DeclarationName and DeclarationNameTable. Make this more explicit by making
the members of these classes private and friending DeclarationName(Table).
2. Make DeclarationName::getFETokenInfo a non-template since every users are
using it to get a void *. It was supposed to be used with a type to avoid
a subsequent static_cast.
3. Change the internal functions DeclarationName::getAs* to castAs* since when
we use them we already know the correct kind. This has no external impact
since all of these are private.
[CodeGen] Add to emitted DebugLoc information about coverage when it's required
Summary:
Some lines have a hit counter where they should not have one.
Cleanup stuff is located to the last line of the body which is most of the time a '}'.
And Exception stuff is added at the beginning of a function and at the end (represented by '{' and '}').
So in such cases, the DebugLoc used in GCOVProfiling.cpp must be marked as not covered.
This patch is a followup of https://reviews.llvm.org/D49915.
Tests in projects/compiler_rt are fixed by: https://reviews.llvm.org/D49917
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);