Devin Coughlin [Thu, 21 Jan 2016 20:09:49 +0000 (20:09 +0000)]
[driver] Enable some static analyzer "unix" checkers on Windows.
Many of the "unix" checkers are not actually unix-specific and would be valuable
to run on Windows. This commit explicitly enables those checkers on
Windows.
Vedant Kumar [Thu, 21 Jan 2016 19:25:35 +0000 (19:25 +0000)]
[Coverage] Reduce complexity of adding function mapping records
Replace a string append operation in addFunctionMappingRecord with a
vector append. The existing behavior is quadratic in the worst case:
this patch makes it linear.
Aaron Ballman [Thu, 21 Jan 2016 15:18:25 +0000 (15:18 +0000)]
When dumping documentation for AST matchers, do something more useful with \see doxygen commands. Ideally this would link to the target of \see, but for now it translates \see into "See also: "
Regenerate the AST documentation for this new functionality.
Alexey Bataev [Wed, 20 Jan 2016 12:29:47 +0000 (12:29 +0000)]
[OPENMP 4.0] Fix for codegen of 'cancel' directive within 'sections' directive.
Allow to emit code for 'cancel' directive within 'sections' directive with single sub-section.
Alexey Bataev [Wed, 20 Jan 2016 09:07:54 +0000 (09:07 +0000)]
[OPENMP 4.5] Allow to use non-static data members in non-static member functions in 'private' clause.
OpenMP 4.5 allows to use non-static members of current class in non-static member functions in 'private' clause. Patch adds initial support for privatizing data members.
Alexey Bataev [Wed, 20 Jan 2016 05:25:51 +0000 (05:25 +0000)]
Fix infinite loop when ::new or ::delete are found in member initializer list, by Denis Zobnin
Fix for an infinite loop on parsing ::new or ::delete in member initializer list, found by fuzzing PR23057, comment #33. Skip the rest of the member initializers if the previous initializer was invalid.
Differential Revision: http://reviews.llvm.org/D16216
Adrian Prantl [Wed, 20 Jan 2016 01:29:34 +0000 (01:29 +0000)]
Module Debugging: Fine-tune the condition that determines whether a type
can be found in a module.
There are externally visible anonymous types that can be found:
typedef struct { } s; // I can be found via the typedef.
There are anonymous internal types that can be found:
namespace { struct s {}; } // I can be found by name.
Adrian Prantl [Tue, 19 Jan 2016 23:42:53 +0000 (23:42 +0000)]
Module Debugging: Don't emit external type references to anonymous types.
Even if they exist in the module, they can't be matched with the forward
declaration in the object file.
<rdar://problem/24199640>
Chris Bieneman [Tue, 19 Jan 2016 23:01:38 +0000 (23:01 +0000)]
[CMake] Don't apply Export set to clang tools
I can't apply export to tools without getting some strange CMake spew. The behavior here is a bit unexpected. CMake is complaining about static link dependencies not being in the same export set, which shouldn't matter.
In the short term it is easier to just remove the export set (which was just added in r258209) while I sort this out.
Chris Bieneman [Tue, 19 Jan 2016 22:41:51 +0000 (22:41 +0000)]
[CMake] Creating add_clang_tool macro to wrap add_clang_executable and generate install actions and targets.
This change brings forward the LLVM convention that "executables" are just runnable binaries, and "tools" are executables that are part of the project's install.
Having this abstraction will allow us to simplify some of the tool CMakeLists files, and it will standardize some of the install behaviors.
Samuel Antao [Tue, 19 Jan 2016 20:40:49 +0000 (20:40 +0000)]
[OpenMP] Detect implicit map type to report unspecified map type for target enter/exit data directives.
Support for the following OpenMP 4.5 restriction on 'target enter data' and 'target exit data':
- A map-type must be specified in all map clauses.
I have to save 'IsMapTypeImplicit' when parsing a map clause to support this constraint and for more informative error messages. This helps me support the following case:
#pragma omp target enter data map(r) // expected-error {{map type must be specified for '#pragma omp target enter data'}}
and distinguish it from:
#pragma omp target enter data map(tofrom: r) // expected-error {{map type 'tofrom' is not allowed for '#pragma omp target enter data'}}
Adrian Prantl [Tue, 19 Jan 2016 18:02:47 +0000 (18:02 +0000)]
Module Debugging: Defer the emission of anonymous tag decls
until we are visiting their declcontext.
This fixes a regression introduced in r256962:
When building debug info for a typdef'd anonymous tag type, we would be
visiting the inner anonymous type first thus creating a "typedef changes
linkage of anonymous type, but linkage was already computed" error.
Nico Weber [Tue, 19 Jan 2016 15:15:31 +0000 (15:15 +0000)]
Add -Wexpansion-to-undefined: warn when using `defined` in a macro definition.
[cpp.cond]p4:
Prior to evaluation, macro invocations in the list of preprocessing
tokens that will become the controlling constant expression are replaced
(except for those macro names modified by the 'defined' unary operator),
just as in normal text. If the token 'defined' is generated as a result
of this replacement process or use of the 'defined' unary operator does
not match one of the two specified forms prior to macro replacement, the
behavior is undefined.
This isn't an idle threat, consider this program:
#define FOO
#define BAR defined(FOO)
#if BAR
...
#else
...
#endif
clang and gcc will pick the #if branch while Visual Studio will take the
#else branch. Emit a warning about this undefined behavior.
One problem is that this also applies to function-like macros. While the
example above can be written like
there is no easy way to rewrite a function-like macro like `#define FOO(x)
(defined __foo_##x && __foo_##x)`. Function-like macros like this are used in
practice, and compilers seem to not have differing behavior in that case. So
this a default-on warning only for object-like macros. For function-like
macros, it is an extension warning that only shows up with `-pedantic`.
(But it's undefined behavior in both cases.)
Faisal Vali [Tue, 19 Jan 2016 03:58:55 +0000 (03:58 +0000)]
Fix PR26134: When substituting into default template arguments, keep CurContext unchanged.
Or, do not set Sema's CurContext to the template declaration's when substituting into default template arguments of said template declaration.
If we do push the template declaration context on to Sema, and the template declaration is at namespace scope, Sema can get confused and try and do odr analysis when substituting into default template arguments, even though the substitution could be occurring within a dependent context.
I'm not sure why this was being done, perhaps there was concern that if a default template argument referred to a previous template parameter, it might not be found during substitution - but all regression tests pass, and I can't craft a test that would cause it to fails (if some one does, please inform me, and i'll craft a different fix for the PR).
This patch removes a single line of code, but unfortunately adds more than it removes, because of the tests. Some day I still hope to commit a patch that removes far more lines than it adds, while leaving clang better for it ;)
Sorry that r253590 ("Change the expression evaluation context from Unevaluated to ConstantEvaluated while substituting into non-type template argument defaults") caused the PR!
Aaron Ballman [Mon, 18 Jan 2016 20:28:57 +0000 (20:28 +0000)]
Augments r258042; changes the AST matcher tests to use matchesNot and EXPECT_TRUE instead of EXPECT_FALSE. Adds a matcher test to ensure that static member functions are properly handled. Generates the documentation from the matcher.
Devin Coughlin [Mon, 18 Jan 2016 18:53:33 +0000 (18:53 +0000)]
[analyzer] Nullability: Look through implicit casts when suppressing warnings on return.
In r256567 I changed the nullability checker to suppress warnings about returning a null
value from a function/method with a non-null return type when the type of the returned
expression is itself nonnull. This enables the programmer to silence nullability warnings
by casting to _Nonnull:
return (SomeObject * _Nonnull)nil;
Unfortunately, under ObjC automated reference counting, Sema adds implicit casts to
_Nonnull to return expressions of nullable or unspecified types in functions with
non-null function/method return types. With r256567, these casts cause all nullability
warnings for returns of reference-counted types to be suppressed under ARC, leading to
false negatives.
This commit updates the nullability checker to look through implicit casts before
determining the type of the returned expression. It also updates the tests to turn on
ARC for the nullability_nullonly.mm testfile and adds a new testfile to test when ARC
is turned off.
David Majnemer [Sun, 17 Jan 2016 07:09:24 +0000 (07:09 +0000)]
[MS ABI] Don't crash while mangling recursive lambdas
We might get into bad situations where we try to embed the signature of
an inner lambda into an outer lambda which cannot work: the inner lambda
wants to embed the name of the outer lambda!
Instead, omit the return type for lambdas.
This fixes PR26105.
N.B. While we are here, make lambdas nested within functions use an
artificial scope so that they can get demangled.
NAKAMURA Takumi [Sat, 16 Jan 2016 03:44:52 +0000 (03:44 +0000)]
[Cygwin] Use -femulated-tls by default since r257718 introduced the new pass.
FIXME: Add more targets to use emutls into clang/test/Driver/emulated-tls.cpp.
FIXME: Add cygwin tests into llvm/test/CodeGen/X86. Working in progress.
Justin Lebar [Sat, 16 Jan 2016 03:30:08 +0000 (03:30 +0000)]
Respect bound archs, even when they don't alter the toolchain.
Summary:
It's possible to BindArch without changing the toolchain at all. For
example, armv7 and armv7s have exactly the same toolchain triple.
Therefore the code in the Driver that checks that we're not creating a
job for the same Action twice needs to consider (Action, Toolchain,
BoundArch) tuples.
Nico Weber [Fri, 15 Jan 2016 21:45:31 +0000 (21:45 +0000)]
Make -Wdelete-non-virtual-dtor warn on explicit `a->~A()` dtor calls too.
-Wdelete-non-virtual-dtor warns if A is a type with virtual functions but
without virtual dtor has its constructor called via `delete a`. This makes the
warning also fire if the dtor is called via `a->~A()`. This would've found a
security bug in Chromium at compile time. Fixes PR26137.
To fix the warning, add a virtual destructor, make the class final, or remove
its other virtual methods. If you want to silence the warning, there's also
a fixit that shows how:
test.cc:12:3: warning: destructor called on 'B' ... [-Wdelete-non-virtual-dtor]
b->~B();
^
test.cc:12:6: note: qualify call to silence this warning
b->~B();
^
B::
Devin Coughlin [Fri, 15 Jan 2016 21:35:40 +0000 (21:35 +0000)]
[analyzer] Check for return of nil in ObjC methods with nonnull return type.
Update NullabilityChecker so that it checks return statements in ObjC methods.
Previously it was returning early because methods do not have a function type.
Also update detection of violated parameter _Nonnull preconditions to handle
ObjC methods.
Chris Bieneman [Fri, 15 Jan 2016 21:21:12 +0000 (21:21 +0000)]
[CMake] Support generation of linker order files using dtrace
Summary:
This patch extends the lit-based perf-training tooling supplied for PGO data generation to also generate linker order files using dtrace.
This patch should work on any system that has dtrace. If CMake can find the dtrace tool it will generate a target 'generate-order-file' which will run the per-training tests wrapped by dtrace to capture function entries. There are several algorithms implemented for sorting the order files which can be experimented with for best performance. The dtrace wrapper also supports bot oneshot and pid probes.
The perf-helper.py changes to support order file construction are ported from internal changes by ddunbar; he gets all the credit for the hard work here, I just copy and pasted.
Note: I've tested these patches on FreeBSD and OS X 10.10.
Artem Dergachev [Fri, 15 Jan 2016 15:22:05 +0000 (15:22 +0000)]
[analyzer] Provide .def-files and visitors for SVal/SymExpr/MemRegion, v2.
Provide separate visitor templates for the three hierarchies, and also
the `FullSValVisitor' class, which is a union of all three visitors.
Additionally, add a particular example visitor, `SValExplainer', in order to
test the visitor templates. This visitor is capable of explaining the SVal,
SymExpr, or MemRegion in a natural language.
Compared to the reverted r257605, this fixes the test that used to fail
on some triples, and fixes build failure under -fmodules.
Richard Trieu [Fri, 15 Jan 2016 05:48:38 +0000 (05:48 +0000)]
Fixing more issues with template type diffing
1) Print qualifiers for templates with zero arguments
2) Add a few more tests for the template type diffing refactoring.
Specifically, PR24587 has been fixed and has a test case from
http://reviews.llvm.org/D15384
3) Adds asserts to check the DiffTree is in correct state when moving nodes
4) Rename the field FromType and ToType since it is heavily used within
member functions.
Richard Trieu [Fri, 15 Jan 2016 05:01:53 +0000 (05:01 +0000)]
Add new diff modes to template type diffing.
Remove an old assertion that does not hold. It is possible for a template
argument to be a declaration in one instantiation and an integer in another.
Create two new diff kinds for these (decl vs int and int vs decl).
Alexey Bataev [Fri, 15 Jan 2016 04:36:32 +0000 (04:36 +0000)]
PR26111: segmentation fault with __attribute__((mode(QI))) on function declaration, by Denis Zobnin
Allow "mode" attribute to be applied to VarDecl, not ValueDecl (which includes FunctionDecl and EnumConstantDecl), emit an error if this attribute is used with function declarations and enum constants.
Differential Revision: http://reviews.llvm.org/D16112
Alexey Bataev [Fri, 15 Jan 2016 04:06:31 +0000 (04:06 +0000)]
[X86] Support 'interrupt' attribute for x86
This attribute may be attached to a function definition and instructs the backend to generate appropriate function entry/exit code so that
it can be used directly as an interrupt handler.
The IRET instruction, instead of the RET instruction, is used to return from interrupt or exception handlers. All registers, except for the EFLAGS register which is restored by the IRET instruction, are preserved by the compiler.
Any interruptible-without-stack-switch code must be compiled with -mno-red-zone since interrupt handlers can and will, because of the hardware design, touch
the red zone.
interrupt handler must be declared with a mandatory pointer argument:
struct interrupt_frame;
__attribute__ ((interrupt))
void f (struct interrupt_frame *frame) {
...
}
and user must properly define the structure the pointer pointing to.
exception handler:
The exception handler is very similar to the interrupt handler with a different mandatory function signature:
#ifdef __x86_64__
typedef unsigned long long int uword_t;
#else
typedef unsigned int uword_t;
#endif
struct interrupt_frame;
__attribute__ ((interrupt))
void f (struct interrupt_frame *frame, uword_t error_code) {
...
}
and compiler pops the error code off stack before the IRET instruction.
The exception handler should only be used for exceptions which push an error code and all other exceptions must use the interrupt handler.
The system will crash if the wrong handler is used.
Differential Revision: http://reviews.llvm.org/D15709
Akira Hatanaka [Fri, 15 Jan 2016 03:34:06 +0000 (03:34 +0000)]
[CodeGen] Attach attributes to thread local wrapper function.
This commit is a follow-up to r251734, r251476, and r249735, which fixes
a bug where function attributes were not attached to thread local
wrapper functions.
Richard Smith [Fri, 15 Jan 2016 03:24:18 +0000 (03:24 +0000)]
When copying whitespace flags from the token naming a macro argument onto the
first token of the expansion, don't forget to copy the "is at the start of a
line" token (which is always false, as newlines cannot appear within a macro
body); otherwise, stringizing the result can insert spurious whitespace.
Richard Trieu [Fri, 15 Jan 2016 02:55:17 +0000 (02:55 +0000)]
Save the integer type for integral template arguments.
Save the integer type when diffing integers in template type diffing. When
integers are different sizes, print out the type along with the integer value.
Also with the type information, print true and false instead of 1 and 0 for
boolean values.
Richard Trieu [Fri, 15 Jan 2016 01:08:56 +0000 (01:08 +0000)]
Make template type diffing use the new desguared iterator.
If available, use the canonical template argument to fill in information for
template type diffing instead of attempting to special case and evaluate Expr's
for the value. Since those are the values used in template instantiation,
we don't have to worry about difference between our evaluator and theirs. Also
move the nullptr template arguments from DiffKind::Expression to
DiffKind::Declaration and allow DiffKind::Declaration to set an Expr. The only
effect that should result is that a named nullptr will show up as
'ptr aka nullptr' in diagnostics.
Justin Lebar [Thu, 14 Jan 2016 23:31:30 +0000 (23:31 +0000)]
[CUDA] Warn undeclared identifiers in CUDA kernel calls
Value, type, and instantiation dependence were not being handled
correctly for CUDAKernelCallExpr AST nodes. As a result, if an
undeclared identifier was used in the triple-angle-bracket kernel call
configuration, there would be no error during parsing, and there would
be a crash during code gen. This patch makes sure that an error will be
issued during parsing in this case, just as there would be for any other
use of an undeclared identifier in C++.
Richard Trieu [Thu, 14 Jan 2016 23:30:12 +0000 (23:30 +0000)]
Change the TSTiterator in Template Type Diffing.
Modify the TSTiterator to have two internal iterators, which will walk
the provided sugared type and the desugared type. This will provide better
access to the template argument information. No functional changes.
Richard Trieu [Thu, 14 Jan 2016 22:56:39 +0000 (22:56 +0000)]
Refactor template type diffing
1) Instead of using pairs of From/To* fields, combine fields into a struct
TemplateArgInfo and have two in each DiffNode.
2) Use default initialization in DiffNode so that the constructor shows the
only field that is initialized differently on construction.
3) Use Set and Get functions per each DiffKind to make sure all fields for the
diff is set. In one case, the Expr fields were not set.
4) Don't print boolean literals for boolean template arguments. This prevents
printing 'false aka 0'
Only #3 has a functional change, which is reflected in the test change.
Justin Lebar [Thu, 14 Jan 2016 21:41:27 +0000 (21:41 +0000)]
[CUDA] Invoke ptxas and fatbinary during compilation.
Summary:
Previously we compiled CUDA device code to PTX assembly and embedded
that asm as text in our host binary. Now we compile to PTX assembly and
then invoke ptxas to assemble the PTX into a cubin file. We gather the
ptx and cubin files for each of our --cuda-gpu-archs and combine them
using fatbinary, and then embed that into the host binary.
Adds two new command-line flags, -Xcuda_ptxas and -Xcuda_fatbinary,
which pass args down to the external tools.
Andrey Bokhanko [Thu, 14 Jan 2016 10:41:16 +0000 (10:41 +0000)]
PR25910: clang allows two var definitions with the same mangled name
Proper diagnostic and resolution of mangled names' conflicts in variables.
When there is a declaration and a definition using the same name but different
types, we emit what is in the definition. When there are two conflicting
definitions, we issue an error.