Petr Hosek [Fri, 18 May 2018 18:33:07 +0000 (18:33 +0000)]
[Support] Avoid normalization in sys::getDefaultTargetTriple
The return value of sys::getDefaultTargetTriple, which is derived from
-DLLVM_DEFAULT_TRIPLE, is used to construct tool names, default target,
and in the future also to control the search path directly; as such it
should be used textually, without interpretation by LLVM.
Normalization of this value may lead to unexpected results, for example
if we configure LLVM with -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-linux-gnu,
normalization will transform that value to x86_64--linux-gnu. Driver will
use that value to search for tools prefixed with x86_64--linux-gnu- which
may be confusing. This is also inconsistent with the behavior of the
--target flag which is taken as-is without any normalization and overrides
the value of LLVM_DEFAULT_TARGET_TRIPLE.
Users of sys::getDefaultTargetTriple already perform their own
normalization as needed, so this change shouldn't impact existing logic.
MC: Change the streamer ctors to take an object writer instead of a stream. NFCI.
The idea is that a client that wants split dwarf would create a
specific kind of object writer that creates two files, and use it to
create the streamer.
Summary:
Previously, clang-format's parser would fail to annotate the
selector in a single-component Objective-C method invocation with
`TT_SelectorName`. For example, the following:
Eric Liu [Fri, 18 May 2018 14:16:37 +0000 (14:16 +0000)]
Move #include manipulation code to new lib/Tooling/Inclusions.
Summary:
clangToolingCore is linked into almost everything (incl. clang), but
not few tools need #include manipulation at this point. So pull this into a
separate library in Tooling.
This patch aims to match the changes introduced
in gcc by https://gcc.gnu.org/ml/gcc-cvs/2018-04/msg00534.html.
The -mibt feature flag is being removed, and the -fcf-protection
option now also defines a CET macro and causes errors when used
on non-X86 targets, while X86 targets no longer check for -mibt
and -mshstk to determine if -fcf-protection is supported. -mshstk
is now used only to determine availability of shadow stack intrinsics.
Reid Kleckner [Thu, 17 May 2018 18:12:18 +0000 (18:12 +0000)]
Fix a mangling failure on clang-cl C++17
MethodVFTableLocations in MigrosoftVTableContext contains canonicalized
decl. But, it's sometimes asked to lookup for non-canonicalized decl,
and that causes assertion failure, and compilation failure.
Walter Lee [Thu, 17 May 2018 18:04:39 +0000 (18:04 +0000)]
[sanitizer] Don't add --export-dynamic for Myriad
This is to work around a bug in some versions of gnu ld, where
--export-dynamic implies -shared even if -static is explicitly given.
Myriad supports static linking only, so --export-dynamic is never
needed.
Justin Lebar [Thu, 17 May 2018 16:15:07 +0000 (16:15 +0000)]
[CUDA] Allow "extern __shared__ Foo foo[]" within anon. namespaces.
Summary:
Previously this triggered a -Wundefined-internal warning. But it's not
an undefined variable -- any variable of this form is a pointer to the
base of GPU core's shared memory.
Nico Weber [Thu, 17 May 2018 15:26:37 +0000 (15:26 +0000)]
Fix __uuidof handling on non-type template parameter in C++17
Clang used to pass the base lvalue of a non-type template parameter
to the template instantiation phase when the base part is __uuidof
and it's running in C++17 mode.
However, that drops its LValuePath, and unintentionally transforms
&__uuidof(...) to __uuidof(...).
This CL fixes that by passing whole expr. Fixes PR24986.
https://reviews.llvm.org/D46820?id=146557
Patch from Taiju Tsuiki <tzik@chromium.org>!
Peter Smith [Thu, 17 May 2018 13:17:33 +0000 (13:17 +0000)]
[AArch64] Correct inline assembly test case for S modifier [NFC]
The existing test for the AArch64 inline assembly constraint S uses the
A and L modifiers. These modifiers were implemented in the original
AArch64 backend but were not carried forward to the merged backend. The
A is associated with ADRP and does nothing, the L is associated with
:lo12: . Given that A and L are not supported by GCC and not supported
by the new implementation of constraint S in LLVM (see D46745) I've
altered the test to put :lo12: directly in the string so that A and L
are not needed.
Jan Korous [Thu, 17 May 2018 11:51:49 +0000 (11:51 +0000)]
Use dotted format of version tuple for availability diagnostics
E. g. use "10.11" instead of "10_11".
We are maintaining backward compatibility by parsing underscore-delimited version tuples but no longer keep track of the separator and using dot format for output.
Ivan Donchevskii [Thu, 17 May 2018 09:24:37 +0000 (09:24 +0000)]
[libclang] Allow skipping function bodies in preamble only
Second attempt. Fix line endings and warning.
As an addition to CXTranslationUnit_SkipFunctionBodies, provide the
new option CXTranslationUnit_LimitSkipFunctionBodiesToPreamble,
which constraints the skipping of functions bodies to the preamble
only. Function bodies in the main file are not affected if this
option is set.
Skipping function bodies only in the preamble is what clangd already
does and the introduced flag implements it for libclang clients.
Ivan Donchevskii [Thu, 17 May 2018 09:21:07 +0000 (09:21 +0000)]
[Frontend] Avoid running plugins during code completion parse
Second attempt. Proper line endings.
The parsing that is done for code completion is a special case that will
discard any generated diagnostics, so avoid running plugins for this
case in the first place to avoid performance penalties due to the
plugins.
A scenario for this is for example libclang with extra plugins like tidy.
Jacek Olesiak [Thu, 17 May 2018 08:35:15 +0000 (08:35 +0000)]
[clang-format] Fix putting ObjC message arguments in one line for multiline receiver
Summary:
Currently BreakBeforeParameter is set to true everytime message receiver spans multiple lines, e.g.:
```
[[object block:^{
return 42;
}] aa:42 bb:42];
```
will be formatted:
```
[[object block:^{
return 42;
}] aa:42
bb:42];
```
even though arguments could fit into one line. This change fixes this behavior.
Test Plan:
make -j12 FormatTests && tools/clang/unittests/Format/FormatTests
Ivan Donchevskii [Thu, 17 May 2018 07:31:29 +0000 (07:31 +0000)]
[libclang] Allow skipping function bodies in preamble only
As an addition to CXTranslationUnit_SkipFunctionBodies, provide the
new option CXTranslationUnit_LimitSkipFunctionBodiesToPreamble,
which constraints the skipping of functions bodies to the preamble
only. Function bodies in the main file are not affected if this
option is set.
Skipping function bodies only in the preamble is what clangd already
does and the introduced flag implements it for libclang clients.
Volodymyr Sapsai [Wed, 16 May 2018 18:28:58 +0000 (18:28 +0000)]
[Sema] Fix assertion when constructor is disabled with partially specialized template.
The added test case was triggering assertion
> Assertion failed: (!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && "Already set to a class template partial specialization!"), function setInstantiationOf, file clang/include/clang/AST/DeclTemplate.h, line 1825.
It was happening with ClassTemplateSpecializationDecl
`enable_if_not_same<int, int>`. Because this template is specialized for
equal types not to have a definition, it wasn't instantiated and its
specialization kind remained TSK_Undeclared. And because it was implicit
instantiation, we didn't mark the decl as invalid. So when we try to
find the best matching partial specialization the second time, we hit
the assertion as partial specialization is already set.
Fix by reusing stored partial specialization when available, instead of
looking for the best match every time.
[Modules] Do not diagnose missing import in recovery mode if there isn't a decl to lookup
Clang often tries to create implicit module import for error recovery,
which does a great job helping out with diagnostics. However, sometimes
clang does not have enough information given that it's using an invalid
context to move on. Be more strict in those cases to avoid crashes.
We hit crash on invalids because of this but unfortunately there are no
testcases and I couldn't manage to create one. The crashtrace however
indicates pretty clear why it's happening.
Alexey Bataev [Wed, 16 May 2018 15:08:32 +0000 (15:08 +0000)]
[OPENMP] DO not crash on combined constructs in declare target
functions.
If the combined construct is specified in the declare target function
and the device code is emitted, the compiler crashes because of the
incorrectly chosen captured stmt. We should choose the innermost
captured statement, not the outermost.
Sanjay Patel [Wed, 16 May 2018 14:38:07 +0000 (14:38 +0000)]
[OpenCL] make test independent of optimizer
There shouldn't be any tests that run the entire optimizer here,
but the last test in this file is definitely going to break with
a change in LLVM IR canonicalization. Change that part to check
the unoptimized IR because that's the real intent of this file.
Erich Keane [Wed, 16 May 2018 13:57:17 +0000 (13:57 +0000)]
Add support for __declspec(code_seg("segname"))
Add support for __declspec(code_seg("segname"))
This patch is built on the existing support for #pragma code_seg. The code_seg
declspec is allowed on functions and classes. The attribute enables the
placement of code into separate named segments, including compiler-generated
members and template instantiations.
For more information, please see the following:
https://msdn.microsoft.com/en-us/library/dn636922.aspx
A new CodeSeg attribute is used instead of adding a new spelling to the existing
Section attribute since they don’t apply to the same Subjects. Section
attributes are also added for the code_seg declspec since they are used for
#pragma code_seg. No CodeSeg attributes are added to the AST.
The patch is written to match with the Microsoft compiler’s behavior even where
that behavior is a little complicated (see https://reviews.llvm.org/D22931, the
Microsoft feedback page is no longer available since MS has removed the page).
That code is in getImplicitSectionAttrFromClass routine.
Diagnostics messages are added to match with the Microsoft compiler for code-seg
attribute mismatches on base and derived classes and virtual overrides.
Ivan Donchevskii [Wed, 16 May 2018 13:50:05 +0000 (13:50 +0000)]
[Frontend] Avoid running plugins during code completion parse
The parsing that is done for code completion is a special case that will
discard any generated diagnostics, so avoid running plugins for this
case in the first place to avoid performance penalties due to the
plugins.
A scenario for this is for example libclang with extra plugins like tidy.
Alexey Bataev [Wed, 16 May 2018 13:36:30 +0000 (13:36 +0000)]
[OPENMP, NVPTX] Add check for SPMD mode in orphaned parallel directives.
If the orphaned directive is executed in SPMD mode, we need to emit the
check for the SPMD mode and run the orphaned parallel directive in
sequential mode.
Henry Wong [Wed, 16 May 2018 12:37:53 +0000 (12:37 +0000)]
[analyzer] Improve the modeling of memset().
Since there is no perfect way bind the non-zero value with the default binding, this patch only considers the case where buffer's offset is zero and the char value is 0. And according to the value for overwriting, decide how to update the string length.
Ilya Biryukov [Wed, 16 May 2018 12:30:09 +0000 (12:30 +0000)]
[AST] Added a helper to extract a user-friendly text of a comment.
Summary:
The helper is used in clangd for documentation shown in code completion
and storing the docs in the symbols. See D45999.
This patch reuses the code of the Doxygen comment lexer, disabling the
bits that do command and html tag parsing.
The new helper works on all comments, including non-doxygen comments.
However, it does not understand or transform any doxygen directives,
i.e. cannot extract brief text, etc.
Although not very well known, diagtool is an incredibly convenient
utility for dealing with diagnostics.
Particularly useful are the "tree" and "show-enabled" commands:
- The former prints the hierarchy of diagnostic (warning) flags and
which of them are enabled by default.
- The latter can be used to replace an invocation to clang and will
print which diagnostics are disabled, warnings or errors.
For instance: `diagtool show-enabled -Wall -Werror /tmp/test.c` will
print that -Wunused-variable (warn_unused_variable) will be treated as
an error.
This patch adds them to the install target so it gets shipped with the
LLVM release. It also adds a very basic man page and mentions this
change in the release notes.
Francois Ferrand [Wed, 16 May 2018 08:25:03 +0000 (08:25 +0000)]
clang-format: Allow optimizer to break template declaration.
Summary:
Introduce `PenaltyBreakTemplateDeclaration` to control the penalty,
and change `AlwaysBreakTemplateDeclarations` to an enum with 3 modes:
* `No` for regular, penalty based, wrapping of template declaration
* `MultiLine` for always wrapping before multi-line declarations (e.g.
same as legacy behavior when `AlwaysBreakTemplateDeclarations=false`)
* `Yes` for always wrapping (e.g. same as legacy behavior when
`AlwaysBreakTemplateDeclarations=true`)
Francois Ferrand [Wed, 16 May 2018 08:03:52 +0000 (08:03 +0000)]
clang-format: tweak formatting of variable initialization blocks
Summary:
This patch changes the behavior of PenaltyBreakBeforeFirstCallParameter
so that is does not apply after a brace, when Cpp11BracedListStyle is
false.
This way, variable initialization is wrapped more like an initializer
than like a function call, which is more consistent with user
expectations for this braced list style.
With PenaltyBreakBeforeFirstCallParameter=200, this gives the following
code: (with Cpp11BracedListStyle=false)
Akira Hatanaka [Tue, 15 May 2018 21:00:30 +0000 (21:00 +0000)]
Address post-commit review comments after r328731. NFC.
- Define a function (canPassInRegisters) that determines whether a
record can be passed in registers based on language rules and
target-specific ABI rules.
- Set flag RecordDecl::ParamDestroyedInCallee to true in MSVC mode and
remove ASTContext::isParamDestroyedInCallee, which is no longer needed.
- Use the same type (unsigned) for RecordDecl's bit-field members.
For more background, see the following discussions that took place on
cfe-commits.
Sunil Srivastava [Tue, 15 May 2018 18:28:42 +0000 (18:28 +0000)]
Fixed some rtti-options tests.
Certain tests in rtti-options.cpp are not really testing anything because they are testing for the absence of -frtti option to the cc1 process. Since the cc1 process does not take -frtti option, these tests are passing tautologically.
The RTTI mode is enabled by default in cc1, and -fno-rtti disables it. Therefore the correct way to check for enabling of RTTI is to check for the absence of -fno-rtti to cc1, and the correct way to check for disabling of RTTI is to check for the presence of -fno-rtti to cc1.
Alexey Bataev [Tue, 15 May 2018 18:01:01 +0000 (18:01 +0000)]
[OPENMP, NVPTX] Do not globalize variables with reference/pointer types.
In generic data-sharing mode we do not need to globalize
variables/parameters of reference/pointer types. They already are placed
in the global memory.
Nicola Zaghen [Tue, 15 May 2018 13:30:56 +0000 (13:30 +0000)]
[clang] Update uses of DEBUG macro to LLVM_DEBUG.
The DEBUG() macro is very generic so it might clash with other projects.
The renaming was done as follows:
- git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
- git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM
Explicitly avoided changing the strings in the clang-format tests.
Rainer Orth [Tue, 15 May 2018 11:36:00 +0000 (11:36 +0000)]
[Solaris] Only define _REENTRANT if -pthread
When looking at lib/Basic/Targets/OSTargets.h, I noticed that _REENTRANT is defined
unconditionally on Solaris, unlike all other targets and what either Studio cc (only define
it with -mt) or gcc (only define it with -pthread) do.
Aleksei Sidorin [Tue, 15 May 2018 11:09:07 +0000 (11:09 +0000)]
[ASTImporter] Extend lookup logic in class templates
During import of a class template, lookup may find a forward
declaration and structural match falsely reports equivalency
between a forward decl and a definition. The result is that
some definitions are not imported if we had imported a forward
decl previously. This patch gives a fix.
Joel E. Denny [Tue, 15 May 2018 00:44:14 +0000 (00:44 +0000)]
[AST] Fix printing tag decl groups in decl contexts
For example, given:
struct T1 {
struct T2 *p0;
};
-ast-print produced:
struct T1 {
struct T2;
struct T2 *p0;
};
Compiling that produces a warning that the first struct T2 declaration
does not declare anything.
Details:
A tag decl group is one or more decls that share a type specifier that
is a tag decl (that is, a struct/union/class/enum decl). Within
functions, the parser builds such a tag decl group as part of a
DeclStmt. However, in decl contexts, such as file scope or a member
list, the parser does not group together the members of a tag decl
group. Previously, detection of tag decl groups during printing was
implemented but only if the tag decl was unnamed. Otherwise, as in
the above example, the members of the group did not print together and
so sometimes introduced warnings.
This patch extends detection of tag decl groups in decl contexts to
any tag decl that is recorded in the AST as not free-standing.
Richard Trieu [Mon, 14 May 2018 23:21:48 +0000 (23:21 +0000)]
Enable control flow pruning of float overflow warnings.
Like other conversion warnings, allow float overflow warnings to be disabled
in known dead paths of template instantiation. This often occurs when a
template template type is a numeric type and the template will check the
range of the numeric type before performing the conversion.
Volodymyr Sapsai [Mon, 14 May 2018 22:49:44 +0000 (22:49 +0000)]
[c++17] Fix assertion on synthesizing deduction guides after a fatal error.
After a fatal error Sema::InstantiatingTemplate doesn't allow further
instantiation and doesn't push a CodeSynthesisContext. When we tried to
synthesize implicit deduction guides from constructors we hit the
assertion
> Assertion failed: (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack"), function SubstType, file clang/lib/Sema/SemaTemplateInstantiate.cpp, line 1580.
Fix by avoiding deduction guide synthesis if InstantiatingTemplate is invalid.
George Karpenkov [Mon, 14 May 2018 21:39:54 +0000 (21:39 +0000)]
[analyzer] Extend the ObjCAutoreleaseWriteChecker to warn on captures as well
A common pattern is that the code in the block does not write into the
variable explicitly, but instead passes it to a helper function which
performs the write.
Richard Smith [Mon, 14 May 2018 20:52:48 +0000 (20:52 +0000)]
Fix regression in r332076.
If the name after 'template' is an unresolved using declaration (not containing
'typename'), then we don't yet know if it's a valid template-name, so don't
reject it prior to instantiation. Instead, treat it as naming a dependent
member of the current instantiation.
George Karpenkov [Mon, 14 May 2018 20:29:16 +0000 (20:29 +0000)]
Remove the fixit for the diagnostics regarding capturing autoreleasing variables in a block
The fixit is actively harmful, as it encourages developers to ignore the
warning and to write unsafe code.
It is almost impossible to write safe code while capturing autoreleasing
variables in the block, as in order to check that the block is never
called in the autoreleasing pool the developer has to check the
transitive closure of all potential callers of the block.
Joel E. Denny [Mon, 14 May 2018 19:36:45 +0000 (19:36 +0000)]
[AST] Print correct tag decl for tag specifier
For example, given:
void fn() {
struct T *p0;
struct T { int i; } *p1;
}
-ast-print produced:
void fn() {
struct T { int i; } *p0;
struct T { int i; } *p1;
}
Compiling that fails with a redefinition error.
Given:
void fn() {
struct T *p0;
struct __attribute__((deprecated)) T *p1;
}
-ast-print dropped the attribute.
Details:
For a tag specifier (that is, struct/union/class/enum used as a type
specifier in a declaration) that was also a tag declaration (that is,
first occurrence of the tag) or tag redeclaration (that is, later
occurrence that specifies attributes or a member list), clang printed
the tag specifier as either (1) the full tag definition if one
existed, or (2) the first tag declaration otherwise. Redefinition
errors were sometimes introduced, as in the first example above. Even
when that was impossible because no member list was ever specified,
attributes were sometimes lost, thus changing semantics and
diagnostics, as in the second example above.
This patch fixes a major culprit for these problems. It does so by
creating an ElaboratedType with a new OwnedDecl member wherever an
occurrence of a tag type is a (re)declaration of that tag type.
PrintingPolicy's IncludeTagDefinition used to trigger printing of the
member list, attributes, etc. for a tag specifier by using a tag
(re)declaration selected as described above. Now, it triggers the
same thing except it uses the tag (re)declaration stored in the
OwnedDecl. Of course, other tooling can now make use of the new
OwnedDecl as well.
Also, to be more faithful to the original source, this patch
suppresses printing of attributes inherited from previous
declarations.
Yaxun Liu [Mon, 14 May 2018 19:20:12 +0000 (19:20 +0000)]
CodeGen: Emit string literal in constant address space
Some targets have constant address space (e.g. amdgcn). For them string literal should be
emitted in constant address space then casted to default address space.
Diagnostics print _Bool as bool when the latter is defined as the
former. However, diagnostics were altering the printing policy for
-ast-print as well. The printed source was then invalid because the
preprocessor eats the bool definition.
Problematic diagnostics included suppressed warnings (e.g., add
-Wno-unused-value to the above example), including those that are
suppressed by default.
This patch fixes this bug and cleans up some related comments.
Craig Topper [Mon, 14 May 2018 17:50:40 +0000 (17:50 +0000)]
[X86] Use __builtin_convertvector to replace some of the avx512 truncate builtins.
As long as the destination type is a 256 or 128 bit vector with the same number of elements we can use __builtin_convertvector to directly generate trunc IR instruction which will be handled natively by the backend.
Aleksei Sidorin [Mon, 14 May 2018 16:12:31 +0000 (16:12 +0000)]
[ASTImporter] Turn StringRefs back to std::strings to avoid use-after-free
This is a workaround for the issue in buildASTFromCodeWithArgs()
where a local buffer can be used to store the program text
referred by SourceManager.
FIXME: Fix the root issue in buildASTFromCodeWithArgs().
Pavel Labath [Mon, 14 May 2018 11:02:23 +0000 (11:02 +0000)]
[CodeGen] Disable aggressive structor optimizations at -O0
Summary:
Removing the full structor and replacing all usages with the base one
can degrade debug quality as it will leave the debugger unable to locate
the full object structor. This is apparent when evaluating an expression
in the debugger which requires constructing an object of class which has
had this optimization applied to it. When compiling the expression, we
pretend that the class and its methods have been defined in another
compilation unit, so the expression compiler assumes the structor
definition must be available. This didn't use to be the case for
structors with internal linkage. Less aggressive optimizations like
emitting the full structor as an alias remain in place, as they do not
cause the structor symbol to disappear completely.
This improves debug quality on non-darwin platforms (darwin does not
have -mconstructor-aliases on by default, so it is spared these
problems) and enable us to remove some workarounds from LLDB which attempt to
mitigate this issue.
[clang-format] Continue after non-scope-closers in getLengthToMatchingParen
Summary:
This fixes a regression introduced by `r331857` where we stop the search for
the End token as soon as we hit a non-scope-closer, which prematurely stops before
semicolons for example, which should otherwise be considered as part of the unbreakable tail.
Added atomic_fetch_min, max, umin, umax intrinsics to clang.
These intrinsics work exactly as all other atomic_fetch_* intrinsics and allow to create *atomicrmw* with ordering.
Updated the clang-extensions document.
Douglas Yung [Sat, 12 May 2018 00:06:59 +0000 (00:06 +0000)]
Force the PS4 clang ABI version to 6.
The PS4 requires clang ABI version 6 for compatibility reasons. This change forces this and if the user specifies a different version when the PS4 target is specified, the compiler emits a warning that the specified version is being ignored.