Richard Smith [Tue, 7 May 2019 07:36:07 +0000 (07:36 +0000)]
Improve function / variable disambiguation.
Keep looking for decl-specifiers after an unknown identifier. Don't
issue diagnostics about an error type specifier conflicting with later
type specifiers.
Petr Hosek [Mon, 6 May 2019 23:24:17 +0000 (23:24 +0000)]
[Clang][NewPM] Don't bail out if the target machine is empty
This matches the behavior of the old pass manager. There are some
targets that don't have target machine at all (e.g. le32, spir) which
whose tests would never run with new pass manager. Similarly, we would
need to disable tests for targets that are disabled.
Martin Storsjo [Mon, 6 May 2019 21:19:07 +0000 (21:19 +0000)]
[AArch64] Add __builtin_sponentry, for calling setjmp in MinGW
In MinGW, setjmp isn't expanded as a builtin in the compiler (like it
is for MSVC), but manually hooked up as calls to the right underlying
functions in headers. Using the actual CRT's real setjmp/longjmp
functions requires this intrinsic. (Currently this is worked around by
using MinGW specific reimplementations of setjmp/longjmp on aarch64.)
Alexey Bataev [Mon, 6 May 2019 20:07:20 +0000 (20:07 +0000)]
[OPENMP]Fix PR41767: diagnose DSA for variables in clauses with
default(none).
If the combined directive has default(none) clause and has clauses for
inner directive that reference some variables, for which data-sharing
attributes are not specified, the error messages should be emitted for
such variables.
Summary:
In this patch we propose a temporary solution to resolving math functions for the NVPTX toolchain, temporary until OpenMP variant is supported by Clang.
We intercept the inclusion of math.h and cmath headers and if we are in the OpenMP-NVPTX case, we re-use CUDA's math function resolution mechanism.
Alexey Bataev [Mon, 6 May 2019 17:49:22 +0000 (17:49 +0000)]
[OPENMP]Fix PR41768: check DSA for globals with `default(none)` clauses.
If the `default(none)` was specified for the construct, we might miss
diagnostic for the globals without explicitly specified data-sharing
attributes. Patch fixes this problem.
Ilya Biryukov [Mon, 6 May 2019 13:18:00 +0000 (13:18 +0000)]
[CodeComplete] Add a trailing semicolons to some pattern completions
Summary:
Where semicolon is required in any case. Here's a list of completions
that now have a semicolon:
- namespace <name> = <target>;
- using namespace <name>;
- using <qualifier>::<name>;
- continue;
- break;
- goto <label>;
- return;
- return <expression>;
Hans Wennborg [Mon, 6 May 2019 09:51:10 +0000 (09:51 +0000)]
Revert r359949 "[clang] adding explicit(bool) from c++2a"
This caused Clang to start erroring on the following:
struct S {
template <typename = int> explicit S();
};
struct T : S {};
struct U : T {
U();
};
U::U() {}
$ clang -c /tmp/x.cc
/tmp/x.cc:10:4: error: call to implicitly-deleted default constructor of 'T'
U::U() {}
^
/tmp/x.cc:5:12: note: default constructor of 'T' is implicitly deleted
because base class 'S' has no default constructor
struct T : S {};
^
1 error generated.
See discussion on the cfe-commits email thread.
This also reverts the follow-ups r359966 and r359968.
> this patch adds support for the explicit bool specifier.
>
> Changes:
> - The parsing for the explicit(bool) specifier was added in ParseDecl.cpp.
> - The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class.
> - Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted.
> - Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration.
> - The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected.
> - Test for Semantic and Serialization were added.
>
> This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback.
> Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky.
>
> Patch by Tyker
>
> Differential Revision: https://reviews.llvm.org/D60934
Luo, Yuanke [Mon, 6 May 2019 08:25:11 +0000 (08:25 +0000)]
Enable intrinsics of AVX512_BF16, which are supported for BFLOAT16 in Cooper Lake
Summary:
1. Enable infrastructure of AVX512_BF16, which is supported for BFLOAT16 in Cooper Lake;
2. Enable intrinsics for VCVTNE2PS2BF16, VCVTNEPS2BF16 and DPBF16PS instructions, which are Vector Neural Network Instructions supporting BFLOAT16 inputs and conversion instructions from IEEE single precision.
For more details about BF16 intrinsic, please refer to the latest ISE document: https://software.intel.com/en-us/download/intel-architecture-instruction-set-extensions-programming-reference
Richard Smith [Mon, 6 May 2019 03:47:15 +0000 (03:47 +0000)]
[c++20] Implement P1009R2: allow omitting the array bound in an array
new expression.
This was voted into C++20 as a defect report resolution, so we
retroactively apply it to all prior language modes (though it can never
actually be used before C++11 mode).
The 'CodeGenObjC/illegal-UTF8.m' get failed with Clang built with 32-bit targets only (as example ARM-only) with the following error:
error: unable to create target: 'No available targets are compatible with triple "< ... any 64-bit target triple ... >"'
I didn't find any 64-bit dependencies for the test and I think removing '-m64' option should fix the problem and allow this test for any target specified by LLVM_DEFAULT_TARGET_TRIPLE.
Kristof Umann [Sun, 5 May 2019 19:42:33 +0000 (19:42 +0000)]
[analyzer][UninitializedObjectChecker] PR41741: Regard all scalar types as primitive.
https://bugs.llvm.org/show_bug.cgi?id=41741
Pretty much the same as D61246 and D61106, this time for __complex__ types. Upon
further investigation, I realized that we should regard all types
Type::isScalarType returns true for as primitive, so I merged
isMemberPointerType(), isBlockPointerType() and isAnyComplexType()` into that
instead.
I also stumbled across yet another bug,
https://bugs.llvm.org/show_bug.cgi?id=41753, but it seems to be unrelated to
this checker.
Simon Pilgrim [Sun, 5 May 2019 17:10:05 +0000 (17:10 +0000)]
Revert rL359962 : Use DiagRuntimeBehavior for -Wunsequenced to weed out false positives
where either the modification or the other access is unreachable.
........
Try to fix buildbots
Nicolas Lesser [Sun, 5 May 2019 12:35:12 +0000 (12:35 +0000)]
[clang] fixing -ast-print for variadic parameter pack in lambda capture
Summary:
currently for:
```
template<typename ... T>
void f(T... t) {
auto l = [t...]{};
}
```
`clang -ast-print file.cpp`
outputs:
```
template <typename ...T> void f(T ...t) {
auto l = [t] {
}
;
}
```
notice that there is not `...` in the capture list of the lambda. this patch fixes this issue. and add test for it.
Richard Smith [Sat, 4 May 2019 06:46:18 +0000 (06:46 +0000)]
[c++20] Implement tweaked __VA_OPT__ rules from P1042R1:
* __VA_OPT__ is expanded if the *expanded* __VA_ARGS__ is non-empty,
not if the original argument contained no tokens.
* Placemarkers at the start and end of __VA_OPT__ are retained just
long enough to paste them with adjacent ## operators. We never paste
"across" a discarded placemarker.
Richard Trieu [Sat, 4 May 2019 04:22:33 +0000 (04:22 +0000)]
Reduce amount of work ODR hashing does.
When a FunctionProtoType is in the original type in a DecayedType, the decayed
type is a PointerType which points back the original FunctionProtoType. The
visitor for ODRHashing will attempt to process both Type's, doing double work.
By chaining together multiple DecayedType's and FunctionProtoType's, this would
result in 2^N Type's visited only N DecayedType's and N FunctionProtoType's
exsit. Another bug where VisitDecayedType and VisitAdjustedType did
redundant work doubled the work at each level, giving 4^N Type's visited. This
patch removed the double work and detects when a FunctionProtoType decays to
itself to only check the Type once. This lowers the exponential runtime to
linear runtime. Fixes https://bugs.llvm.org/show_bug.cgi?id=41625
Richard Smith [Sat, 4 May 2019 04:00:45 +0000 (04:00 +0000)]
Disallow the operand of __builtin_constant_p from modifying enclosing
state when it's encountered while evaluating a constexpr function.
We attempt to follow GCC trunk's behavior here, but it is somewhat
inscrutible, so our behavior is only approximately the same for now.
Specifically, we only permit modification of objects whose lifetime
began within the operand of the __builtin_constant_p. GCC appears to
have effectively the same restriction, but also some unknown restriction
based on where and how the local state of the constexpr function is
mentioned within the operand (see added testcases).
Richard Smith [Sat, 4 May 2019 00:27:21 +0000 (00:27 +0000)]
[cxx_status] Don't list -fmodules / -fmodules-ts against C++ modules
support; those turn on different modules modes. The real C++ modules
support is behind -std=c++2a like the rest of C++20.
Nicolas Lesser [Sat, 4 May 2019 00:09:00 +0000 (00:09 +0000)]
[clang] adding explicit(bool) from c++2a
this patch adds support for the explicit bool specifier.
Changes:
- The parsing for the explicit(bool) specifier was added in ParseDecl.cpp.
- The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class.
- Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted.
- Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration.
- The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected.
- Test for Semantic and Serialization were added.
This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback.
Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky.
Don Hinton [Fri, 3 May 2019 17:47:29 +0000 (17:47 +0000)]
[CommandLine] Change help output to prefix long options with `--` instead of `-`. NFC . Part 3 of 5
Summary:
By default, `parseCommandLineOptions()` will accept either a
`-` or `--` prefix for long options -- options with names longer than
a single character.
While this change does not affect behavior, it will be helpful with a
subsequent change that requires long options use the `--` prefix.
David Blaikie [Fri, 3 May 2019 00:44:50 +0000 (00:44 +0000)]
SemaOverload: Complete candidates before emitting the error, to ensure diagnostics emitted (or suppressed) during completion don't interfere with the overload notes
Because diagnostics and their notes are not connected at the API level,
if the error message for an overload is emitted, then the overload
candidates are completed - if a diagnostic is emitted during that work,
the notes related to overload candidates would be attached to the latter
diagnostic, not the original error. Sort of worse, if the latter
diagnostic was disabled, the notes are disabled.
Richard Smith [Thu, 2 May 2019 23:21:28 +0000 (23:21 +0000)]
Fix -Wunsequenced false-positives in code controlled by a branch on
__builtin_constant_p.
If the operand of __builtin_constant_p is not constant and has
side-effects, then code controlled by a branch on it is unreachable and
we should not emit runtime behavior warnings in such code.
Leonard Chan [Thu, 2 May 2019 20:38:14 +0000 (20:38 +0000)]
[Attribute/Diagnostics] Print macro if definition is an attribute declaration
If an address_space attribute is defined in a macro, print the macro instead
when diagnosing a warning or error for incompatible pointers with different
address_spaces.
We allow this for all attributes (not just address_space), and for multiple
attributes declared in the same macro.
Nico Weber [Thu, 2 May 2019 19:47:05 +0000 (19:47 +0000)]
Another attempt to fix "could not find clang-check" lit warning in analyzer-less builds
r359717 added clang-check as a dep of check-clang unconditionally
because I had missed lit.local.cfg in test/Tooling.
Instead, only add clang-check to the tools if the analyzer is enabled,
since the build target only exists then, and since all tests using
clang-check are skipped when the analyzer is disabled.
Before this change, when emitting debug info for the
`is_same_v<int, int>` global variable, clang would crash because it
would try to use the template parameter list from the partial
specialization to give parameter names to template arguments. This
doesn't work in general, since a partial specialization can have fewer
arguments than the primary template. Therefore, always use the primary
template. Hypothetically we could try to use the parameter names from
the partial specialization when possible, but it's not clear this really
helps debugging in practice.
When the expression used to initialise 'this' has a pointer type,
check the address space of the pointee type instead of the pointer
type to decide whether an address space cast is required.
It is the pointee type that carries the address space qualifier.
Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO
This follows up after b7692bc3e9ad2691fc07261904b88fb15f30696b "[UBSan] Fix
isDerivedFromAtOffset on iOS ARM64" fixed the RTTI comparison in
isDerivedFromAtOffset on just one platform and then a25a2c7c9a7e1e328a5bd8274d2d86b1fadc4692 "Always compare C++ typeinfo (based on
libstdc++ implementation)" extended that fix to more platforms.
But there is another RTTI comparison for -fsanitize=function generated in
clang's CodeGenFunction::EmitCall as just a pointer comparison. For
SANITIZER_NON_UNIQUE_TYPEINFO platforms this needs to be extended to also do
string comparison. For that, __ubsan_handle_function_type_mismatch[_abort]
takes the two std::type_info pointers as additional parameters now, checks them
internally for potential equivalence, and returns without reporting failure if
they turn out to be equivalent after all. (NORETURN needed to be dropped from
the _abort variant for that.) Also these functions depend on ABI-specific RTTI
now, so needed to be moved from plain UBSAN_SOURCES (ubsan_handlers.h/cc) to
UBSAN_CXXABI_SOURCES (ubsan_handlers_cxx.h/cc), but as -fsanitize=function is
only supported in C++ mode that's not a problem.
Richard Smith [Thu, 2 May 2019 00:49:14 +0000 (00:49 +0000)]
Replace ad-hoc tracking of pattern for an instantiated class-scope
explicit function specialization with the MemberSpecializationInfo used
everywhere else.
Not NFC: the ad-hoc pattern tracking was not being serialized /
deserialized properly. That's fixed here.
Richard Smith [Thu, 2 May 2019 00:49:05 +0000 (00:49 +0000)]
Diagnose non-dependent qualified friend function template declarations
that don't match any existing declaration. Don't get confused and treat
such declarations as template *specializations*.
Tom Tan [Thu, 2 May 2019 00:38:14 +0000 (00:38 +0000)]
[COFF, ARM64] Align global symbol by size for ARM64 MSVC ABI
According to alignment section in below ARM64 ABI document, MSVC could increase
alignment of global data based on its total size. Clang doesn't do this. Compile
the same symbol into different alignments by Clang and MSVC could cause link
error because some instruction encodings, like 64-bit LDR/STR with immediate,
require the target to be 8 bytes aligned, and linker could choose code stream
with such LDR/STR instruction from MSVC and 4 bytes aligned data from Clang into
final image, which actually cannot be linked together
(see https://bugs.llvm.org/show_bug.cgi?id=41506 for more details).
Richard Trieu [Wed, 1 May 2019 23:33:49 +0000 (23:33 +0000)]
Consume unexpected "template" keywords after "using"
The parser was dealing with unexpected "template" keywords after "using"
keywords too late and putting the parser into the wrong state, which could
lead to a crash down the line. This change allows the parser to consume the
bad "template" keywords earlier, and continue parsing as if "template" was
never there to begin with for better error recovery.
Kristof Umann [Wed, 1 May 2019 19:56:47 +0000 (19:56 +0000)]
[analyzer] Don't display implementation checkers under -analyzer-checker-help, but do under the new flag -analyzer-checker-help-hidden
During my work on analyzer dependencies, I created a great amount of new
checkers that emitted no diagnostics at all, and were purely modeling some
function or another.
However, the user shouldn't really disable/enable these by hand, hence this
patch, which hides these by default. I intentionally chose not to hide alpha
checkers, because they have a scary enough name, in my opinion, to cause no
surprise when they emit false positives or cause crashes.
The patch introduces the Hidden bit into the TableGen files (you may remember
it before I removed it in D53995), and checkers that are either marked as
hidden, or are in a package that is marked hidden won't be displayed under
-analyzer-checker-help. -analyzer-checker-help-hidden, a new flag meant for
developers only, displays the full list.
Nico Weber [Wed, 1 May 2019 19:34:00 +0000 (19:34 +0000)]
Make check-clang depend on the clang-check binary always
check-clang (the target that runs all clang tests) used to
only depend on clang-check (a binary like clang-tidy,
clang-refactor, etc) if the static analyzer is enabled.
However, several lit tests call clang-check unconditionally,
so always depend on it.
Fixes a "could not find clang-check" lit warning in clean builds with
the static analyzer disabled.
Also sort the deps in the CMake file and put just one dep on each line.
[Parser] Avoid correcting delayed typos in array subscript multiple times.
We correct some typos in `ActOnArraySubscriptExpr` and
`ActOnOMPArraySectionExpr`, so when their result is `ExprError`, we can
end up correcting delayed typos in the same expressions again. In
general it is OK but when `NumTypos` is incorrect, we can hit the
assertion
> Assertion failed: (Entry != DelayedTypos.end() && "Failed to get the state for a TypoExpr!"), function getTypoExprState, file clang/lib/Sema/SemaLookup.cpp, line 5219.
Fix by replacing some subscript `ExprResult` with typo-corrected expressions
instead of keeping the original expressions. Thus if original expressions
contained `TypoExpr`, we'll use corrected expressions instead of trying to
correct them again.
Petr Hosek [Wed, 1 May 2019 16:52:45 +0000 (16:52 +0000)]
[Driver] Explicitly request platform rtlib in the Driver pic test
This test checks whether crtbegin.o and crtend.o appear on the link
line, but names of these files may be affected by the choice of the
rtlib, specifically when compiler-rt is used as the default rtlib
the names will be clang_rt.crtbegin.o and clang_rt.crtend.o instead
of crtbeginS.o and crtendS.o. To avoid the test failure, explicitly
request to use the platform rtlib.
Reference expected files not ending with a newline are normalized to
have said newlines. Additionally `plist-macros-with-expansion.cpp.plist`
is modified to add a line that is ignored by `%diff_plist`, but not by
the more sensitive pattern proposed by
http://lists.llvm.org/pipermail/cfe-dev/2019-April/061904.html for
`%normalize_plist`.
Hubert Tong [Wed, 1 May 2019 15:53:56 +0000 (15:53 +0000)]
[analyzer][tests] Use diff_plist, correct order of arguments for missed cases; NFC
For various files under `clang/test/Analysis`, D52036 applied
`%diff_plist` to replace `diff` invocations with certain options and
D56340 swapped the order of the arguments so that the reference file
comes first. The tests that used `tail` to filter the test output were
not modified accordingly. This patch applies the corresponding update
to those tests.
Tom Stellard [Wed, 1 May 2019 06:18:03 +0000 (06:18 +0000)]
lib/Header: Fix Visual Studio builds try #2
Summary:
This is a follow up to r355253 and a better fix than the first attempt
which was r359257.
We can't install anything from ${CMAKE_CFG_INTDIR}, because this value
is only defined at build time, but we still must make sure to copy the
headers into ${CMAKE_CFG_INTDIR}/lib/clang/$VERSION/include, because the lit
tests look for headers there. So for this fix we revert to the
old behavior of copying the headers to ${CMAKE_CFG_INTDIR}/lib/clang/$VERSION/include
during the build and then installing them from the source tree.
Dan Gohman [Tue, 30 Apr 2019 23:06:07 +0000 (23:06 +0000)]
[WebAssembly] Use the "wasm32-wasi" triple in tests
Similar to https://reviews.llvm.org/D61334, update clang tests to use the
"wasm32-wasi" triple, removing the "-musl" environment and omitting the
"-unknown" vendor.
Variable auto-init: don't initialize aggregate padding of all aggregates
Summary:
C guarantees that brace-init with fewer initializers than members in the
aggregate will initialize the rest of the aggregate as-if it were static
initialization. In turn static initialization guarantees that padding is
initialized to zero bits.
Quoth the Standard:
C17 6.7.9 Initialization ❡21
If there are fewer initializers in a brace-enclosed list than there are elements
or members of an aggregate, or fewer characters in a string literal used to
initialize an array of known size than there are elements in the array, the
remainder of the aggregate shall be initialized implicitly the same as objects
that have static storage duration.
C17 6.7.9 Initialization ❡10
If an object that has automatic storage duration is not initialized explicitly,
its value is indeterminate. If an object that has static or thread storage
duration is not initialized explicitly, then:
* if it has pointer type, it is initialized to a null pointer;
* if it has arithmetic type, it is initialized to (positive or unsigned) zero;
* if it is an aggregate, every member is initialized (recursively) according to
these rules, and any padding is initialized to zero bits;
* if it is a union, the first named member is initialized (recursively)
according to these rules, and any padding is initialized to zero bits;
Petr Hosek [Tue, 30 Apr 2019 19:35:14 +0000 (19:35 +0000)]
[Driver] Support compiler-rt crtbegin.o/crtend.o for Linux
When compiler-rt is selected as the runtime library for Linux targets
use its crtbegin.o/crtend.o implemenetation rather than platform one
if available.
[LibTooling] Change Transformer's TextGenerator to a partial function.
Summary:
Changes the signature of the TextGenerator std::function to return an Expected<std::string>
instead of std::string to allow for (non-fatal) failures. Previously, we
expected that any failures would be expressed with assertions. However, that's
unfriendly to running the code in servers or other places that don't want their
library calls to crash the program.
Correspondingly, updates Transformer's handling of failures in TextGenerators
and the signature of `ChangeConsumer`.
[analyzer][UninitializedObjectChecker] PR41611: Regard vector types as primitive
https://bugs.llvm.org/show_bug.cgi?id=41611
Similarly to D61106, the checker ran over an llvm_unreachable for vector types:
struct VectorSizeLong {
VectorSizeLong() {}
__attribute__((__vector_size__(16))) long x;
};
void __vector_size__LongTest() {
VectorSizeLong v;
}
Since, according to my short research,
"The vector_size attribute is only applicable to integral and float scalars,
although arrays, pointers, and function return values are allowed in conjunction
with this construct."
[src: https://gcc.gnu.org/onlinedocs/gcc-4.6.1/gcc/Vector-Extensions.html#Vector-Extensions]
[analyzer] Treat functions without run-time branches as "small".
Currently we always inline functions that have no branches, i.e. have exactly
three CFG blocks: ENTRY, some code, EXIT. This makes sense because when there
are no branches, it means that there's no exponential complexity introduced
by inlining such function. Such functions also don't trigger various fundamental
problems with our inlining mechanism, such as the problem of inlined
defensive checks.
Sometimes the CFG may contain more blocks, but in practice it still has
linear structure because all directions (except, at most, one) of all branches
turned out to be unreachable. When this happens, still treat the function
as "small". This is useful, in particular, for dealing with C++17 if constexpr.
Douglas Yung [Mon, 29 Apr 2019 22:57:15 +0000 (22:57 +0000)]
Make test more robust by writing stdout/stderr to different files.
Our internal build bots were failing this test randomly as the stderr
output was emitted to the file in the middle of the stdout output
line that the test was checking.