]> granicus.if.org Git - clang/log
clang
5 years ago[Driver] Fix accidentally reversed condition in r349752
Michal Gorny [Thu, 20 Dec 2018 13:27:37 +0000 (13:27 +0000)]
[Driver] Fix accidentally reversed condition in r349752

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349754 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[SystemZ] Improve testing of vecintrin.h intrinsics
Ulrich Weigand [Thu, 20 Dec 2018 13:10:47 +0000 (13:10 +0000)]
[SystemZ] Improve testing of vecintrin.h intrinsics

This adds assembly-level tests to verify that the high-level
intrinsics generate the instructions they're supposed to.
These tests would have caught the codegen bugs I just fixed.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349753 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoReplace getOS() == llvm::Triple::*BSD with isOS*BSD() [NFCI]
Michal Gorny [Thu, 20 Dec 2018 13:09:30 +0000 (13:09 +0000)]
Replace getOS() == llvm::Triple::*BSD with isOS*BSD() [NFCI]

Replace multiple comparisons of getOS() value with FreeBSD, NetBSD,
OpenBSD and DragonFly with matching isOS*BSD() methods.  This should
improve the consistency of coding style without changing the behavior.
Direct getOS() comparisons were left whenever used in switch or switch-
like context.

Differential Revision: https://reviews.llvm.org/D55916

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349752 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[SystemZ] Fix wrong codegen caused by typos in vecintrin.h
Ulrich Weigand [Thu, 20 Dec 2018 13:09:09 +0000 (13:09 +0000)]
[SystemZ] Fix wrong codegen caused by typos in vecintrin.h

The following two bugs in SystemZ high-level vector intrinsics are
fixes by this patch:

- The float case of vec_insert_and_zero should generate a VLLEZF
  pattern, but currently erroneously generates VLLEZLF.

- The float and double versions of vec_orc erroneously generate
  and-with-complement instead of or-with-complement.

The patch also fixes a couple of typos in the associated test.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349751 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[X86][SSE] Auto upgrade PADDS/PSUBS intrinsics to SADD_SAT/SSUB_SAT generic intrinsic...
Simon Pilgrim [Thu, 20 Dec 2018 11:53:45 +0000 (11:53 +0000)]
[X86][SSE] Auto upgrade PADDS/PSUBS intrinsics to SADD_SAT/SSUB_SAT generic intrinsics (clang)

This emits SADD_SAT/SSUB_SAT generic intrinsics for the SSE signed saturated math intrinsics.

LLVM counterpart: https://reviews.llvm.org/D55894

Differential Revision: https://reviews.llvm.org/D55890

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349743 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Sema] Better static assert diagnostics for expressions involving temporaries/casts...
Clement Courbet [Thu, 20 Dec 2018 09:05:15 +0000 (09:05 +0000)]
[Sema] Better static assert diagnostics for expressions involving temporaries/casts/....

Summary:
Handles expressions such as:
 - `std::is_const<T>()`
 - `std::is_const<T>()()`;
 - `std::is_same(decltype(U()), V>::value`;

Reviewers: aaron.ballman, Quuxplusone

Subscribers: cfe-commits, llvm-commits

Differential Revision: https://reviews.llvm.org/D55552

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349729 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] pr38668: Do not attempt to cast loaded values of non-scalar types.
Artem Dergachev [Wed, 19 Dec 2018 23:48:44 +0000 (23:48 +0000)]
[analyzer] pr38668: Do not attempt to cast loaded values of non-scalar types.

It is expected to have the same object (memory region) treated as if it has
different types in different program points. The correct behavior for
RegionStore when an object is stored as an object of type T1 but loaded as
an object of type T2 is to store the object as if it has type T1 but cast it
to T2 during load.

Note that the cast here is some sort of a "reinterpret_cast" (even in C). For
instance, if you store a float and load an integer, you won't have your float
rounded to an integer; instead, you will have garbage.

Admit that we cannot perform the cast as long as types we're dealing with are
non-trivial (neither integers, nor pointers).

Of course, if the cast is not necessary (eg, T1 == T2), we can still load the
value just fine.

Differential Revision: https://reviews.llvm.org/D55875

rdar://problem/45062567

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349701 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] GenericTaint: Fix formatting to prepare for incoming improvements.
Artem Dergachev [Wed, 19 Dec 2018 23:35:08 +0000 (23:35 +0000)]
[analyzer] GenericTaint: Fix formatting to prepare for incoming improvements.

Patch by Gábor Borsik!

Differential Revision: https://reviews.llvm.org/D54918

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349698 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] Improve modeling for returning an object from the top frame with RVO.
Artem Dergachev [Wed, 19 Dec 2018 23:14:06 +0000 (23:14 +0000)]
[analyzer] Improve modeling for returning an object from the top frame with RVO.

Static Analyzer processes the program function-by-function, sometimes diving
into other functions ("inlining" them). When an object is returned from an
inlined function, Return Value Optimization is modeled, and the returned object
is constructed at its return location directly.

When an object is returned from the function from which the analysis has started
(the top stack frame of the analysis), the return location is unknown. Model it
with a SymbolicRegion based on a conjured symbol that is specifically tagged for
that purpose, because this is generally the correct way to symbolicate
unknown locations in Static Analyzer.

Fixes leak false positives when an object is returned from top frame in C++17:
objects that are put into a SymbolicRegion-based memory region automatically
"escape" and no longer get reported as leaks. This only applies to C++17 return
values with destructors, because it produces a redundant CXXBindTemporaryExpr
in the call site, which confuses our liveness analysis. The actual fix
for liveness analysis is still pending, but it is no longer causing problems.

Additionally, re-enable temporary destructor tests in C++17.

Differential Revision: https://reviews.llvm.org/D55804

rdar://problem/46217550

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349696 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoDisable -faddsig by default for PS4 target.
Douglas Yung [Wed, 19 Dec 2018 22:45:26 +0000 (22:45 +0000)]
Disable -faddsig by default for PS4 target.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349691 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] CStringChecker: Add the forgotten test file.
Artem Dergachev [Wed, 19 Dec 2018 21:51:59 +0000 (21:51 +0000)]
[analyzer] CStringChecker: Add the forgotten test file.

Differential Revision: https://reviews.llvm.org/D55873

rdar://problem/45366551

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349683 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] CStringChecker: Fix a crash on C++ overloads of standard functions.
Artem Dergachev [Wed, 19 Dec 2018 21:50:46 +0000 (21:50 +0000)]
[analyzer] CStringChecker: Fix a crash on C++ overloads of standard functions.

It turns out that it's not all that uncommon to have a C++ override of, say,
memcpy that receives a structure (or two) by reference (or by value, if it's
being copied from) and copies memory from it (or into it, if it's passed
by reference). In this case the argument will be of structure type (recall that
expressions of reference type do not exist: instead, C++ classifies expressions
into prvalues and lvalues and xvalues).

In this scenario we crash because we are trying to assume that, say,
a memory region is equal to an empty CompoundValue (the non-lazy one; this is
what makeZeroVal() return for compound types and it represents prvalue of
an object that is initialized with an empty initializer list).

Add defensive checks.

Differential Revision: https://reviews.llvm.org/D55873

rdar://problem/45366551

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349682 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoPR40096: Forwards-compatible with C++20 rule regarding aggregates not having user...
David Blaikie [Wed, 19 Dec 2018 19:33:35 +0000 (19:33 +0000)]
PR40096: Forwards-compatible with C++20 rule regarding aggregates not having user-declared ctors

Looks like these were in place to make these types move-only. That's
generally not a feature that the type should prescribe (unless it's an
inherent limitation) - instead leaving it up to the users of a type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349669 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[OPENMP]Mark the loop as started when initialized.
Alexey Bataev [Wed, 19 Dec 2018 18:16:37 +0000 (18:16 +0000)]
[OPENMP]Mark the loop as started when initialized.

Need to mark the loop as started when the initialization statement is
found. It is required to prevent possible incorrect loop iteraton
variable detection during template instantiation and fix the compiler
crash during the codegen.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349657 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[CodeComplete] Properly determine qualifiers of 'this' in a lambda
Ilya Biryukov [Wed, 19 Dec 2018 18:01:24 +0000 (18:01 +0000)]
[CodeComplete] Properly determine qualifiers of 'this' in a lambda

Summary:
The clang used to pick up the qualifiers of the lamba's call operator
(which is always const) and fail to show non-const methods of 'this' in
completion results.

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D55885

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349655 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Driver] [NetBSD] Add -D_REENTRANT when using sanitizers
Michal Gorny [Wed, 19 Dec 2018 17:25:59 +0000 (17:25 +0000)]
[Driver] [NetBSD] Add -D_REENTRANT when using sanitizers

NetBSD intends to support only reentrant interfaces in interceptors.
When -lpthread is used without _REENTRANT defined, things are
not guaranteed to work.

This is especially important for <stdio.h> and sanitization of
interfaces around FILE.  Some APIs have alternative modes depending
on the _REENTRANT definition, and NetBSD intends to support sanitization
of the _REENTRANT ones.

Differential Revision: https://reviews.llvm.org/D55654

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349650 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Driver] Add .hasAnySanitizer() to SanitizerArgs
Michal Gorny [Wed, 19 Dec 2018 17:25:55 +0000 (17:25 +0000)]
[Driver] Add .hasAnySanitizer() to SanitizerArgs

Add a simple method to query whether any sanitizer was enabled,
via SanitizerArgs.  This will be used in the NetBSD driver to pass
additional definitions that are required by all sanitizers.

Differential Revision: https://reviews.llvm.org/D55832

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349649 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Basic] Correct description of SanitizerSet.empty()
Michal Gorny [Wed, 19 Dec 2018 17:25:51 +0000 (17:25 +0000)]
[Basic] Correct description of SanitizerSet.empty()

Differential Revision: https://reviews.llvm.org/D55830

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349648 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Driver] Disable -faddrsig by default on NetBSD
Michal Gorny [Wed, 19 Dec 2018 17:25:46 +0000 (17:25 +0000)]
[Driver] Disable -faddrsig by default on NetBSD

Avoid passing -faddrsig by default on NetBSD.  This platform is still
using old GNU binutils that crashes on executables containing those
sections.

Differential Revision: https://reviews.llvm.org/D55828

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349647 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[OpenMP] Fix data sharing analysis in nested clause
Joel E. Denny [Wed, 19 Dec 2018 15:59:47 +0000 (15:59 +0000)]
[OpenMP] Fix data sharing analysis in nested clause

Without this patch, clang doesn't complain that X needs explicit data
sharing attributes in the following:

```
 #pragma omp target teams default(none)
 {
   #pragma omp parallel num_threads(X)
     ;
 }
```

However, clang does produce that complaint after the braces are
removed.  With this patch, clang complains in both cases.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D55861

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349635 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[X86][SSE] Auto upgrade PADDUS/PSUBUS intrinsics to UADD_SAT/USUB_SAT generic intrins...
Simon Pilgrim [Wed, 19 Dec 2018 14:43:47 +0000 (14:43 +0000)]
[X86][SSE] Auto upgrade PADDUS/PSUBUS intrinsics to UADD_SAT/USUB_SAT generic intrinsics (clang)

Sibling patch to D55855, this emits UADD_SAT/USUB_SAT generic intrinsics for the SSE saturated math intrinsics instead of expanding to a IR code sequence that could be difficult to reassemble.

Differential Revision: https://reviews.llvm.org/D55879

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349631 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoPortable Python script across Python version
Serge Guelton [Wed, 19 Dec 2018 13:46:13 +0000 (13:46 +0000)]
Portable Python script across Python version

urllib2 as been renamed into urllib and the library layout has changed.
Workaround that in a consistent manner.

Differential Revision: https://reviews.llvm.org/D55199

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349627 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Index] Index paremeters in lambda expressions.
Haojian Wu [Wed, 19 Dec 2018 13:44:41 +0000 (13:44 +0000)]
[Index] Index paremeters in lambda expressions.

Summary: This fixes clangd couldn't find references for lambda parameters.

Reviewers: ilya-biryukov

Subscribers: ioeric, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D55437

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349626 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoUse "EvaluateAsRValue" instead of as a known int, because if it's not a known
Bill Wendling [Wed, 19 Dec 2018 04:54:29 +0000 (04:54 +0000)]
Use "EvaluateAsRValue" instead of as a known int, because if it's not a known
integer we want to emit a diagnostic instead of asserting.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349604 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoRevert accidentally included code.
Bill Wendling [Wed, 19 Dec 2018 04:36:42 +0000 (04:36 +0000)]
Revert accidentally included code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349603 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Driver] Also obey -nostdlib++ when rewriting -lstdc++.
Dan Albert [Tue, 18 Dec 2018 23:29:35 +0000 (23:29 +0000)]
[Driver] Also obey -nostdlib++ when rewriting -lstdc++.

Reviewers: pirama

Reviewed By: pirama

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D55856

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349570 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoEmit ASM input in a constant context
Bill Wendling [Tue, 18 Dec 2018 22:54:03 +0000 (22:54 +0000)]
Emit ASM input in a constant context

Summary:
Some ASM input constraints (e.g., "i" and "n") require immediate values. At O0,
very few code transformations are performed. So if we cannot resolve to an
immediate when emitting the ASM input we shouldn't delay its processing.

Reviewers: rsmith, efriedma

Reviewed By: efriedma

Subscribers: rehana, efriedma, craig.topper, jyknight, cfe-commits

Differential Revision: https://reviews.llvm.org/D55616

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349561 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[OPENMP] parsing and sema support for 'close' map-type-modifier
Kelvin Li [Tue, 18 Dec 2018 22:18:41 +0000 (22:18 +0000)]
[OPENMP] parsing and sema support for 'close' map-type-modifier

A map clause with the close map-type-modifier is a hint to
prefer that the variables are mapped using a copy into faster
memory.

Patch by Ahsan Saghir (saghir)

Differential Revision: https://reviews.llvm.org/D55719

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349551 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoFix errors with the Clang natvis file.
Aaron Ballman [Tue, 18 Dec 2018 21:42:20 +0000 (21:42 +0000)]
Fix errors with the Clang natvis file.

This updates the FunctionProtoType visualizer to use the proper bits for determining parameter information and the DeclarationName visualizer to use the detail namespace. It also adds support for viewing newer special declaration names (like deduction guides).

Patch with help of Bruno Ricci.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349547 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[CodeGen] Handle mixed-width ops in mixed-sign mul-with-overflow lowering
Vedant Kumar [Tue, 18 Dec 2018 21:05:03 +0000 (21:05 +0000)]
[CodeGen] Handle mixed-width ops in mixed-sign mul-with-overflow lowering

The special lowering for __builtin_mul_overflow introduced in r320902
fixed an ICE seen when passing mixed-sign operands to the builtin.

This patch extends the special lowering to cover mixed-width, mixed-sign
operands. In a few common scenarios, calls to muloti4 will no longer be
emitted.

This should address the latest comments in PR34920 and work around the
link failure seen in:

  https://bugzilla.redhat.com/show_bug.cgi?id=1657544

Testing:
- check-clang
- A/B output comparison with: https://gist.github.com/vedantk/3eb9c88f82e5c32f2e590555b4af5081

Differential Revision: https://reviews.llvm.org/D55843

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349542 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[OPENMP][NVPTX]Emit shared memory buffer for reduction as 128 bytes
Alexey Bataev [Tue, 18 Dec 2018 21:01:42 +0000 (21:01 +0000)]
[OPENMP][NVPTX]Emit shared memory buffer for reduction as 128 bytes
buffer.

Seems to me, nvlink has a bug with the proper support of the weakly
linked symbols. It does not allow to define several shared memory buffer
with the different sizes even with the weak linkage. Instead we always
use 128 bytes buffer to prevent nvlink from the error message emission.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349540 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoGenerate objc intrinsics instead of runtime calls as the ARC optimizer now works...
Pete Cooper [Tue, 18 Dec 2018 20:33:00 +0000 (20:33 +0000)]
Generate objc intrinsics instead of runtime calls as the ARC optimizer now works only on intrinsics

Differential Revision: https://reviews.llvm.org/D55802

Reviewers: rjmccall

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349535 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[OPENMP][NVPTX]Added extra sync point to the inter-warp copy function.
Alexey Bataev [Tue, 18 Dec 2018 19:20:15 +0000 (19:20 +0000)]
[OPENMP][NVPTX]Added extra sync point to the inter-warp copy function.

The parallel reduction operation requires an extra synchronization point
in the inter-warp copy function to avoid divergence.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349525 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Driver][PS4] Do not implicitly link against asan or ubsan if -nostdlib or -nodefault...
Pierre Gousseau [Tue, 18 Dec 2018 17:03:35 +0000 (17:03 +0000)]
[Driver][PS4] Do not implicitly link against asan or ubsan if -nostdlib or -nodefaultlibs on PS4.

NFC for targets other than PS4.

Respect -nostdlib and -nodefaultlibs when enabling asan or ubsan.

Differential Revision: https://reviews.llvm.org/D55712

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349508 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[NFC] Fix usage of Builder.insert(new Bitcast...)in CodeGenFunction
Erich Keane [Tue, 18 Dec 2018 16:22:21 +0000 (16:22 +0000)]
[NFC] Fix usage of Builder.insert(new Bitcast...)in CodeGenFunction

This is exactly a "CreateBitCast", so refactor this to get rid of a
'new'.

Note that this slightly changes the test, as the Builder is now
seemingly smart enough to fold one of the bitcasts into the annotation
call.

Change-Id: I1733fb1fdf91f5c9d88651067130b9a4e7b5ab67

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349506 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoPortable Python script across Python version
Serge Guelton [Tue, 18 Dec 2018 16:07:37 +0000 (16:07 +0000)]
Portable Python script across Python version

Make scripts more future-proof by importing most __future__ stuff.

Differential Revision: https://reviews.llvm.org/D55208

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349504 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoPortable Python script across Python version
Serge Guelton [Tue, 18 Dec 2018 16:07:06 +0000 (16:07 +0000)]
Portable Python script across Python version

commands.getoutput has been move to subprocess module in Python3

Differential Revision: https://reviews.llvm.org/D55205

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349503 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoPortable Python script across Python version
Serge Guelton [Tue, 18 Dec 2018 16:04:21 +0000 (16:04 +0000)]
Portable Python script across Python version

In Python3, dict.items, dict.keys, dict.values, zip, map and filter no longer return lists, they create generator instead.

The portability patch consists in forcing an extra `list` call if the result is actually used as a list.
`map` are replaced by list comprehension and `filter` by filtered list comprehension.

Differential Revision: https://reviews.llvm.org/D55197

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349501 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoEmit -Wformat properly for bit-field promotions.
Aaron Ballman [Tue, 18 Dec 2018 15:54:38 +0000 (15:54 +0000)]
Emit -Wformat properly for bit-field promotions.

Only explicitly look through integer and floating-point promotion where the result type is actually a promotion, which is not always the case for bit-fields in C.

Patch by Bevin Hansson.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349497 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[AST] Unify the code paths of traversing lambda expressions.
Haojian Wu [Tue, 18 Dec 2018 15:29:12 +0000 (15:29 +0000)]
[AST] Unify the code paths of traversing lambda expressions.

Summary:
This supposes to be a non-functional change. We have two code paths when
traversing lambda expressions:

1) traverse the function proto typeloc when parameters and return type
are explicit;
2) otherwise fallback to traverse parameter decls and return type loc
individually;

This patch unifies the code path to always traverse parameters and
return type, rather than relying on traversing the full type-loc.

Reviewers: ilya-biryukov

Subscribers: arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D55820

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349494 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[PowerPC] Make no-PIC default to match GCC - CLANG
Stefan Pintilie [Tue, 18 Dec 2018 15:08:03 +0000 (15:08 +0000)]
[PowerPC] Make no-PIC default to match GCC - CLANG

Make -fno-PIC default on PowerPC for Little Endian Linux.

Differential Revision: https://reviews.llvm.org/D53384

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349489 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoPortable Python script across Python version
Serge Guelton [Tue, 18 Dec 2018 08:38:50 +0000 (08:38 +0000)]
Portable Python script across Python version

In Python2, division between integer yields an integer, while it yields a float in Python3.
Use a combination of from __future__ import division and // operator to get a portable behavior.

Differential Revision: https://reviews.llvm.org/D55204

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349455 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoPortable Python script across Python version
Serge Guelton [Tue, 18 Dec 2018 08:36:33 +0000 (08:36 +0000)]
Portable Python script across Python version

Using from __future__ import print_function it is possible to have a compatible behavior of `print(...)` across Python version.

Differential Revision: https://reviews.llvm.org/D55213

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349454 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[unittests] Remove superfluous semicolon, fixing warnings with GCC. NFC.
Martin Storsjo [Tue, 18 Dec 2018 08:36:16 +0000 (08:36 +0000)]
[unittests] Remove superfluous semicolon, fixing warnings with GCC. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349453 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Driver] Automatically enable -munwind-tables if -fseh-exceptions is enabled
Martin Storsjo [Tue, 18 Dec 2018 08:36:10 +0000 (08:36 +0000)]
[Driver] Automatically enable -munwind-tables if -fseh-exceptions is enabled

For targets where SEH exceptions are used by default (on MinGW,
only x86_64 so far), -munwind-tables are added automatically. If
-fseh-exeptions is enabled on a target where SEH exeptions are
availble but not enabled by default yet (aarch64), we need to
pass -munwind-tables if -fseh-exceptions was specified.

Differential Revision: https://reviews.llvm.org/D55749

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349452 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoPortable Python script across Python version
Serge Guelton [Tue, 18 Dec 2018 08:25:25 +0000 (08:25 +0000)]
Portable Python script across Python version

ConfigParser module has been renamed as configparser in Python3

Differential Revision: https://reviews.llvm.org/D55200

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349449 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoPortable Python script across Python version
Serge Guelton [Tue, 18 Dec 2018 08:24:06 +0000 (08:24 +0000)]
Portable Python script across Python version

Replace `xrange(...)` by either `range(...)` or `list(range(...))` depending on the context.

Differential Revision: https://reviews.llvm.org/D55193

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349448 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoPortable Python script across Python version
Serge Guelton [Tue, 18 Dec 2018 08:22:47 +0000 (08:22 +0000)]
Portable Python script across Python version

dict no longer have the `has_key` method in Python3. Instead, one can
use the `in` keyword which already works in Python2.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349447 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[ExprConstant] Handle compound assignment when LHS has integral type and RHS has...
Tan S. B [Tue, 18 Dec 2018 07:38:06 +0000 (07:38 +0000)]
[ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type

Fixes PR39858

Differential Revision: https://reviews.llvm.org/D55413

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349444 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoAutomatic variable initialization
JF Bastien [Tue, 18 Dec 2018 05:12:21 +0000 (05:12 +0000)]
Automatic variable initialization

Summary:
Add an option to initialize automatic variables with either a pattern or with
zeroes. The default is still that automatic variables are uninitialized. Also
add attributes to request uninitialized on a per-variable basis, mainly to disable
initialization of large stack arrays when deemed too expensive.

This isn't meant to change the semantics of C and C++. Rather, it's meant to be
a last-resort when programmers inadvertently have some undefined behavior in
their code. This patch aims to make undefined behavior hurt less, which
security-minded people will be very happy about. Notably, this means that
there's no inadvertent information leak when:

  - The compiler re-uses stack slots, and a value is used uninitialized.
  - The compiler re-uses a register, and a value is used uninitialized.
  - Stack structs / arrays / unions with padding are copied.

This patch only addresses stack and register information leaks. There's many
more infoleaks that we could address, and much more undefined behavior that
could be tamed. Let's keep this patch focused, and I'm happy to address related
issues elsewhere.

To keep the patch simple, only some `undef` is removed for now, see
`replaceUndef`. The padding-related infoleaks are therefore not all gone yet.
This will be addressed in a follow-up, mainly because addressing padding-related
leaks should be a stand-alone option which is implied by variable
initialization.

There are three options when it comes to automatic variable initialization:

  0. Uninitialized

    This is C and C++'s default. It's not changing. Depending on code
    generation, a programmer who runs into undefined behavior by using an
    uninialized automatic variable may observe any previous value (including
    program secrets), or any value which the compiler saw fit to materialize on
    the stack or in a register (this could be to synthesize an immediate, to
    refer to code or data locations, to generate cookies, etc).

  1. Pattern initialization

    This is the recommended initialization approach. Pattern initialization's
    goal is to initialize automatic variables with values which will likely
    transform logic bugs into crashes down the line, are easily recognizable in
    a crash dump, without being values which programmers can rely on for useful
    program semantics. At the same time, pattern initialization tries to
    generate code which will optimize well. You'll find the following details in
    `patternFor`:

    - Integers are initialized with repeated 0xAA bytes (infinite scream).
    - Vectors of integers are also initialized with infinite scream.
    - Pointers are initialized with infinite scream on 64-bit platforms because
      it's an unmappable pointer value on architectures I'm aware of. Pointers
      are initialize to 0x000000AA (small scream) on 32-bit platforms because
      32-bit platforms don't consistently offer unmappable pages. When they do
      it's usually the zero page. As people try this out, I expect that we'll
      want to allow different platforms to customize this, let's do so later.
    - Vectors of pointers are initialized the same way pointers are.
    - Floating point values and vectors are initialized with a negative quiet
      NaN with repeated 0xFF payload (e.g. 0xffffffff and 0xffffffffffffffff).
      NaNs are nice (here, anways) because they propagate on arithmetic, making
      it more likely that entire computations become NaN when a single
      uninitialized value sneaks in.
    - Arrays are initialized to their homogeneous elements' initialization
      value, repeated. Stack-based Variable-Length Arrays (VLAs) are
      runtime-initialized to the allocated size (no effort is made for negative
      size, but zero-sized VLAs are untouched even if technically undefined).
    - Structs are initialized to their heterogeneous element's initialization
      values. Zero-size structs are initialized as 0xAA since they're allocated
      a single byte.
    - Unions are initialized using the initialization for the largest member of
      the union.

    Expect the values used for pattern initialization to change over time, as we
    refine heuristics (both for performance and security). The goal is truly to
    avoid injecting semantics into undefined behavior, and we should be
    comfortable changing these values when there's a worthwhile point in doing
    so.

    Why so much infinite scream? Repeated byte patterns tend to be easy to
    synthesize on most architectures, and otherwise memset is usually very
    efficient. For values which aren't entirely repeated byte patterns, LLVM
    will often generate code which does memset + a few stores.

  2. Zero initialization

    Zero initialize all values. This has the unfortunate side-effect of
    providing semantics to otherwise undefined behavior, programs therefore
    might start to rely on this behavior, and that's sad. However, some
    programmers believe that pattern initialization is too expensive for them,
    and data might show that they're right. The only way to make these
    programmers wrong is to offer zero-initialization as an option, figure out
    where they are right, and optimize the compiler into submission. Until the
    compiler provides acceptable performance for all security-minded code, zero
    initialization is a useful (if blunt) tool.

I've been asked for a fourth initialization option: user-provided byte value.
This might be useful, and can easily be added later.

Why is an out-of band initialization mecanism desired? We could instead use
-Wuninitialized! Indeed we could, but then we're forcing the programmer to
provide semantics for something which doesn't actually have any (it's
uninitialized!). It's then unclear whether `int derp = 0;` lends meaning to `0`,
or whether it's just there to shut that warning up. It's also way easier to use
a compiler flag than it is to manually and intelligently initialize all values
in a program.

Why not just rely on static analysis? Because it cannot reason about all dynamic
code paths effectively, and it has false positives. It's a great tool, could get
even better, but it's simply incapable of catching all uses of uninitialized
values.

Why not just rely on memory sanitizer? Because it's not universally available,
has a 3x performance cost, and shouldn't be deployed in production. Again, it's
a great tool, it'll find the dynamic uses of uninitialized variables that your
test coverage hits, but it won't find the ones that you encounter in production.

What's the performance like? Not too bad! Previous publications [0] have cited
2.7 to 4.5% averages. We've commmitted a few patches over the last few months to
address specific regressions, both in code size and performance. In all cases,
the optimizations are generally useful, but variable initialization benefits
from them a lot more than regular code does. We've got a handful of other
optimizations in mind, but the code is in good enough shape and has found enough
latent issues that it's a good time to get the change reviewed, checked in, and
have others kick the tires. We'll continue reducing overheads as we try this out
on diverse codebases.

Is it a good idea? Security-minded folks think so, and apparently so does the
Microsoft Visual Studio team [1] who say "Between 2017 and mid 2018, this
feature would have killed 49 MSRC cases that involved uninitialized struct data
leaking across a trust boundary. It would have also mitigated a number of bugs
involving uninitialized struct data being used directly.". They seem to use pure
zero initialization, and claim to have taken the overheads down to within noise.
Don't just trust Microsoft though, here's another relevant person asking for
this [2]. It's been proposed for GCC [3] and LLVM [4] before.

What are the caveats? A few!

  - Variables declared in unreachable code, and used later, aren't initialized.
    This goto, Duff's device, other objectionable uses of switch. This should
    instead be a hard-error in any serious codebase.
  - Volatile stack variables are still weird. That's pre-existing, it's really
    the language's fault and this patch keeps it weird. We should deprecate
    volatile [5].
  - As noted above, padding isn't fully handled yet.

I don't think these caveats make the patch untenable because they can be
addressed separately.

Should this be on by default? Maybe, in some circumstances. It's a conversation
we can have when we've tried it out sufficiently, and we're confident that we've
eliminated enough of the overheads that most codebases would want to opt-in.
Let's keep our precious undefined behavior until that point in time.

How do I use it:

  1. On the command-line:

    -ftrivial-auto-var-init=uninitialized (the default)
    -ftrivial-auto-var-init=pattern
    -ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang

  2. Using an attribute:

    int dont_initialize_me __attribute((uninitialized));

  [0]: https://users.elis.ugent.be/~jsartor/researchDocs/OOPSLA2011Zero-submit.pdf
  [1]: https://twitter.com/JosephBialek/status/1062774315098112001
  [2]: https://outflux.net/slides/2018/lss/danger.pdf
  [3]: https://gcc.gnu.org/ml/gcc-patches/2014-06/msg00615.html
  [4]: https://github.com/AndroidHardeningArchive/platform_external_clang/commit/776a0955ef6686d23a82d2e6a3cbd4a6a882c31c
  [5]: http://wg21.link/p1152

I've also posted an RFC to cfe-dev: http://lists.llvm.org/pipermail/cfe-dev/2018-November/060172.html

<rdar://problem/39131435>

Reviewers: pcc, kcc, rsmith

Subscribers: JDevlieghere, jkorous, dexonsmith, cfe-commits

Differential Revision: https://reviews.llvm.org/D54604

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349442 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoFix ms-layout_version declspec test and add missing new test
Reid Kleckner [Mon, 17 Dec 2018 23:16:43 +0000 (23:16 +0000)]
Fix ms-layout_version declspec test and add missing new test

Now that MSVC compatibility versions are stored as a four digit number
(1912) instead of a two digit number (19), we need to adjust how we
handle this attribute.

Also add a new test that was intended to be part of r349414.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349415 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoUpdate Microsoft name mangling scheme for exception specifiers in the type system
Reid Kleckner [Mon, 17 Dec 2018 23:10:43 +0000 (23:10 +0000)]
Update Microsoft name mangling scheme for exception specifiers in the type system

Summary:
The msvc exception specifier for noexcept function types has changed
from the prior default of "Z" to "_E" if the function cannot throw when
compiling with /std:C++17.

Patch by Zachary Henkel!

Reviewers: zturner, rnk

Reviewed By: rnk

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D55685

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349414 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] MoveChecker: Squash the bit field because it causes a GCC warning.
Artem Dergachev [Mon, 17 Dec 2018 21:07:38 +0000 (21:07 +0000)]
[analyzer] MoveChecker: Squash the bit field because it causes a GCC warning.

The warning seems spurious (GCC bug 51242), but the bit field is
simply not worth the hassle.

rdar://problem/41349073

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349394 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoMake test/Driver/darwin-sdk-version.c pass on hosts < macOS10.14
Alex Lorenz [Mon, 17 Dec 2018 21:01:04 +0000 (21:01 +0000)]
Make test/Driver/darwin-sdk-version.c pass on hosts < macOS10.14

The test test/Driver/darwin-sdk-version.c from r349380 checks if the macOS
deployment target can be correctly inferred from the SDK version. When the
SDK version is > host version, the driver will pick the host version, so
the old test failed on macOS < 10.14. This commit makes this test more
resilient by using an older SDK version.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349393 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoFix build after r349380
Alex Lorenz [Mon, 17 Dec 2018 20:25:41 +0000 (20:25 +0000)]
Fix build after r349380

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349388 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[NFC] Test commit: tweak whitespace in comment
Tan S. B [Mon, 17 Dec 2018 19:53:22 +0000 (19:53 +0000)]
[NFC] Test commit: tweak whitespace in comment

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349384 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[darwin][arm64] use the "cyclone" CPU for Darwin even when `-arch`
Alex Lorenz [Mon, 17 Dec 2018 19:30:46 +0000 (19:30 +0000)]
[darwin][arm64] use the "cyclone" CPU for Darwin even when `-arch`
is not specified

The -target option allows the user to specify the build target using LLVM
triple. The triple includes the arch, and so the -arch option is redundant.
This should work just as well without the -arch. However, the driver has a bug
in which it doesn't target the "Cyclone" CPU for darwin if -target is used
without -arch. This commit fixes this issue.

rdar://46743182

Differential Revision: https://reviews.llvm.org/D55731

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349382 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Driver] Don't override '-march' when using '-arch x86_64h'
Francis Visoiu Mistrih [Mon, 17 Dec 2018 19:29:27 +0000 (19:29 +0000)]
[Driver] Don't override '-march' when using '-arch x86_64h'

On Darwin, using '-arch x86_64h' would always override the option passed
through '-march'.

This patch allows users to use '-march' with x86_64h, while keeping the
default to 'core-avx2'

Differential Revision: https://reviews.llvm.org/D55775

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349381 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[darwin] parse the SDK settings from SDKSettings.json if it exists and
Alex Lorenz [Mon, 17 Dec 2018 19:19:15 +0000 (19:19 +0000)]
[darwin] parse the SDK settings from SDKSettings.json if it exists and
pass in the -target-sdk-version to the compiler and backend

This commit adds support for reading the SDKSettings.json file in the Darwin
driver. This file is used by the driver to determine the SDK's version, and it
uses that information to pass it down to the compiler using the new
-target-sdk-version= option. This option is then used to set the appropriate
SDK Version module metadata introduced in r349119.

Note: I had to adjust the two ast tests as the SDKROOT environment variable
on macOS caused SDK version to be picked up for the compilation of source file
but not the AST.

rdar://45774000

Differential Revision: https://reviews.llvm.org/D55673

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349380 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[CodeComplete] Fix test failure on different host and target configs
Ilya Biryukov [Mon, 17 Dec 2018 16:37:52 +0000 (16:37 +0000)]
[CodeComplete] Fix test failure on different host and target configs

This should fix PR40033.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349362 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoBuild ASTImporterTest.cpp with /bigobj on MSVC builds to keep llvm-clang-x86_64-expen...
Simon Pilgrim [Mon, 17 Dec 2018 15:14:08 +0000 (15:14 +0000)]
Build ASTImporterTest.cpp with /bigobj on MSVC builds to keep llvm-clang-x86_64-expensive-checks-win buildbot happy

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349357 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[ASTImporter] Add importer specific lookup
Gabor Marton [Mon, 17 Dec 2018 13:53:12 +0000 (13:53 +0000)]
[ASTImporter] Add importer specific lookup

Summary:
There are certain cases when normal C/C++ lookup (localUncachedLookup)
does not find AST nodes. E.g.:

Example 1:

  template <class T>
  struct X {
    friend void foo(); // this is never found in the DC of the TU.
  };

Example 2:

  // The fwd decl to Foo is not found in the lookupPtr of the DC of the
  // translation unit decl.
  struct A { struct Foo *p; };

In these cases we create a new node instead of returning with the old one.
To fix it we create a new lookup table which holds every node and we are
not interested in any C++ specific visibility considerations.
Simply, we must know if there is an existing Decl in a given DC.

Reviewers: a_sidorin, a.sidorin

Subscribers: mgorny, rnkovacs, dkrupp, Szelethus, cfe-commits

Differential Revision: https://reviews.llvm.org/D53708

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349351 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[ASTImporter] Fix redecl chain of classes and class templates
Gabor Marton [Mon, 17 Dec 2018 12:42:12 +0000 (12:42 +0000)]
[ASTImporter] Fix redecl chain of classes and class templates

Summary:
The crux of the issue that is being fixed is that lookup could not find
previous decls of a friend class. The solution involves making the
friend declarations visible in their decl context (i.e. adding them to
the lookup table).
Also, we simplify `VisitRecordDecl` greatly.

This fix involves two other repairs (without these the unittests fail):
(1) We could not handle the addition of injected class types properly
when a redecl chain was involved, now this is fixed.
(2) DeclContext::removeDecl failed if the lookup table in Vector form
did not contain the to be removed element. This caused troubles in
ASTImporter::ImportDeclContext. This is also fixed.

Reviewers: a_sidorin, balazske, a.sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, cfe-commits

Differential Revision: https://reviews.llvm.org/D53655

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349349 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoRevert rC349281 '[analyzer][MallocChecker][NFC] Document and reorganize some functions'
Kristof Umann [Mon, 17 Dec 2018 12:25:48 +0000 (12:25 +0000)]
Revert rC349281 '[analyzer][MallocChecker][NFC] Document and reorganize some functions'

Accidentally commited earlier with the same commit title, but really it
should've been
"Revert rC349283 '[analyzer][MallocChecker] Improve warning messages on double-delete errors'"

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349344 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoFix "enumeral mismatch in conditional expression" gcc7 warning. NFCI.
Simon Pilgrim [Mon, 17 Dec 2018 12:25:42 +0000 (12:25 +0000)]
Fix "enumeral mismatch in conditional expression" gcc7 warning. NFCI.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349343 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoFix "enumeral mismatch in conditional expression" gcc7 warnings. NFCI.
Simon Pilgrim [Mon, 17 Dec 2018 12:17:37 +0000 (12:17 +0000)]
Fix "enumeral mismatch in conditional expression" gcc7 warnings. NFCI.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349342 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoRevert rC349281 '[analyzer][MallocChecker][NFC] Document and reorganize some functions'
Kristof Umann [Mon, 17 Dec 2018 12:07:57 +0000 (12:07 +0000)]
Revert rC349281 '[analyzer][MallocChecker][NFC] Document and reorganize some functions'

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349340 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoReverting bitfield size to attempt to fix a windows buildbot
Kristof Umann [Mon, 17 Dec 2018 10:31:35 +0000 (10:31 +0000)]
Reverting bitfield size to attempt to fix a windows buildbot

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349336 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Docs] Expand -fstack-protector and -fstack-protector-all
Carey Williams [Mon, 17 Dec 2018 10:11:35 +0000 (10:11 +0000)]
[Docs] Expand -fstack-protector and -fstack-protector-all

Improve the description of these command line options
by providing specific heuristic information, as outlined
for the ssp function attribute(s) in LLVM's documentation.

Also rewords -fstack-protector-all for affinity.

Differential Revision: https://reviews.llvm.org/D55428

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349335 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] MoveChecker: Enable by default as cplusplus.Move.
Artem Dergachev [Mon, 17 Dec 2018 06:30:39 +0000 (06:30 +0000)]
[analyzer] MoveChecker: Enable by default as cplusplus.Move.

This checker warns you when you re-use an object after moving it.

Mostly developed by Peter Szecsi!

Differential Revision: https://reviews.llvm.org/D38675

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349328 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] MoveChecker: Add an option to suppress warnings on locals.
Artem Dergachev [Mon, 17 Dec 2018 06:19:32 +0000 (06:19 +0000)]
[analyzer] MoveChecker: Add an option to suppress warnings on locals.

Re-using a moved-from local variable is most likely a bug because there's
rarely a good motivation for not introducing a separate variable instead.
We plan to keep emitting such warnings by default.

Introduce a flag that allows disabling warnings on local variables that are
not of a known move-unsafe type. If it doesn't work out as we expected,
we'll just flip the flag.

We still warn on move-unsafe objects and unsafe operations on known move-safe
objects.

Differential Revision: https://reviews.llvm.org/D55730

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349327 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoSpeculatively re-apply "[analyzer] MoveChecker: Add checks for dereferencing..."
Artem Dergachev [Mon, 17 Dec 2018 05:25:23 +0000 (05:25 +0000)]
Speculatively re-apply "[analyzer] MoveChecker: Add checks for dereferencing..."

This re-applies commit r349226 that was reverted in r349233 due to failures
on clang-x64-windows-msvc.

Specify enum type as unsigned for use in bit field. Otherwise overflows
may cause UB.

Differential Revision: https://reviews.llvm.org/D55388

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349326 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] Fix some expressions staying live too long. Add a debug checker.
Artem Dergachev [Sun, 16 Dec 2018 23:44:06 +0000 (23:44 +0000)]
[analyzer] Fix some expressions staying live too long. Add a debug checker.

StaticAnalyzer uses the CFG-based RelaxedLiveVariables analysis in order to,
in particular, figure out values of which expressions are still needed.
When the expression becomes "dead", it is garbage-collected during
the dead binding scan.

Expressions that constitute branches/bodies of control flow statements,
eg. `E1' in `if (C1) E1;' but not `E2' in `if (C2) { E2; }', were kept alive
for too long. This caused false positives in MoveChecker because it relies
on cleaning up loop-local variables when they go out of scope, but some of those
live-for-too-long expressions were keeping a reference to those variables.

Fix liveness analysis to correctly mark these expressions as dead.

Add a debug checker, debug.DumpLiveStmts, in order to test expressions liveness.

Differential Revision: https://reviews.llvm.org/D55566

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349320 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoThread safety analysis: Avoid intermediate copies [NFC]
Aaron Puchert [Sun, 16 Dec 2018 16:19:11 +0000 (16:19 +0000)]
Thread safety analysis: Avoid intermediate copies [NFC]

The main reason is to reduce the number of constructor arguments though,
especially since many of them had the same type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349308 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoThread safety analysis: Allow scoped releasing of capabilities
Aaron Puchert [Sun, 16 Dec 2018 14:15:30 +0000 (14:15 +0000)]
Thread safety analysis: Allow scoped releasing of capabilities

Summary:
The pattern is problematic with C++ exceptions, and not as widespread as
scoped locks, but it's still used by some, for example Chromium.

We are a bit stricter here at join points, patterns that are allowed for
scoped locks aren't allowed here. That could still be changed in the
future, but I'd argue we should only relax this if people ask for it.

Fixes PR36162.

Reviewers: aaron.ballman, delesley, pwnall

Reviewed By: delesley, pwnall

Subscribers: pwnall, cfe-commits

Differential Revision: https://reviews.llvm.org/D52578

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349300 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer][MallocChecker] Improve warning messages on double-delete errors
Kristof Umann [Sat, 15 Dec 2018 18:41:37 +0000 (18:41 +0000)]
[analyzer][MallocChecker] Improve warning messages on double-delete errors

Differential Revision: https://reviews.llvm.org/D54834

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349283 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer][MallocChecker][NFC] Document and reorganize some functions
Kristof Umann [Sat, 15 Dec 2018 18:34:00 +0000 (18:34 +0000)]
[analyzer][MallocChecker][NFC] Document and reorganize some functions

This patch merely reorganizes some things, and features no functional change.

In detail:

* Provided documentation, or moved existing documentation in more obvious
places.
* Added dividers. (the //===----------===// thing).
* Moved getAllocationFamily, printAllocDeallocName, printExpectedAllocName and
printExpectedDeallocName in the global namespace on top of the file where
AllocationFamily is declared, as they are very strongly related.
* Moved isReleased and MallocUpdateRefState near RefState's definition for the
same reason.
* Realloc modeling was very poor in terms of variable and structure naming, as
well as documentation, so I renamed some of them and added much needed docs.
* Moved function IdentifierInfos to a separate struct, and moved isMemFunction,
isCMemFunction adn isStandardNewDelete inside it. This makes the patch affect
quite a lot of lines, should I extract it to a separate one?
* Moved MallocBugVisitor out of MallocChecker.
* Preferred switches to long else-if branches in some places.
* Neatly organized some RUN: lines.

Differential Revision: https://reviews.llvm.org/D54823

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349281 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer][NFC] Merge ClangCheckerRegistry to CheckerRegistry
Kristof Umann [Sat, 15 Dec 2018 18:11:49 +0000 (18:11 +0000)]
[analyzer][NFC] Merge ClangCheckerRegistry to CheckerRegistry

Now that CheckerRegistry lies in Frontend, we can finally eliminate
ClangCheckerRegistry. Fortunately, this also provides us with a
DiagnosticsEngine, so I went ahead and removed some parameters from it's
methods.

Differential Revision: https://reviews.llvm.org/D54437

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349280 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoLink examples/clang-interpreter against clangSerialization
Kristof Umann [Sat, 15 Dec 2018 18:03:15 +0000 (18:03 +0000)]
Link examples/clang-interpreter against clangSerialization

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349279 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoFix a compilation error in examples/
Kristof Umann [Sat, 15 Dec 2018 17:12:38 +0000 (17:12 +0000)]
Fix a compilation error in examples/

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349278 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer][NFC] Move CheckerRegistry from the Core directory to Frontend
Kristof Umann [Sat, 15 Dec 2018 16:23:51 +0000 (16:23 +0000)]
[analyzer][NFC] Move CheckerRegistry from the Core directory to Frontend

ClangCheckerRegistry is a very non-obvious, poorly documented, weird concept.
It derives from CheckerRegistry, and is placed in lib/StaticAnalyzer/Frontend,
whereas it's base is located in lib/StaticAnalyzer/Core. It was, from what I can
imagine, used to circumvent the problem that the registry functions of the
checkers are located in the clangStaticAnalyzerCheckers library, but that
library depends on clangStaticAnalyzerCore. However, clangStaticAnalyzerFrontend
depends on both of those libraries.

One can make the observation however, that CheckerRegistry has no place in Core,
it isn't used there at all! The only place where it is used is Frontend, which
is where it ultimately belongs.

This move implies that since
include/clang/StaticAnalyzer/Checkers/ClangCheckers.h only contained a single function:

class CheckerRegistry;

void registerBuiltinCheckers(CheckerRegistry &registry);

it had to re purposed, as CheckerRegistry is no longer available to
clangStaticAnalyzerCheckers. It was renamed to BuiltinCheckerRegistration.h,
which actually describes it a lot better -- it does not contain the registration
functions for checkers, but only those generated by the tblgen files.

Differential Revision: https://reviews.llvm.org/D54436

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349275 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] Prefer returns values to out-params in CheckerRegistry.cpp
Kristof Umann [Sat, 15 Dec 2018 15:44:05 +0000 (15:44 +0000)]
[analyzer] Prefer returns values to out-params in CheckerRegistry.cpp

Renaming collectCheckers to getEnabledCheckers
Changing the functionality to acquire all enabled checkers, rather then collect
checkers for a specific CheckerOptInfo (for example, collecting all checkers for
{ "core", true }, which meant enabling all checkers from the core package, which
was an unnecessary complication).
Removing CheckerOptInfo, instead of storing whether the option was claimed via a
field, we handle errors immediately, as getEnabledCheckers can now access a
DiagnosticsEngine. Realize that the remaining information it stored is directly
accessible through AnalyzerOptions.CheckerControlList.
Fix a test with -analyzer-disable-checker -verify accidentally left in.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349274 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] Assume that we always have a SubEngine available
Gabor Horvath [Sat, 15 Dec 2018 13:20:33 +0000 (13:20 +0000)]
[analyzer] Assume that we always have a SubEngine available

The removed codepath was dead.

Differential Revision: https://reviews.llvm.org/D55697

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349266 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[libclang] Add dependency on clangSerialization to unbreak -DBUILD_SHARED_LIBS=1...
Fangrui Song [Sat, 15 Dec 2018 08:54:06 +0000 (08:54 +0000)]
[libclang] Add dependency on clangSerialization to unbreak -DBUILD_SHARED_LIBS=1 build after rC349237

Frontend headers have undefined reference on the symbol `clang::PCHContainerOperations::PCHContainerOperations()` through some shared_ptr usage. Any dependents will get the undefined reference which can only be resolved by explicit dependency on clangSerialization (due to -z defs).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349259 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[MinGW] Produce a vtable and RTTI for dllexported classes without a key function
Martin Storsjo [Sat, 15 Dec 2018 08:08:11 +0000 (08:08 +0000)]
[MinGW] Produce a vtable and RTTI for dllexported classes without a key function

This matches what GCC does in these situations.

This fixes compiling Qt in debug mode. In release mode, references to
the vtable of this particular class ends up optimized away, but in debug
mode, the compiler creates references to the vtable, which is expected
to be dllexported from a different DLL. Make sure the dllexported
version actually ends up emitted.

Differential Revision: https://reviews.llvm.org/D55698

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349256 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoFix includes and dependencies for libclang
Richard Trieu [Sat, 15 Dec 2018 04:25:19 +0000 (04:25 +0000)]
Fix includes and dependencies for libclang

Remove unneeded includes
Add needed include
Remove dependency on Serialization

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349237 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoRevert "[analyzer] MoveChecker: Add checks for dereferencing a smart pointer..."
Artem Dergachev [Sat, 15 Dec 2018 02:55:55 +0000 (02:55 +0000)]
Revert "[analyzer] MoveChecker: Add checks for dereferencing a smart pointer..."

This reverts commit r349226.

Fails on an MSVC buildbot.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349233 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoMove static analyzer core diagnostics to common.
Richard Trieu [Sat, 15 Dec 2018 02:30:16 +0000 (02:30 +0000)]
Move static analyzer core diagnostics to common.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349230 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] Fix unknown block calls to have zero parameters.
Artem Dergachev [Sat, 15 Dec 2018 02:13:26 +0000 (02:13 +0000)]
[analyzer] Fix unknown block calls to have zero parameters.

Right now they report to have one parameter with null decl,
because initializing an ArrayRef of pointers with a nullptr
yields an ArrayRef to an array of one null pointer.

Fixes a crash in the OSObject section of RetainCountChecker.

Differential Revision: https://reviews.llvm.org/D55671

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349229 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] ObjCDealloc: Fix a crash when a class attempts to deallocate a class.
Artem Dergachev [Sat, 15 Dec 2018 02:09:02 +0000 (02:09 +0000)]
[analyzer] ObjCDealloc: Fix a crash when a class attempts to deallocate a class.

The checker wasn't prepared to see the dealloc message sent to the class itself
rather than to an instance, as if it was +dealloc.

Additionally, it wasn't prepared for pure-unknown or undefined self values.
The new guard covers that as well, but it is annoying to test because
both kinds of values shouldn't really appear and we generally want to
get rid of all of them (by modeling unknown values with symbols and
by warning on use of undefined values before they are used).

The CHECK: directive for FileCheck at the end of the test looks useless,
so i removed it.

Differential Revision: https://reviews.llvm.org/D55680

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349228 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] ObjCContainers: Track index values.
Artem Dergachev [Sat, 15 Dec 2018 02:06:13 +0000 (02:06 +0000)]
[analyzer] ObjCContainers: Track index values.

Use trackExpressionValue() (previously known as trackNullOrUndefValue())
to track index value in the report, so that the user knew
what Static Analyzer thinks the index is.

Additionally, implement printState() to help debugging the checker later.

Differential Revision: https://reviews.llvm.org/D55458

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349227 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] MoveChecker: Add checks for dereferencing a smart pointer after move.
Artem Dergachev [Sat, 15 Dec 2018 01:53:38 +0000 (01:53 +0000)]
[analyzer] MoveChecker: Add checks for dereferencing a smart pointer after move.

Calling operator*() or operator->() on a null STL smart pointer is
undefined behavior.

Smart pointers are specified to become null after being moved from.
So we can't warn on arbitrary method calls, but these two operators
definitely make no sense.

The new bug is fatal because it's an immediate UB,
unlike other use-after-move bugs.

The work on a more generic null smart pointer dereference checker
is still pending.

Differential Revision: https://reviews.llvm.org/D55388

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349226 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[analyzer] MoveChecker: NFC: De-duplicate a few checks.
Artem Dergachev [Sat, 15 Dec 2018 01:50:58 +0000 (01:50 +0000)]
[analyzer] MoveChecker: NFC: De-duplicate a few checks.

No functional change intended.

Differential Revision: https://reviews.llvm.org/D55387

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349225 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoMangle calling conventions into function pointer types where GCC does
Reid Kleckner [Fri, 14 Dec 2018 23:42:59 +0000 (23:42 +0000)]
Mangle calling conventions into function pointer types where GCC does

Summary:
GCC 5.1 began mangling these Windows calling conventions into function
types, since they can be used for overloading. They've always been
mangled in the MS ABI, but they are new to the Itanium mangler. Note
that the calling convention doesn't appear as part of the main
declaration, it only appears on function parameter types and other
types.

Fixes PR39860

Reviewers: rjmccall, efriedma

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D55672

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349212 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoAdd AddressSpace mangling to MS mode
Erich Keane [Fri, 14 Dec 2018 23:17:34 +0000 (23:17 +0000)]
Add AddressSpace mangling to MS mode

All of the symbols demangle on llvm-undname and demangler.com. This
address space qualifier is useful for when we want to use opencl C++ in
Windows mode. Additionally, C++ address-space using functions will now
be usable on windows.

Differential Revision: https://reviews.llvm.org/D55715

Change-Id: Ife4506613c3cce778a783456d62117fbf7d83c26

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349209 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoRevert "Add extension to always default-initialize nullptr_t."
Erich Keane [Fri, 14 Dec 2018 22:41:18 +0000 (22:41 +0000)]
Revert "Add extension to always default-initialize nullptr_t."

This reverts commit 46efdf2ccc2a80aefebf8433dbf9c7c959f6e629.

Richard Smith commented just after I submitted this that this is the
wrong solution.  Reverting so that I can fix differently.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349206 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoAdd extension to always default-initialize nullptr_t.
Erich Keane [Fri, 14 Dec 2018 22:22:29 +0000 (22:22 +0000)]
Add extension to always default-initialize nullptr_t.

Core issue 1013 suggests that having an uninitialied std::nullptr_t be
UB is a bit foolish, since there is only a single valid value. This DR
reports that DR616 fixes it, which does so by making lvalue-to-rvalue
conversions from nullptr_t be equal to nullptr.

However, just implementing that results in warnings/etc in many places.
In order to fix all situations where nullptr_t would seem uninitialized,
this patch instead (as an otherwise transparent extension) default
initializes uninitialized VarDecls of nullptr_t.

Differential Revision: https://reviews.llvm.org/D53713

Change-Id: I84d72a9290054fa55341e8cbdac43c8e7f25b885

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349201 91177308-0d34-0410-b5e6-96231b3b80d8

5 years agoUsing llvm::find_if() instead of a range-based for loop; NFC.
Aaron Ballman [Fri, 14 Dec 2018 21:14:44 +0000 (21:14 +0000)]
Using llvm::find_if() instead of a range-based for loop; NFC.

This addresses post-commit review feedback from r349188.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349197 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[Clang] Add __builtin_launder
Eric Fiselier [Fri, 14 Dec 2018 21:11:28 +0000 (21:11 +0000)]
[Clang] Add __builtin_launder

Summary:
This patch adds `__builtin_launder`, which is required to implement `std::launder`. Additionally GCC provides `__builtin_launder`, so thing brings Clang in-line with GCC.

I'm not exactly sure what magic `__builtin_launder` requires, but  based on previous discussions this patch applies a `@llvm.invariant.group.barrier`. As noted in previous discussions, this may not be enough to correctly handle vtables.

Reviewers: rnk, majnemer, rsmith

Reviewed By: rsmith

Subscribers: kristina, Romain-Geissler-1A, erichkeane, amharc, jroelofs, cfe-commits, Prazek

Differential Revision: https://reviews.llvm.org/D40218

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349195 91177308-0d34-0410-b5e6-96231b3b80d8

5 years ago[OPENMP][NVPTX]Improved interwarp copy function.
Alexey Bataev [Fri, 14 Dec 2018 21:00:58 +0000 (21:00 +0000)]
[OPENMP][NVPTX]Improved interwarp copy function.

Inlined runtime with the current implementation of the interwarp copy
function leads to the undefined behavior because of the not quite
correct implementation of the barriers. Start using generic
__kmpc_barier function instead of the custom made barriers.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349192 91177308-0d34-0410-b5e6-96231b3b80d8