Commit Graph

53681 Commits

Author SHA1 Message Date
Nico Weber b215d0731a Let new test from r350340 still pass even after r350451.
llvm-svn: 350453
2019-01-05 01:19:14 +00:00
Nico Weber 9f0c21c1e0 Move -add-plugin validation after -load was executed.
Moves the code added in r350340 around a bit, to hopefully make the existing
plugin tests pass when clang is built with examples enabled.

llvm-svn: 350451
2019-01-05 01:10:20 +00:00
Joel E. Denny bae586fb0a [OpenMP] Refactor const restriction for linear
As discussed in D56113, this patch refactors the implementation of the
const restriction for linear to reuse a function introduced by D56113.
A side effect is that, if a variable has mutable members, this
diagnostic is now skipped, and the diagnostic for the variable not
being an integer or pointer is reported instead.

Reviewed By: ABataev

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

llvm-svn: 350441
2019-01-04 22:12:13 +00:00
Joel E. Denny d2649292ef [OpenMP] Refactor const restriction for reductions
As discussed in D56113, this patch refactors the implementation of the
const restriction for reductions to reuse a function introduced by
D56113.  A side effect is that diagnostics sometimes now say
"variable" instead of "list item" when a list item is a variable.

Reviewed By: ABataev

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

llvm-svn: 350440
2019-01-04 22:11:56 +00:00
Joel E. Denny e6234d1429 [OpenMP] Replace predetermined shared for const variable
The following appears in OpenMP 3.1 sec. 2.9.1.1 as a predetermined
data-sharing attribute:

> Variables with const-qualified type having no mutable member are
> shared.

It does not appear in OpenmP 4.0, 4.5, or 5.0.  This patch removes the
implementation of that attribute when the requested OpenMP version is
greater than 3.1.

One effect of that removal is that `default(none)` affects const
variables without mutable members.

Also, without this patch, if a const variable without mutable members
was explicitly lastprivate or private, it was an error because it was
predetermined shared.  Now, clang instead complains that it's const
without mutable fields, which is a more intelligible diagnostic.  That
should be fine for all of the above versions because they all have
something like the following, which is quoted from OpenMP 5.0
sec. 2.19.3:

> A variable that is privatized must not have a const-qualified type
> unless it is of class type with a mutable member. This restriction does
> not apply to the firstprivate clause.

reduction and linear clauses already have separate checks for const
variables.  Future patches will merge the implementations.

Reviewed By: ABataev

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

llvm-svn: 350439
2019-01-04 22:11:31 +00:00
Peter Collingbourne 87f477b5e4 hwasan: Implement lazy thread initialization for the interceptor ABI.
The problem is similar to D55986 but for threads: a process with the
interceptor hwasan library loaded might have some threads started by
instrumented libraries and some by uninstrumented libraries, and we
need to be able to run instrumented code on the latter.

The solution is to perform per-thread initialization lazily. If a
function needs to access shadow memory or add itself to the per-thread
ring buffer its prologue checks to see whether the value in the
sanitizer TLS slot is null, and if so it calls __hwasan_thread_enter
and reloads from the TLS slot. The runtime does the same thing if it
needs to access this data structure.

This change means that the code generator needs to know whether we
are targeting the interceptor runtime, since we don't want to pay
the cost of lazy initialization when targeting a platform with native
hwasan support. A flag -fsanitize-hwaddress-abi={interceptor,platform}
has been introduced for selecting the runtime ABI to target. The
default ABI is set to interceptor since it's assumed that it will
be more common that users will be compiling application code than
platform code.

Because we can no longer assume that the TLS slot is initialized,
the pthread_create interceptor is no longer necessary, so it has
been removed.

Ideally, lazy initialization should only cost one instruction in the
hot path, but at present the call may cause us to spill arguments
to the stack, which means more instructions in the hot path (or
theoretically in the cold path if the spills are moved with shrink
wrapping). With an appropriately chosen calling convention for
the per-thread initialization function (TODO) the hot path should
always need just one instruction and the cold path should need two
instructions with no spilling required.

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

llvm-svn: 350429
2019-01-04 19:27:04 +00:00
Aaron Enye Shi bea57bb5a4 [HIP][DRIVER][OFFLOAD] Do not unbundle unsupported file types
The offload bundler action should not unbundle the input file types that does not match the action type. This fixes an issue where .so files are unbundled when the action type is object files.

llvm-svn: 350425
2019-01-04 19:05:41 +00:00
Teresa Johnson 6ed7913c98 [ThinLTO] Clang changes to utilize new pass to handle chains of aliases
Summary:
As with NameAnonGlobals, invoke the new CanonicalizeAliases via clang
when using the new PM.

Depends on D54507.

Reviewers: pcc, davidxl

Subscribers: mehdi_amini, inglorion, steven_wu, dexonsmith, cfe-commits

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

llvm-svn: 350424
2019-01-04 19:05:01 +00:00
Erik Pilkington 1e36882b52 [ObjCARC] Add an new attribute, objc_externally_retained
This attribute, called "objc_externally_retained", exposes clang's
notion of pseudo-__strong variables in ARC. Pseudo-strong variables
"borrow" their initializer, meaning that they don't retain/release
it, instead assuming that someone else is keeping their value alive.

If a function is annotated with this attribute, implicitly strong
parameters of that function aren't implicitly retained/released in
the function body, and are implicitly const. This is useful to expose
for performance reasons, most functions don't need the extra safety
of the retain/release, so programmers can opt out as needed.

This attribute can also apply to declarations of local variables,
with similar effect.

Differential revision: https://reviews.llvm.org/D55865

llvm-svn: 350422
2019-01-04 18:33:06 +00:00
Alexey Bataev 8e009036c9 [OPENMP][NVPTX]Use new functions from the runtime library.
Updated codegen to use the new functions from the runtime library.

llvm-svn: 350415
2019-01-04 17:25:09 +00:00
Aaron Ballman 9bdf515c74 Add two new pragmas for controlling software pipelining optimizations.
This patch adds #pragma clang loop pipeline and #pragma clang loop pipeline_initiation_interval for debugging or reducing compile time purposes. It is possible to disable SWP for concrete loops to save compilation time or to find bugs by not doing SWP to certain loops. It is possible to set value of initiation interval to concrete number to save compilation time by not doing extra pipeliner passes or to check created schedule for specific initiation interval.

Patch by Alexey Lapshin.

llvm-svn: 350414
2019-01-04 17:20:00 +00:00
Aaron Ballman fb6deeb984 Refactor the way we handle diagnosing unused expression results.
Rather than sprinkle calls to DiagnoseUnusedExprResult() around in places where we want diagnostics, we now diagnose unused expression statements and full expressions in a more generic way when acting on the final expression statement. This results in more appropriate diagnostics for [[nodiscard]] where we were previously lacking them, such as when the body of a for loop is not a compound statement.

This patch fixes PR39837.

llvm-svn: 350404
2019-01-04 16:58:14 +00:00
Erich Keane 414ff52d09 Prevent unreachable when checking invalid multiversion decls.
CPUSpecifc/CPUDispatch call resolution assumed that all declarations
that would be passed are valid, however this was an invalid assumption.
This patch deals with those situations by making the valid version take
priority.  Note that the checked ordering is arbitrary, since both are
replaced by calls to the resolver later.

Change-Id: I7ff2ec88c55a721d51bc1f39ea1a1fe242b4e45f
llvm-svn: 350398
2019-01-04 15:24:06 +00:00
Anastasia Stulova 4cebc9db04 [Basic] Extend DiagnosticEngine to store and format Qualifiers.
Qualifiers can now be streamed into the DiagnosticEngine using
regular << operator. If Qualifiers are empty 'unqualified' will
be printed in the diagnostic otherwise regular qual syntax is
used.

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

llvm-svn: 350386
2019-01-04 11:50:36 +00:00
Daniel Dunbar a39bab36c6 Adopt SwiftABIInfo for WebAssembly.
Summary:
 - This adopts SwiftABIInfo as the base class for WebAssemblyABIInfo, which is in keeping with what is done for other targets for which Swift is supported.

 - This is a minimal patch to unblock exploration of WASM support for Swift (https://bugs.swift.org/browse/SR-9307)

Reviewers: rjmccall, sunfish

Reviewed By: rjmccall

Subscribers: ahti, dschuff, sbc100, jgravelle-google, aheejin, cfe-commits

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

llvm-svn: 350372
2019-01-03 23:24:50 +00:00
Nico Weber ca27a2b037 Validate -add-plugin arguments.
-plugin already prints an error if the name of an unknown plugin is passed.
-add-plugin used to silently ignore that, now it errors too.

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

llvm-svn: 350340
2019-01-03 18:26:06 +00:00
Arnaud Bienner 57fc9582f9 Make -Wstring-plus-int warns even if when the result is not out of bounds
Summary: Patch by Arnaud Bienner

Reviewers: sylvestre.ledru, thakis, serge-sans-paille

Reviewed By: thakis

Subscribers: arphaman, dyung, anemet, llvm-commits, cfe-commits

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

llvm-svn: 350335
2019-01-03 17:45:28 +00:00
Alexey Bataev a3924b517e [OPENMP][NVPTX]Use __kmpc_barrier_simple_spmd(nullptr, 0) instead of
nvvm_barrier0.

Use runtime functions instead of the direct call to the nvvm intrinsics.
It allows to prevent some dangerous LLVM optimizations, that breaks the
code for the NVPTX target.

llvm-svn: 350328
2019-01-03 16:25:35 +00:00
Aaron Ballman d23e9bc5af Diagnose an unused result from a call through a function pointer whose return type is marked [[nodiscard]].
When a function returns a type and that type was declared [[nodiscard]], we diagnose any unused results from that call as though the function were marked nodiscard. The same behavior should apply to calls through a function pointer.

This addresses PR31526.

llvm-svn: 350317
2019-01-03 14:24:31 +00:00
Philip Pfaffe b39a97c8f6 [NewPM] Port Msan
Summary:
Keeping msan a function pass requires replacing the module level initialization:
That means, don't define a ctor function which calls __msan_init, instead just
declare the init function at the first access, and add that to the global ctors
list.

Changes:
- Pull the actual sanitizer and the wrapper pass apart.
- Add a newpm msan pass. The function pass inserts calls to runtime
  library functions, for which it inserts declarations as necessary.
- Update tests.

Caveats:
- There is one test that I dropped, because it specifically tested the
  definition of the ctor.

Reviewers: chandlerc, fedor.sergeev, leonardchan, vitalybuka

Subscribers: sdardis, nemanjai, javed.absar, hiraditya, kbarton, bollu, atanasyan, jsji

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

llvm-svn: 350305
2019-01-03 13:42:44 +00:00
Patrick Lyster e13b1e3299 [OpenMP] Added support for explicit mapping of classes using 'this' pointer. Differential revision: https://reviews.llvm.org/D55982
llvm-svn: 350252
2019-01-02 19:28:48 +00:00
Pete Cooper de0a8d37a0 Only convert objc messages to alloc to objc_alloc if the receiver is a class.
r348687 converted [Foo alloc] to objc_alloc(Foo).  However the objc runtime method only takes a Class, not an arbitrary pointer.

This makes sure we are messaging a class before we convert these messages.

rdar://problem/46943703

llvm-svn: 350224
2019-01-02 17:25:30 +00:00
Akira Hatanaka c7c7574ea3 [CodeGen] Replace '@' characters in block descriptors' symbol names with
'\1'.

'@' can't be used in block descriptors' symbol names since it is
reserved on ELF platforms as a separator between symbol names and symbol
versions.

See the discussion here: https://reviews.llvm.org/D50783.

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

llvm-svn: 350157
2018-12-29 17:28:30 +00:00
Richard Trieu b3e902f4c3 Add vtable anchor to classes.
llvm-svn: 350143
2018-12-29 02:02:30 +00:00
David Chisnall 386477a541 [objc-gnustep2] Fix a bug in category generation.
We were not emitting a protocol definition while generating the category
method list.  This was fine in most cases, because something else in the
library typically referenced any given protocol, but it caused linker
failures if the category was the only reference to a given protocol.

llvm-svn: 350130
2018-12-28 17:44:54 +00:00
Alexey Bataev db43f0696e [OPENMP]Fix processing of the clauses on target combined directives.
For constants with the predefined data-sharing clauses we may had
troubles with the target combined directives. It may cause compiler
crash in some corner cases.

llvm-svn: 350127
2018-12-28 17:27:32 +00:00
David Chisnall ddd06821c4 [objc-gnustep] Fix a copy-and-paste error.
We were emitting the null class symbol in the wrong section, which meant
that programs that contained no Objective-C classes would fail to link.

llvm-svn: 350092
2018-12-27 14:44:36 +00:00
Reid Kleckner a643e6449b [clang-cl] Treat inputs as C++ with /E, like MSVC
midl invokes the compiler on .idl files with /E. Before this change, we
would treat unrecognized inputs as object files. Now we pre-process to
stdout as expected. I checked that MSVC defines __cplusplus when invoked
this way, so treating the input as C++ seems like the right thing to do.

After this change, I was able to run midl like this with clang-cl:
$ midl -cpp_cmd clang-cl.exe foo.idl

Things worked for the example IDL file in the Microsoft documentation,
but beyond that, I don't know if this will work well.

Fixes PR40140

llvm-svn: 350072
2018-12-26 21:04:08 +00:00
Reid Kleckner 3ab5a9cd1c [MS] Mangle return adjusting thunks with the public access specifier
MSVC does this, so we should too.

Fixes PR40138

llvm-svn: 350071
2018-12-26 20:07:52 +00:00
Reid Kleckner 423b65333d Ignore ConstantExpr in IgnoreParens
Summary:
This moves it up from IgnoreParenImpCasts to IgnoreParens, so that more
helpers ignore it. For most clients, this ensures that these helpers
behave the same with and without C++17 enabled, which is what appears to
introduce these new expression nodes.

Fixes PR39881

Reviewers: void, rsmith

Subscribers: cfe-commits

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

llvm-svn: 350068
2018-12-26 17:44:40 +00:00
George Karpenkov b945db8afc [analyzer] [NFC] Clean up the mess of constructing argument effects in RetainCountChecker
Previously, argument effects were stored in a method variable, which was
effectively global.
The global state was reset at each (hopefully) entrance point to the
summary construction,
and every function could modify it.

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

llvm-svn: 350057
2018-12-24 18:45:18 +00:00
Michal Gorny dae01c352b [Driver] Disable -faddrsig on Gentoo by default
Gentoo supports combining clang toolchain with GNU binutils, and many
users actually do that.  As -faddrsig is not supported by GNU strip,
this results in a lot of warnings.  Disable it by default and let users
enable it explicitly if they want it; with the intent of reevaluating
when the underlying feature becomes standarized.

See also: https://bugs.gentoo.org/667854

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

llvm-svn: 350028
2018-12-23 15:07:26 +00:00
Michal Gorny f241228a02 [Distro] Support detecting Gentoo
Add support for distinguishing plain Gentoo distribution, and a unit
test for it.  This is going to be used to introduce distro-specific
customizations in the driver code; most notably, it is going to be used
to disable -faddrsig.

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

llvm-svn: 350027
2018-12-23 15:07:19 +00:00
Bruno Ricci ddb8f6b83a [AST] Store the arguments of CXXConstructExpr in a trailing array
Store the arguments of CXXConstructExpr in a trailing array. This is very
similar to the CallExpr case in D55771, with the exception that there is
only one derived class (CXXTemporaryObjectExpr) and that we compute the
offset to the trailing array instead of storing it.

This saves one pointer per CXXConstructExpr and CXXTemporaryObjectExpr.

Reviewed By: rjmccall

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

llvm-svn: 350003
2018-12-22 14:39:30 +00:00
Artem Dergachev 02955afbb4 [analyzer] pr38668: Do not attempt to cast loaded integers to floats.
This patch is a different approach to landing the reverted r349701.

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 an integer and load a float, you won't get your integer
represented as a float; instead, you will get garbage.

Admit that we cannot perform the cast and return an unknown value.

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

rdar://problem/45062567

llvm-svn: 349984
2018-12-22 02:06:51 +00:00
Artem Belevich 9953577cb2 [CUDA] Treat extern global variable shadows same as regular extern vars.
This fixes compiler crash when we attempted to compile this code:

extern __device__ int data;
__device__ int data = 1;

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

llvm-svn: 349981
2018-12-22 01:11:09 +00:00
Aaron Ballman d914174d9b Switch from static_cast<> to cast<>, update identifier for coding conventions; NFC.
llvm-svn: 349955
2018-12-21 21:11:36 +00:00
Pete Cooper e5b64ea2b8 Convert some ObjC retain/release msgSends to runtime calls.
It is faster to directly call the ObjC runtime for methods such as retain/release instead of sending a message to those functions.

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

Reviewed By: rjmccall

llvm-svn: 349952
2018-12-21 21:00:32 +00:00
Bruno Ricci d8c17673d7 [Sema][NFC] Fix a Wimplicit-fallthrough warning in CheckSpecializationInstantiationRedecl
All cases are covered so add an llvm_unreachable. NFC.

llvm-svn: 349949
2018-12-21 20:38:06 +00:00
Bruno Ricci 21636ab80c [AST][NFC] Remove stale comment in CXXRecordDecl::is(Virtually)DerivedFrom.
The "this" capture was removed in r291939.

llvm-svn: 349948
2018-12-21 20:23:07 +00:00
Alex Lorenz d92b1ae1d7 Remove stat cache chaining as it's no longer needed after PTH support has been
removed

Stat cache chaining was implemented for a StatListener in the PTH writer so that
it could write out the stat information to PTH. r348266 removed support for PTH,
and it doesn't seem like there are other uses of stat cache chaining. We can
remove the chaining support.

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

llvm-svn: 349942
2018-12-21 19:33:09 +00:00
George Karpenkov 255b05820c Revert "Revert rL349876 from cfe/trunk: [analyzer] Perform escaping in RetainCountChecker on type mismatch even for inlined functions"
This reverts commit b44b33f6e020a2c369da2b0c1d53cd52975f2526.

Revert the revert with the fix.

llvm-svn: 349939
2018-12-21 19:13:40 +00:00
George Karpenkov 79f0340c53 [analyzer] Correct the summary violation diagnostics for the retain count checker
It should be in the past tense.

llvm-svn: 349938
2018-12-21 19:13:28 +00:00
Bruno Ricci c4ba546ab8 [AST][NFC] Fix Wsign-compare warning introduced in CXXOperatorCallExpr
llvm-svn: 349934
2018-12-21 17:54:51 +00:00
Bruno Ricci e5bcf0beb1 [Sema][NFC] Fix Wimplicit-fallthrough warning in getCursorKindForDecl
All cases are covered so add an llvm_unreachable. NFC.

llvm-svn: 349933
2018-12-21 17:52:13 +00:00
Bruno Ricci feb1923c7a [AST][NFC] Pack CXXOperatorCallExpr
Use the space available in the bit-fields of Stmt.
This saves 8 bytes per CXXOperatorCallExpr. NFC.

llvm-svn: 349924
2018-12-21 16:51:57 +00:00
Bruno Ricci c5885cffc5 [AST] Store the callee and argument expressions of CallExpr in a trailing array.
Since CallExpr::setNumArgs has been removed, it is now possible to store the
callee expression and the argument expressions of CallExpr in a trailing array.
This saves one pointer per CallExpr, CXXOperatorCallExpr, CXXMemberCallExpr,
CUDAKernelCallExpr and UserDefinedLiteral.

Given that CallExpr is used as a base of the above classes we cannot use
llvm::TrailingObjects. Instead we store the offset in bytes from the this pointer
to the start of the trailing objects and manually do the casts + arithmetic.

Some notes:

1.) I did not try to fit the number of arguments in the bit-fields of Stmt.
    This leaves some space for future additions and avoid the discussion about
    whether x bits are sufficient to hold the number of arguments.

2.) It would be perfectly possible to recompute the offset to the trailing
    objects before accessing the trailing objects. However the trailing objects
    are frequently accessed and benchmarks show that it is slightly faster to
    just load the offset from the bit-fields. Additionally, because of 1),
    we have plenty of space in the bit-fields of Stmt.

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

Reviewed By: rjmccall

llvm-svn: 349910
2018-12-21 15:20:32 +00:00
Bruno Ricci 4224c8764c [Sema][NFC] Remove some unnecessary calls to getASTContext.
The AST context is already easily available. NFC.

llvm-svn: 349904
2018-12-21 14:35:24 +00:00
Bruno Ricci 5fc4db7579 [AST][NFC] Pass the AST context to one of the ctor of DeclRefExpr.
All of the other constructors already take a reference to the AST context.
This avoids calling Decl::getASTContext in most cases. Additionally move
the definition of the constructor from Expr.h to Expr.cpp since it is calling
DeclRefExpr::computeDependence. NFC.

llvm-svn: 349901
2018-12-21 14:10:18 +00:00
Simon Pilgrim 82fbb66465 Revert rL349876 from cfe/trunk: [analyzer] Perform escaping in RetainCountChecker on type mismatch even for inlined functions
The fix done in D55465 did not previously apply when the function was inlined.

rdar://46889541

Differential Revision: https://reviews.llvm.org/D55976
........
Fixes broken buildbot: http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/14764

llvm-svn: 349894
2018-12-21 10:11:23 +00:00
Akira Hatanaka 71645c2feb [Sema] Produce diagnostics when C++17 aligned allocation/deallocation
functions that are unavailable on Darwin are explicitly called or called
from deleting destructors.

rdar://problem/40736230

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

llvm-svn: 349890
2018-12-21 07:05:36 +00:00
George Karpenkov aecb371a0a [analyzer] Perform escaping in RetainCountChecker on type mismatch even for inlined functions
The fix done in D55465 did not previously apply when the function was inlined.

rdar://46889541

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

llvm-svn: 349876
2018-12-21 02:16:36 +00:00
George Karpenkov f508532627 [analyzer] Fix a bug in RetainCountDiagnostics while printing a note on mismatched summary in inlined functions
Previously, we were not printing a note at all if at least one of the parameters was not annotated.

rdar://46888422

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

llvm-svn: 349875
2018-12-21 02:16:23 +00:00
Reid Kleckner 0a6096bab2 [mingw] Don't mangle thiscall like fastcall etc
GCC does not mangle it when it is not explicit in the source.  The
mangler as currently written cannot differentiate between explicit and
implicit calling conventions, so we can't match GCC. Explicit thiscall
conventions are rare, so mangle as if the convention was implicit to be
as ABI compatible as possible.

Also fixes some tests using %itanium_abi_triple in some configurations
as a side effect.

Fixes PR40107.

llvm-svn: 349872
2018-12-21 01:40:29 +00:00
Artem Dergachev 0ec95c8651 [driver] [analyzer] Fix --analyze -Xanalyzer after r349863.
If an -analyzer-config is passed through -Xanalyzer, it is not found while
looking for -Xclang.

Additionally, don't emit -analyzer-config-compatibility-mode for *every*
-analyzer-config flag we encounter; one is enough.

https://reviews.llvm.org/D55823

rdar://problem/46504165

llvm-svn: 349866
2018-12-21 01:11:21 +00:00
George Karpenkov 6d45b1f3b0 Revert "Revert "[driver] [analyzer] Fix a backward compatibility issue after r348038.""
This reverts commit 144927939587b790c0536f4ff08245043fc8d733.

Fixes the bug in the original commit.

llvm-svn: 349863
2018-12-21 00:26:19 +00:00
Artem Dergachev 212bbfad25 [analyzer] RetainCount: Suppress retain detection heuristic on some CM methods.
If it ends with "Retain" like CFRetain and returns a CFTypeRef like CFRetain,
then it is not necessarily a CFRetain. But it is indeed true that these two
return something retained.

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

rdar://problem/39390714

llvm-svn: 349862
2018-12-21 00:18:58 +00:00
Volodymyr Sapsai 232d22f380 [CodeGen] Fix assertion on emitting cleanup for object with inlined inherited constructor and non-trivial destructor.
Fixes assertion
> Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file llvm/Support/Casting.h, line 255.

It was triggered by trying to cast `FunctionDecl` to `CXXMethodDecl` as
`CGF.CurCodeDecl` in `CallBaseDtor::Emit`. It was happening because
cleanups were emitted in `ScalarExprEmitter::VisitExprWithCleanups`
after destroying `InlinedInheritingConstructorScope`, so
`CodeGenFunction.CurCodeDecl` didn't correspond to expected cleanup decl.

Fix the assertion by emitting cleanups before leaving
`InlinedInheritingConstructorScope` and changing `CurCodeDecl`.

Test cases based on a patch by Shoaib Meenai.

Fixes PR36748.

rdar://problem/45805151

Reviewers: rsmith, rjmccall

Reviewed By: rjmccall

Subscribers: jkorous, dexonsmith, cfe-commits, smeenai, compnerd

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

llvm-svn: 349848
2018-12-20 22:43:26 +00:00
Erik Pilkington 0876cae0d7 Add support for namespaces on #pragma clang attribute
Namespaces are introduced by adding an "identifier." before a
push/pop directive. Pop directives with namespaces can only pop a
attribute group that was pushed with the same namespace. Push and pop
directives that don't opt into namespaces have the same semantics.

This is necessary to prevent a pitfall of using multiple #pragma
clang attribute directives spread out in a large file, particularly
when macros are involved. It isn't easy to see which pop corripsonds
to which push, so its easy to inadvertently pop the wrong group.

Differential revision: https://reviews.llvm.org/D55628

llvm-svn: 349845
2018-12-20 22:32:04 +00:00
Artem Dergachev 46debda1c7 Revert "[driver] [analyzer] Fix a backward compatibility issue after r348038."
This reverts commits r349824, r349828, r349835.

More buildbot failures were noticed.

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

rdar://problem/46504165

llvm-svn: 349843
2018-12-20 22:29:49 +00:00
Alex Lorenz f50d1aca99 [ObjC] Messages to 'self' in class methods that return 'instancetype' should
use the pointer to the class as the result type of the message

Prior to this commit, messages to self in class methods were treated as instance
methods to a Class value. When these methods returned instancetype the compiler
only saw id through the instancetype, and not the Interface *. This caused
problems when that return value was a receiver in a message send, as the
compiler couldn't select the right method declaration and had to rely on a
selection from the global method pool.

This commit modifies the semantics of such message sends and uses class messages
that are dispatched to the interface that corresponds to the class that contains
the class method. This ensures that instancetypes are correctly interpreted by
the compiler. This change is safe under ARC (as self can't be reassigned),
however, it also applies to MRR code as we are assuming that the user isn't
doing anything unreasonable.

rdar://20940997

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

llvm-svn: 349841
2018-12-20 22:11:11 +00:00
Haibo Huang 303b2333e4 Declares __cpu_model as dso local
__builtin_cpu_supports and __builtin_cpu_is use information in __cpu_model to decide cpu features. Before this change, __cpu_model was not declared as dso local. The generated code looks up the address in GOT when reading __cpu_model. This makes it impossible to use these functions in ifunc, because at that time GOT entries have not been relocated. This change makes it dso local.

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

llvm-svn: 349825
2018-12-20 21:33:59 +00:00
Artem Dergachev d001380a69 [driver] [analyzer] Fix a backward compatibility issue after r348038.
Since r348038 we emit an error every time an -analyzer-config option is not
found. The driver, however, suppresses this error with another flag,
-analyzer-config-compatibility-mode, so backwards compatibility is maintained,
while analyzer developers still enjoy the new typo-free experience.

The backwards compatibility turns out to be still broken when the -analyze
action is not specified; it is still possible to specify -analyzer-config
in that case. This should be fixed now.

Patch by Kristóf Umann!

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

rdar://problem/46504165

llvm-svn: 349824
2018-12-20 21:26:40 +00:00
Michael Kruse 0535137e4a [CodeGen] Generate llvm.loop.parallel_accesses instead of llvm.mem.parallel_loop_access metadata.
Instead of generating llvm.mem.parallel_loop_access metadata, generate
llvm.access.group on instructions and llvm.loop.parallel_accesses on
loops. There is one access group per generated loop.

This is clang part of D52116/r349725.

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

llvm-svn: 349823
2018-12-20 21:24:54 +00:00
Aaron Ballman 2f234cbfb0 Allow direct navigation to static analysis checker documentation through SARIF exports.
This adds anchors to all of the documented checks so that you can directly link to a check by a stable name. This is useful because the SARIF file format has a field for specifying a URI to documentation for a rule and some viewers, like CodeSonar, make use of this information. These links are then exposed through the SARIF exporter.

llvm-svn: 349812
2018-12-20 20:20:20 +00:00
Bruno Ricci ed414847bc [Sema] Don't try to account for the size of an incomplete type in CheckArrayAccess
When checking that the array access is not out-of-bounds in CheckArrayAccess
it is possible that the type of the base expression after IgnoreParenCasts is
incomplete, even though the type of the base expression before IgnoreParenCasts
is complete. In this case we have no information about whether the array access
is out-of-bounds and we should just bail-out instead. This fixes PR39746 which
was caused by trying to obtain the size of an incomplete type.

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

Reviewed By: efriedma

llvm-svn: 349811
2018-12-20 20:05:11 +00:00
Artem Dergachev b40e99af08 Revert "[analyzer] pr38668: Do not attempt to cast loaded values..."
This reverts commit r349701.

The patch was incorrect. The whole point of CastRetrievedVal()
is to handle the case in which the type from which the cast is made
(i.e., the "type" of value `V`) has nothing to do with the type of
the region it was loaded from (i.e., `R->getValueType()`).

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

rdar://problem/45062567

llvm-svn: 349798
2018-12-20 19:36:06 +00:00
Simon Pilgrim 4597379227 [X86] Auto upgrade XOP/AVX512 rotation intrinsics to generic funnel shift intrinsics (clang)
This emits FSHL/FSHR generic intrinsics for the XOP VPROT and AVX512 VPROL/VPROR rotation intrinsics.

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

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

llvm-svn: 349796
2018-12-20 19:01:13 +00:00
Pete Cooper 6c47f54df8 Use @llvm.objc.clang.arc.use intrinsic instead of clang.arc.use function.
Calls to this function are deleted in the ARC optimizer.  However when the ARC
optimizer was updated to use intrinsics instead of functions (r349534), the corresponding
clang change (r349535) to use intrinsics missed this one so it wasn't being deleted.

llvm-svn: 349782
2018-12-20 18:05:41 +00:00
Michal Gorny 920936ce5f [Driver] Fix accidentally reversed condition in r349752
llvm-svn: 349754
2018-12-20 13:27:37 +00:00
Michal Gorny 5a409d0e30 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

llvm-svn: 349752
2018-12-20 13:09:30 +00:00
Ulrich Weigand 22ca9c628a [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.

llvm-svn: 349751
2018-12-20 13:09:09 +00:00
Simon Pilgrim 313dc85ce0 [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

llvm-svn: 349743
2018-12-20 11:53:45 +00:00
Clement Courbet fb2c74d98c [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

llvm-svn: 349729
2018-12-20 09:05:15 +00:00
Artem Dergachev 173f55693e [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

llvm-svn: 349701
2018-12-19 23:48:44 +00:00
Artem Dergachev b68cb5498b [analyzer] GenericTaint: Fix formatting to prepare for incoming improvements.
Patch by Gábor Borsik!

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

llvm-svn: 349698
2018-12-19 23:35:08 +00:00
Artem Dergachev 179064983a [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

llvm-svn: 349696
2018-12-19 23:14:06 +00:00
Douglas Yung 25f0477195 Disable -faddsig by default for PS4 target.
llvm-svn: 349691
2018-12-19 22:45:26 +00:00
Artem Dergachev be2c0c1968 [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

llvm-svn: 349682
2018-12-19 21:50:46 +00:00
David Blaikie 0da49a7ef1 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.

llvm-svn: 349669
2018-12-19 19:33:35 +00:00
Alexey Bataev ce90181751 [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.

llvm-svn: 349657
2018-12-19 18:16:37 +00:00
Ilya Biryukov b45d851bdd [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

llvm-svn: 349655
2018-12-19 18:01:24 +00:00
Michal Gorny f647a9f7dd [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

llvm-svn: 349650
2018-12-19 17:25:59 +00:00
Michal Gorny aaf83c267d [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

llvm-svn: 349647
2018-12-19 17:25:46 +00:00
Joel E. Denny 0fdf5a9acc [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

llvm-svn: 349635
2018-12-19 15:59:47 +00:00
Simon Pilgrim a7b30b4a58 [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

llvm-svn: 349631
2018-12-19 14:43:47 +00:00
Haojian Wu e2a27b3f76 [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

llvm-svn: 349626
2018-12-19 13:44:41 +00:00
Bill Wendling 642e140beb 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.

llvm-svn: 349604
2018-12-19 04:54:29 +00:00
Bill Wendling 13381fbc29 Revert accidentally included code.
llvm-svn: 349603
2018-12-19 04:36:42 +00:00
Dan Albert f5ffa1a67c [Driver] Also obey -nostdlib++ when rewriting -lstdc++.
Reviewers: pirama

Reviewed By: pirama

Subscribers: cfe-commits

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

llvm-svn: 349570
2018-12-18 23:29:35 +00:00
Bill Wendling aa77513bb9 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

llvm-svn: 349561
2018-12-18 22:54:03 +00:00
Kelvin Li ef57943e3f [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

llvm-svn: 349551
2018-12-18 22:18:41 +00:00
Vedant Kumar 77dfca88b2 [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

llvm-svn: 349542
2018-12-18 21:05:03 +00:00
Alexey Bataev 6a1b06bcd4 [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.

llvm-svn: 349540
2018-12-18 21:01:42 +00:00
Pete Cooper 2cd3596b1a 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
llvm-svn: 349535
2018-12-18 20:33:00 +00:00
Alexey Bataev 29d47fcb30 [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.

llvm-svn: 349525
2018-12-18 19:20:15 +00:00
Pierre Gousseau 53b5cfb080 [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

llvm-svn: 349508
2018-12-18 17:03:35 +00:00
Erich Keane 2a4eea3061 [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
llvm-svn: 349506
2018-12-18 16:22:21 +00:00
Aaron Ballman 94d2d09c76 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.

llvm-svn: 349497
2018-12-18 15:54:38 +00:00
Stefan Pintilie 4810420ca1 [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

llvm-svn: 349489
2018-12-18 15:08:03 +00:00
Martin Storsjo 56f9c81c60 [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

llvm-svn: 349452
2018-12-18 08:36:10 +00:00
Tan S. B. 9f935e8749 [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
Fixes PR39858

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

llvm-svn: 349444
2018-12-18 07:38:06 +00:00
JF Bastien 14daa20be1 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]: 776a0955ef
  [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

llvm-svn: 349442
2018-12-18 05:12:21 +00:00
Reid Kleckner 1a94d877bf 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.

llvm-svn: 349415
2018-12-17 23:16:43 +00:00
Reid Kleckner d2f98772d0 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

llvm-svn: 349414
2018-12-17 23:10:43 +00:00
Artem Dergachev b4bde2acee [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

llvm-svn: 349394
2018-12-17 21:07:38 +00:00
Alex Lorenz 9b20a99823 [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

llvm-svn: 349382
2018-12-17 19:30:46 +00:00
Francis Visoiu Mistrih d18f17e587 [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

llvm-svn: 349381
2018-12-17 19:29:27 +00:00
Alex Lorenz 0a264f3928 [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

llvm-svn: 349380
2018-12-17 19:19:15 +00:00
Gabor Marton 54058b5055 [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

llvm-svn: 349351
2018-12-17 13:53:12 +00:00
Gabor Marton 7df342a4d1 [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

llvm-svn: 349349
2018-12-17 12:42:12 +00:00
Kristof Umann 9af1d2d10f 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'"

llvm-svn: 349344
2018-12-17 12:25:48 +00:00
Simon Pilgrim 6d2d96e62f Fix "enumeral mismatch in conditional expression" gcc7 warning. NFCI.
llvm-svn: 349343
2018-12-17 12:25:42 +00:00
Simon Pilgrim fc0ff61f31 Fix "enumeral mismatch in conditional expression" gcc7 warnings. NFCI.
llvm-svn: 349342
2018-12-17 12:17:37 +00:00
Kristof Umann 09e86e77c9 Revert rC349281 '[analyzer][MallocChecker][NFC] Document and reorganize some functions'
llvm-svn: 349340
2018-12-17 12:07:57 +00:00
Kristof Umann a033466602 Reverting bitfield size to attempt to fix a windows buildbot
llvm-svn: 349336
2018-12-17 10:31:35 +00:00
Artem Dergachev 2b500cbdf1 [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

llvm-svn: 349327
2018-12-17 06:19:32 +00:00
Artem Dergachev 69909540a7 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

llvm-svn: 349326
2018-12-17 05:25:23 +00:00
Artem Dergachev dda42164ec [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

llvm-svn: 349320
2018-12-16 23:44:06 +00:00
Aaron Puchert 1386b59baf 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.

llvm-svn: 349308
2018-12-16 16:19:11 +00:00
Aaron Puchert 6a68efc959 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

llvm-svn: 349300
2018-12-16 14:15:30 +00:00
Kristof Umann a82810c56b [analyzer][MallocChecker] Improve warning messages on double-delete errors
Differential Revision: https://reviews.llvm.org/D54834

llvm-svn: 349283
2018-12-15 18:41:37 +00:00
Kristof Umann cf6bb77f65 [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

llvm-svn: 349281
2018-12-15 18:34:00 +00:00
Kristof Umann b0be2ab4d0 [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

llvm-svn: 349280
2018-12-15 18:11:49 +00:00
Kristof Umann 76a21502fd [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

llvm-svn: 349275
2018-12-15 16:23:51 +00:00
Kristof Umann f282d27215 [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.

llvm-svn: 349274
2018-12-15 15:44:05 +00:00
Gabor Horvath 21aa8db606 [analyzer] Assume that we always have a SubEngine available
The removed codepath was dead.

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

llvm-svn: 349266
2018-12-15 13:20:33 +00:00
Martin Storsjo 4790194b19 [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

llvm-svn: 349256
2018-12-15 08:08:11 +00:00
Artem Dergachev fe5be58162 Revert "[analyzer] MoveChecker: Add checks for dereferencing a smart pointer..."
This reverts commit r349226.

Fails on an MSVC buildbot.

llvm-svn: 349233
2018-12-15 02:55:55 +00:00
Richard Trieu 41b1960a89 Move static analyzer core diagnostics to common.
llvm-svn: 349230
2018-12-15 02:30:16 +00:00
Artem Dergachev 46f34624d2 [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

llvm-svn: 349229
2018-12-15 02:13:26 +00:00
Artem Dergachev 0ce45fae72 [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

llvm-svn: 349228
2018-12-15 02:09:02 +00:00
Artem Dergachev 5f500a33c1 [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

llvm-svn: 349227
2018-12-15 02:06:13 +00:00
Artem Dergachev ffba750a0e [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

llvm-svn: 349226
2018-12-15 01:53:38 +00:00
Artem Dergachev b5b974e4b3 [analyzer] MoveChecker: NFC: De-duplicate a few checks.
No functional change intended.

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

llvm-svn: 349225
2018-12-15 01:50:58 +00:00
Reid Kleckner f5f6290899 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

llvm-svn: 349212
2018-12-14 23:42:59 +00:00
Erich Keane 24a0f04f77 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
llvm-svn: 349209
2018-12-14 23:17:34 +00:00
Erich Keane 1b9c746034 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.

llvm-svn: 349206
2018-12-14 22:41:18 +00:00
Erich Keane 07325c80d9 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
llvm-svn: 349201
2018-12-14 22:22:29 +00:00
Aaron Ballman 847e73d69c Using llvm::find_if() instead of a range-based for loop; NFC.
This addresses post-commit review feedback from r349188.

llvm-svn: 349197
2018-12-14 21:14:44 +00:00
Eric Fiselier 261875054e [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

llvm-svn: 349195
2018-12-14 21:11:28 +00:00
Alexey Bataev ae51b96f99 [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.

llvm-svn: 349192
2018-12-14 21:00:58 +00:00
Artem Dergachev 11cadc3e6b [analyzer] MoveChecker Pt.6: Suppress the warning for the move-safe STL classes.
Some C++ standard library classes provide additional guarantees about their
state after move. Suppress warnings on such classes until a more precise
behavior is implemented. Warnings for locals are not suppressed anyway
because it's still most likely a bug.

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

llvm-svn: 349191
2018-12-14 20:52:57 +00:00
Artem Dergachev 12f7c2bacc [analyzer] MoveChecker: Improve invalidation policies.
If a moved-from object is passed into a conservatively evaluated function
by pointer or by reference, we assume that the function may reset its state.

Make sure it doesn't apply to const pointers and const references. Add a test
that demonstrates that it does apply to rvalue references.

Additionally, make sure that the object is invalidated when its contents change
for reasons other than invalidation caused by evaluating a call conservatively.
In particular, when the object's fields are manipulated directly, we should
assume that some sort of reset may be happening.

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

llvm-svn: 349190
2018-12-14 20:47:58 +00:00
Aaron Ballman 3ccec59ec2 Update our SARIF support from 10-10 to 11-28.
Functional changes include:

* The run.files property is now an array instead of a mapping.
* fileLocation objects now have a fileIndex property specifying the array index into run.files.
* The resource.rules property is now an array instead of a mapping.
* The result object was given a ruleIndex property that is an index into the resource.rules array.
* rule objects now have their "id" field filled out in addition to the name field.
* Updated the schema and spec version numbers to 11-28.

llvm-svn: 349188
2018-12-14 20:34:23 +00:00
Scott Linder de6beb02a5 Implement -frecord-command-line (-frecord-gcc-switches)
Implement options in clang to enable recording the driver command-line
in an ELF section.

Implement a new special named metadata, llvm.commandline, to support
frontends embedding their command-line options in IR/ASM/ELF.

This differs from the GCC implementation in some key ways:

* In GCC there is only one command-line possible per compilation-unit,
  in LLVM it mirrors llvm.ident and multiple are allowed.
* In GCC individual options are separated by NULL bytes, in LLVM entire
  command-lines are separated by NULL bytes. The advantage of the GCC
  approach is to clearly delineate options in the face of embedded
  spaces. The advantage of the LLVM approach is to support merging
  multiple command-lines unambiguously, while handling embedded spaces
  with escaping.

Differential Revision: https://reviews.llvm.org/D54487
Clang Differential Revision: https://reviews.llvm.org/D54489

llvm-svn: 349155
2018-12-14 15:38:15 +00:00
Richard Trieu 0f25c747a3 Fix up diagnostics.
Move some diagnostics around between Diagnostic*Kinds.td files.  Diagnostics
used in multiple places were moved to DiagnosticCommonKinds.td.  Diagnostics
listed in the wrong place (ie, Sema diagnostics listed in
DiagnosticsParseKinds.td) were moved to the correct places.  One diagnostic
split into two so that the diagnostic string is in the .td file instead of in
code.  Cleaned up the diagnostic includes after all the changes.

llvm-svn: 349125
2018-12-14 03:35:10 +00:00
Adam Nemet cbb8aa196b Revert "Make -Wstring-plus-int warns even if when the result is not out of bounds"
This reverts commit r349054.

It's causing:

FAILED: tools/clang/bindings/python/tests/CMakeFiles/check-clang-python
FAIL: test_diagnostic_range (tests.cindex.test_diagnostics.TestDiagnostics)
----------------------------------------------------------------------
Traceback (most recent call last):
  File
  "/Users/buildslave/jenkins/workspace/clang-stage1-configure-RA/llvm/tools/clang/bindings/python/tests/cindex/test_diagnostics.py",
  line 55, in test_diagnostic_range
      self.assertEqual(len(tu.diagnostics), 1)
      AssertionError: 2 != 1

======================================================================
FAIL: test_diagnostic_warning (tests.cindex.test_diagnostics.TestDiagnostics)
----------------------------------------------------------------------
Traceback (most recent call last):
  File
  "/Users/buildslave/jenkins/workspace/clang-stage1-configure-RA/llvm/tools/clang/bindings/python/tests/cindex/test_diagnostics.py",
  line 18, in test_diagnostic_warning
      self.assertEqual(len(tu.diagnostics), 2)
      AssertionError: 1 != 2

llvm-svn: 349117
2018-12-14 00:43:34 +00:00
Craig Topper 1f2b181689 [Builltins][X86] Provide implementations of __lzcnt16, __lzcnt, __lzcnt64 for MS compatibility. Remove declarations from intrin.h and implementations from lzcntintrin.h
intrin.h had forward declarations for these and lzcntintrin.h had implementations that were only available with -mlzcnt or a -march that supported the lzcnt feature.

For MS compatibility we should always have these builtins available regardless of X86 being the target or the CPU support the lzcnt instruction. The backends should be able to gracefully fallback to something support even if its just shifts and bit ops.

Unfortunately, gcc also implements 2 of the 3 function names here on X86 when lzcnt feature is enabled.

This patch adds builtins for these for MSVC compatibility and drops the forward declarations from intrin.h. To keep the gcc compatibility the two intrinsics that collided have been turned into macros that use the X86 specific builtins with the lzcnt feature check. These macros are only defined when _MSC_VER is not defined. Without them being macros we can get a redefinition error because -ms-extensions doesn't seem to set _MSC_VER but does make the MS builtins available.

Should fix PR40014

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

llvm-svn: 349098
2018-12-14 00:21:02 +00:00
Artem Belevich 7b05666a19 [CUDA] Make all host-side shadows of device-side variables undef.
The host-side code can't (and should not) access the values that may
only exist on the device side. E.g. address of a __device__ function
does not exist on the host side as we don't generate the code for it there.

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

llvm-svn: 349087
2018-12-13 21:43:04 +00:00
Adrian Prantl 046d100b41 Reinstate DW_AT_comp_dir support after D55519.
The DIFile used by the CU is special and distinct from the main source
file. Its directory part specifies what becomes the DW_AT_comp_dir
(the compilation directory), even if the source file was specified
with an absolute path.

To support the .dwo workflow, a valid DW_AT_comp_dir is necessary even
if source files were specified with an absolute path.

llvm-svn: 349065
2018-12-13 17:53:29 +00:00
Ilya Biryukov 67dbeb6c6a [CodeComplete] Temporarily disable failing assertion
Found the case in the clang codebase where the assertion fires.
To avoid crashing assertion-enabled builds before I re-add the missing
operation.
Will restore the assertion alongside the upcoming fix.

llvm-svn: 349061
2018-12-13 17:23:48 +00:00
Sylvestre Ledru 8523c085e7 Make -Wstring-plus-int warns even if when the result is not out of bounds
Summary: Patch by Arnaud Bienner

Reviewers: sylvestre.ledru, thakis

Reviewed By: thakis

Subscribers: cfe-commits

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

llvm-svn: 349054
2018-12-13 16:06:23 +00:00
Ilya Biryukov 4974d75d7c [CodeComplete] Fill preferred type on binary expressions
Reviewers: kadircet

Reviewed By: kadircet

Subscribers: arphaman, cfe-commits

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

llvm-svn: 349053
2018-12-13 16:06:11 +00:00
Ilya Biryukov 4110967c7b [CodeComplete] Set preferred type to bool on conditions
Reviewers: kadircet

Reviewed By: kadircet

Subscribers: cfe-commits

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

llvm-svn: 349050
2018-12-13 15:36:32 +00:00
Mikael Nilsson 9d2872db74 [OpenCL] Add generic AS to 'this' pointer
Address spaces are cast into generic before invoking the constructor.

Added support for a trailing Qualifiers object in FunctionProtoType.

Note: This recommits the previously reverted patch, 
      but now it is commited together with a fix for lldb.

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

llvm-svn: 349019
2018-12-13 10:15:27 +00:00
Stephane Moore 3897b2dca1 [clang] Add AST matcher for block expressions 🔍
Summary:
This change adds a new AST matcher for block expressions.

Test Notes:
Ran the clang unit tests.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 349004
2018-12-13 03:35:10 +00:00
Reid Kleckner 43071080cd Remove unused Args parameter from EmitFunctionBody, NFC
llvm-svn: 349001
2018-12-13 01:33:20 +00:00
Reid Kleckner 25b56024aa Emit a proper diagnostic when attempting to forward inalloca arguments
The previous assertion was relatively easy to trigger, and likely will
be easy to trigger going forward. EmitDelegateCallArg is relatively
popular.

This cleanly diagnoses PR28299 while I work on a proper solution.

llvm-svn: 348991
2018-12-12 23:46:06 +00:00
Haibo Huang e177082972 Revert "Declares __cpu_model as dso local"
This reverts r348978

llvm-svn: 348982
2018-12-12 22:39:51 +00:00
Haibo Huang 6b22f59207 Declares __cpu_model as dso local
__builtin_cpu_supports and __builtin_cpu_is use information in __cpu_model to decide cpu features. Before this change, __cpu_model was not declared as dso local. The generated code looks up the address in GOT when reading __cpu_model. This makes it impossible to use these functions in ifunc, because at that time GOT entries have not been relocated. This change makes it dso local.

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

llvm-svn: 348978
2018-12-12 22:04:12 +00:00
Eric Fiselier 5cdc2cda28 [AST] Store "UsesADL" information in CallExpr.
Summary:
Currently the Clang AST doesn't store information about how the callee of a CallExpr was found. Specifically if it was found using ADL.

However, this information is invaluable to tooling. Consider a tool which renames usages of a function. If the originally CallExpr was formed using ADL, then the tooling may need to additionally qualify the replacement.
Without information about how the callee was found, the tooling is left scratching it's head. Additionally, we want to be able to match ADL calls as quickly as possible, which means avoiding computing the answer on the fly.

This patch changes `CallExpr` to store whether it's callee was found using ADL. It does not change the size of any AST nodes.


Reviewers: fowles, rsmith, klimek, shafik

Reviewed By: rsmith

Subscribers: aaron.ballman, riccibruno, calabrese, titus, cfe-commits

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

llvm-svn: 348977
2018-12-12 21:50:55 +00:00
Erich Keane 8c94f07f54 Teach __builtin_unpredictable to work through implicit casts.
The __builtin_unpredictable implementation is confused by any implicit
casts, which happen in C++.  This patch strips those off so that
if/switch statements now work with it in C++.

Change-Id: I73c3bf4f1775cd906703880944f4fcdc29fffb0a
llvm-svn: 348969
2018-12-12 20:30:53 +00:00
Erich Keane 8e46c4b83f Change CallGraph print to show the fully qualified name
CallGraph previously would just show the normal name of a function,
which gets really confusing when using it on large C++ projects.  This
patch switches the printName call to a printQualifiedName, so that the
namespaces are included.

Change-Id: Ie086d863f6b2251be92109ea1b0946825b28b49a
llvm-svn: 348950
2018-12-12 18:11:36 +00:00
Steven Wu 098742faa9 [Driver] Add support for -fembed-bitcode for assembly file
Summary:
Handle -fembed-bitcode for assembly inputs. When the input file is
assembly, write a marker as "__LLVM,__asm" section.

Fix llvm.org/pr39659

Reviewers: compnerd, dexonsmith

Reviewed By: compnerd

Subscribers: rjmccall, dblaikie, jkorous, cfe-commits

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

llvm-svn: 348943
2018-12-12 17:30:16 +00:00
Saleem Abdulrasool d4f7d6a7a1 Basic: make `int_least64_t` and `int_fast64_t` match on Darwin
The Darwin targets use `int64_t` and `uint64_t` to define the `int_least64_t`
and `int_fast64_t` types.  The underlying type is actually a `long long`.  Match
the types to allow the printf specifiers to work properly and have the compiler
vended macros match the implementation on the target.

llvm-svn: 348939
2018-12-12 17:05:20 +00:00
Hubert Tong 147b743602 [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types
Summary:
`memchr` and `memcmp` operate upon the character units of the object
representation; that is, the `size_t` parameter expresses the number of
character units. The constant folding implementation is updated in this
patch to account for multibyte element types in the arrays passed to
`memchr`/`memcmp` and, in the case of `memcmp`, to account for the
possibility that the arrays may have differing element types (even when
they are byte-sized).

Actual inspection of the object representation is not implemented.
Comparisons are done only between elements with the same object size;
that is, `memchr` will fail when inspecting at least one character unit
of a multibyte element. The integer types are assumed to have two's
complement representation with 0 for `false`, 1 for `true`, and no
padding bits.

`memcmp` on multibyte elements will only be able to fold in cases where
enough elements are equal for the answer to be 0.

Various tests are added to guard against incorrect folding for cases
that miscompile on some system or other prior to this patch. At the same
time, the unsigned 32-bit `wchar_t` testing in
`test/SemaCXX/constexpr-string.cpp` is restored.

Reviewers: rsmith, aaron.ballman, hfinkel

Reviewed By: rsmith

Subscribers: cfe-commits

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

llvm-svn: 348938
2018-12-12 16:53:43 +00:00
Simon Atanasyan 9d1fa349a4 [mips] Enable using of integrated assembler in all cases.
llvm-svn: 348935
2018-12-12 15:32:25 +00:00
Erich Keane 4d8257e23f Remove TODO leftover from my devleopment branch
Accidentially checked in a TODO line from r348899. This removes it.

Change-Id: I74b59c0ecfe147af8a08dd7fd10893a4ca351d6d
llvm-svn: 348932
2018-12-12 15:13:00 +00:00
Mikael Nilsson 90646732bf Revert "[OpenCL] Add generic AS to 'this' pointer"
Reverting because the patch broke lldb.

llvm-svn: 348931
2018-12-12 15:06:16 +00:00
Alexey Bataev c92fc3c8bc [CUDA][OPENMP][NVPTX]Improve logic of the debug info support.
Summary:
Added support for the -gline-directives-only option + fixed logic of the
debug info for CUDA devices. If optimization level is O0, then options
--[no-]cuda-noopt-device-debug do not affect the debug info level. If
the optimization level is >O0, debug info options are used +
--no-cuda-noopt-device-debug is used or no --cuda-noopt-device-debug is
used, the optimization level for the device code is kept and the
emission of the debug directives is used.
If the opt level is > O0, debug info is requested +
--cuda-noopt-device-debug option is used, the optimization is disabled
for the device code + required debug info is emitted.

Reviewers: tra, echristo

Subscribers: aprantl, guansong, JDevlieghere, cfe-commits

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

llvm-svn: 348930
2018-12-12 14:52:27 +00:00
Mikael Nilsson 78de84719b [OpenCL] Add generic AS to 'this' pointer
Address spaces are cast into generic before invoking the constructor.

Added support for a trailing Qualifiers object in FunctionProtoType.

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

llvm-svn: 348927
2018-12-12 14:11:59 +00:00
Gabor Marton be77a9846d [ASTImporter] Remove import of definition from GetAlreadyImportedOrNull
Summary: a_sidorin

Reviewers: a.sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, cfe-commits

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

llvm-svn: 348923
2018-12-12 11:22:55 +00:00
Andrew Savonichev 87a7e436c0 [OpenCL] Fix for TBAA information of pointer after addresspacecast
Summary: When addresspacecast is generated resulting pointer should preserve TBAA information from original value.

Reviewers: rjmccall, yaxunl, Anastasia

Reviewed By: rjmccall

Subscribers: asavonic, kosarev, cfe-commits, llvm-commits

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

llvm-svn: 348919
2018-12-12 09:51:23 +00:00
Fangrui Song 5313327f61 Add explicit dependency on clangSerialization for a bunch of components to fix -DBUILD_SHARED_LIBS=on build
This is a more thorough fix of rC348911.
The story about -DBUILD_SHARED_LIBS=on build after rC348907 (Move PCHContainerOperations from Frontend to Serialization) is:

1. libclangSerialization.so defines PCHContainerReader dtor, ...
2. clangFrontend and clangTooling define classes inheriting from PCHContainerReader, thus their DSOs have undefined references on PCHContainerReader dtor
3. Components depending on either clangFrontend or clangTooling cannot be linked unless they have explicit dependency on clangSerialization due to the default linker option -z defs. The explicit dependency could be avoided if libclang{Frontend,Tooling}.so had these undefined references.

This patch adds the explicit dependency on clangSerialization to make them build.

llvm-svn: 348915
2018-12-12 08:02:18 +00:00
Fangrui Song 2000170e27 [CodeGen] Fix -DBUILD_SHARED_LIBS=on build after rC348907
llvm-svn: 348911
2018-12-12 06:07:33 +00:00
Richard Trieu f3b0046ba9 Move PCHContainerOperations from Frontend to Serialization
Fix a layering violation.  Frontend depends on Serialization, so anything used
by both should be in Serialization.

llvm-svn: 348907
2018-12-12 02:53:59 +00:00
Erich Keane ef65d6c5c4 Replace Const-Member checking with non-recursive version.
As reported in PR39946, these two implementations cause stack overflows
to occur when a type recursively contains itself.  While this only
happens when an incomplete version of itself is used by membership (and
thus an otherwise invalid program), the crashes might be surprising.

The solution here is to replace the recursive implementation with one
that uses a std::vector as a queue.  Old values are kept around to
prevent re-checking already checked types.

Change-Id: I582bb27147104763d7daefcfee39d91f408b9fa8
llvm-svn: 348899
2018-12-11 21:54:52 +00:00
Aaron Ballman 1c7977b54a Revert r348889; it fails some tests.
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/40784

llvm-svn: 348892
2018-12-11 19:42:04 +00:00
Aaron Ballman 078643e63d 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.

llvm-svn: 348889
2018-12-11 19:18:01 +00:00
David Carlier 37a22ea063 [analyzer][CStringChecker] evaluate explicit_bzero
- explicit_bzero has limited scope/usage only for security/crypto purposes but is non-optimisable version of memset/0 and bzero.
- explicit_memset has similar signature and semantics as memset but is also a non-optimisable version.

Reviewers: NoQ

Reviewed By: NoQ

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

llvm-svn: 348884
2018-12-11 18:57:07 +00:00
Adrian Prantl c2a44ecf39 Remove CGDebugInfo::getOrCreateFile() and use TheCU->getFile() directly.
llvm-svn: 348866
2018-12-11 16:58:46 +00:00
Adrian Prantl aa5bad449b Reuse code from CGDebugInfo::getOrCreateFile() when creating the file
for the DICompileUnit.

This addresses post-commit feedback for D55085. Without this patch, a
main source file with an absolute paths may appear in different
DIFiles, once with the absolute path and once with the common prefix
between the absolute path and the current working directory.

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

llvm-svn: 348865
2018-12-11 16:58:43 +00:00
Eric Fiselier 743ae6045d Pass PartialOverloading argument to the correct corresponding parameter
llvm-svn: 348864
2018-12-11 16:53:25 +00:00
Stefan Pintilie 5e3dc68c6a Revert "[PowerPC] Make no-PIC default to match GCC - CLANG"
This reverts commit rL348299.

llvm-svn: 348858
2018-12-11 15:47:57 +00:00
Clement Courbet f44c6f402c Reland r348741 "[Sema] Further improvements to to static_assert diagnostics."
Fix a dangling reference to temporary, never return nullptr.

llvm-svn: 348834
2018-12-11 08:39:11 +00:00
Clement Courbet 4ba13bd394 Revert r348830 "[Sema]improve static_assert(!expr)"
Submitted the wrong change.

llvm-svn: 348831
2018-12-11 07:28:00 +00:00
Clement Courbet 67b03de9a2 [Sema]improve static_assert(!expr)
llvm-svn: 348830
2018-12-11 07:04:49 +00:00
Richard Trieu 6368818fd5 Move CodeGenOptions from Frontend to Basic
Basic uses CodeGenOptions and should not depend on Frontend.

llvm-svn: 348827
2018-12-11 03:18:39 +00:00
George Karpenkov e8240f4df0 [analyzer] Remove memoization from RunLoopAutoreleaseLeakChecker
Memoization dose not seem to be necessary, as other statement visitors
run just fine without it,
and in fact seems to be causing memory corruptions.
Just removing it instead of investigating the root cause.

rdar://45945002

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

llvm-svn: 348822
2018-12-11 01:14:17 +00:00
George Karpenkov d1081ec508 [analyzer] Hack for backwards compatibility for options for RetainCountChecker.
To be removed once the clients update.

llvm-svn: 348821
2018-12-11 01:13:58 +00:00
George Karpenkov ff01486753 [analyzer] Display a diagnostics when an inlined function violates its os_consumed summary
This is currently a diagnostics, but might be upgraded to an error in the future,
especially if we introduce os_return_on_success attributes.

rdar://46359592

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

llvm-svn: 348820
2018-12-11 01:13:40 +00:00
George Karpenkov 79ed11c12e [analyzer] Resolve another bug where the name of the leaked object was not printed properly
Differential Revision: https://reviews.llvm.org/D55528

llvm-svn: 348819
2018-12-11 01:13:20 +00:00
Stephen Kelly 677e3aec9e Revert "Change InitListExpr dump to label and pointer"
This reverts commit r348794.

llvm-svn: 348799
2018-12-10 21:20:05 +00:00
Stephen Kelly 1be0bea084 Fix nits
llvm-svn: 348798
2018-12-10 21:04:04 +00:00
Stephen Kelly 43835951f4 Re-order content of template parameter dumps
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 348797
2018-12-10 21:03:00 +00:00
Stephen Kelly 266dc19e4e Re-order content in OMPDeclareReductionDecl dump
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 348795
2018-12-10 20:53:39 +00:00
Stephen Kelly a1005921eb Change InitListExpr dump to label and pointer
Summary: Don't add a child just for the label.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 348794
2018-12-10 20:53:32 +00:00
Bruno Cardoso Lopes 5c1399a582 [constexpr][c++2a] Try-catch blocks in constexpr functions
Implement support for try-catch blocks in constexpr functions, as
proposed in http://wg21.link/P1002 and voted in San Diego for c++20.

The idea is that we can still never throw inside constexpr, so the catch
block is never entered. A try-catch block like this:

try { f(); } catch (...) { }

is then morally equivalent to just

{ f(); }

Same idea should apply for function/constructor try blocks.

rdar://problem/45530773

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

llvm-svn: 348789
2018-12-10 19:03:12 +00:00
Fangrui Song d906e731ec ComputeLineNumbers: delete SSE2 vectorization
Summary:
SSE2 vectorization was added in 2012, but it is 2018 now and I can't
observe any performance boost (testing clang -E [all Sema/* CodeGen/* with proper -I options]) with the existing _mm_movemask_epi8+countTrailingZeros or the following SSE4.2 (compiling with -msse4.2):

  __m128i C = _mm_setr_epi8('\r','\n',0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  _mm_cmpestri(C, 2, Chunk, 16, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_POSITIVE_POLARITY | _SIDD_LEAST_SIGNIFICANT)

Delete the vectorization to simplify the code.

Also simplify the code a bit and don't check the line ending sequence \n\r

Reviewers: bkramer, #clang

Reviewed By: bkramer

Subscribers: cfe-commits

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

llvm-svn: 348777
2018-12-10 18:10:35 +00:00
Michael Kruse 157a355f3b Use zip_longest for iterator range comparisons. NFC.
Use zip_longest in two locations that compare iterator ranges.
zip_longest allows the iteration using a range-based for-loop and to be
symmetric over both ranges instead of prioritizing one over the other.
In that latter case code have to handle the case that the first is
longer than the second, the second is longer than the first, and both
are of the same length, which must partially be checked after the loop.

With zip_longest, this becomes an element comparison within the loop
like the comparison of the elements themselves. The symmetry makes it
clearer that neither the first and second iterators are handled
differently. The iterators are not event used directly anymore, just
the ranges.

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

llvm-svn: 348762
2018-12-10 15:16:37 +00:00
Raphael Isemann b23ccecbb0 Misc typos fixes in ./lib folder
Summary: Found via `codespell -q 3 -I ../clang-whitelist.txt -L uint,importd,crasher,gonna,cant,ue,ons,orign,ned`

Reviewers: teemperor

Reviewed By: teemperor

Subscribers: teemperor, jholewinski, jvesely, nhaehnle, whisperity, jfb, cfe-commits

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

llvm-svn: 348755
2018-12-10 12:37:46 +00:00
Andrew Savonichev 1bf1a156d6 [OpenCL][CodeGen] Fix replacing memcpy with addrspacecast
Summary:
If a function argument is byval and RV is located in default or alloca address space
an optimization of creating addrspacecast instead of memcpy is performed. That is
not correct for OpenCL, where that can lead to a situation of address space casting
from __private * to __global *. See an example below:

```
typedef struct {
  int x;
} MyStruct;

void foo(MyStruct val) {}

kernel void KernelOneMember(__global MyStruct* x) {
  foo (*x);
}
```

for this code clang generated following IR:
...
%0 = load %struct.MyStruct addrspace(1)*, %struct.MyStruct addrspace(1)**
%x.addr, align 4
%1 = addrspacecast %struct.MyStruct addrspace(1)* %0 to %struct.MyStruct*
...

So the optimization was disallowed for OpenCL if RV is located in an address space
different than that of the argument (0).


Reviewers: yaxunl, Anastasia

Reviewed By: Anastasia

Subscribers: cfe-commits, asavonic

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

llvm-svn: 348752
2018-12-10 12:03:00 +00:00
Clement Courbet d872041f8f Revert r348741 "[Sema] Further improvements to to static_assert diagnostics."
Seems to break build bots.

llvm-svn: 348742
2018-12-10 08:53:17 +00:00
Clement Courbet 057f7695de [Sema] Further improvements to to static_assert diagnostics.
Summary:
We're now handling cases like `static_assert(!expr)` and
static_assert(!(expr))`.

Reviewers: aaron.ballman, Quuxplusone

Subscribers: cfe-commits

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

llvm-svn: 348741
2018-12-10 08:19:38 +00:00
Craig Topper 6d7a7ef9eb [X86] Remove the addcarry builtins. Leaving only the addcarryx builtins since that matches gcc.
The addcarry and addcarryx builtins do the same thing. The only difference is that addcarryx previously required adx feature.

This commit removes the adx feature check from addcarryx and removes the addcarry builtin. This matches the builtins that gcc has. We don't guarantee compatibility in builtins, but we generally try to be consistent if its not a burden.

llvm-svn: 348738
2018-12-10 06:07:59 +00:00
Stephen Kelly 2413638a6d NFC: Rename TemplateDecl dump utilities
There is a clang::TemplateDecl AST type, so a method called
VisitTemplateDecl looks like it should 'override' the method from the
base visitor, but it does not because of the extra parameters it takes.

In reality, these methods are utilities, so name them like utilities.

llvm-svn: 348720
2018-12-09 13:33:30 +00:00
Stephen Kelly e26a88aaa8 NFC: Move dump of individual comment nodes to NodeDumper
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 348719
2018-12-09 13:30:17 +00:00
Stephen Kelly 50a29bd40b Revert "Introduce optional labels to dumpStmt"
This reverts commit 933402caa09963792058198578522a95f013c69c.

llvm-svn: 348718
2018-12-09 13:24:40 +00:00
Stephen Kelly 3283535dc8 Introduce optional labels to dumpStmt
If the label is present, it is added as a child, with the statement a
child of the label.  This preserves behavior of the InitListExpr dump
output.

llvm-svn: 348717
2018-12-09 13:23:07 +00:00
Stephen Kelly 39271a195b Inline hasNodes into only caller
It is easier to refactor with fewer utility methods.

llvm-svn: 348716
2018-12-09 13:20:43 +00:00
Stephen Kelly 570b297673 Inline dumpFullComment into callers
It causes confusion over whether it or dumpComment is the more
important. It is easier to refactor with fewer utility methods.

llvm-svn: 348715
2018-12-09 13:18:55 +00:00
Stephen Kelly 7ec37b2b29 Re-order content from InitListExpr
Summary:
This causes no change in the output of ast-dump-stmt.cpp due to the way
child nodes are printed with a delay.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 348714
2018-12-09 13:15:18 +00:00
Fangrui Song eae2b49fe3 SourceManager: insert(make_pair(..)) -> try_emplace. NFC
llvm-svn: 348709
2018-12-09 01:46:01 +00:00
Pete Cooper e388680dfa Convert some ObjC msgSends to runtime calls.
It is faster to directly call the ObjC runtime for methods such as alloc/allocWithZone instead of sending a message to those functions.

This patch adds support for converting messages to alloc/allocWithZone to their equivalent runtime calls.

Tests included for the positive case of applying this transformation, negative tests that we ensure we only convert "alloc" to objc_alloc, not "alloc2", and also a driver test to ensure we enable this only for supported runtime versions.

Reviewed By: rjmccall

https://reviews.llvm.org/D55349

llvm-svn: 348687
2018-12-08 05:13:50 +00:00
George Karpenkov 041c9fa8ba Stop tracking retain count of OSObject after escape to void * / other primitive types
Escaping to void * / uint64_t / others non-OSObject * should stop tracking,
as such functions can have heterogeneous semantics depending on context,
and can not always be annotated.

rdar://46439133

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

llvm-svn: 348675
2018-12-08 01:18:40 +00:00
Artem Belevich 43cfce88b4 [CUDA] Added missing 'inline' for functions defined in a header.
llvm-svn: 348662
2018-12-07 22:20:53 +00:00
Volodymyr Sapsai 978be4c1a3 [Preprocessor] Don't avoid entering included files after hitting a fatal error.
Change in r337953 violated the contract for `CXTranslationUnit_KeepGoing`:

> Do not stop processing when fatal errors are encountered.

Use different approach to fix long processing times with multiple inclusion
cycles. Instead of stopping preprocessing for fatal errors, do this after
reaching the max allowed include depth and only for the files that were
processed already. It is likely but not guaranteed those files cause a cycle.

rdar://problem/46108547

Reviewers: erik.pilkington, arphaman

Reviewed By: erik.pilkington

Subscribers: jkorous, dexonsmith, ilya-biryukov, Dmitry.Kozhevnikov

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

llvm-svn: 348641
2018-12-07 20:29:54 +00:00
George Karpenkov 27db33075c [analyzer] Move out tracking retain count for OSObjects into a separate checker
Allow enabling and disabling tracking of ObjC/CF objects
separately from tracking of OS objects.

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

llvm-svn: 348638
2018-12-07 20:21:51 +00:00
George Karpenkov 936a9c978c [analyzer] RetainCountChecker: remove untested, unused, incorrect option IncludeAllocationLine
The option has no tests, is not used anywhere, and is actually
incorrect: it prints the line number without the reference to a file,
which can be outright incorrect.

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

llvm-svn: 348637
2018-12-07 20:21:37 +00:00
Gabor Marton 32aff2eb79 [CTU] Add triple/lang mismatch handling
Summary:
We introduce a strict policy for C++ CTU. It can work across TUs only if
the C++ dialects are the same. We neither allow C vs C++ CTU.  We do this
because the same constructs might be represented with different properties in
the corresponding AST nodes or even the nodes might be completely different (a
struct will be RecordDecl in C, but it will be a CXXRectordDecl in C++, thus it
may cause certain assertions during cast operations).

Reviewers: xazax.hun, a_sidorin

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

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

llvm-svn: 348610
2018-12-07 16:32:43 +00:00
Gabor Marton b87251d0bb [CTU] Add more lit tests and better error handling
Summary:
Adding some more CTU list tests. E.g. to check if a construct is unsupported.
We also slightly modify the handling of the return value of the `Import`
function from ASTImporter.

Reviewers: xazax.hun, balazske, a_sidorin

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

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

llvm-svn: 348605
2018-12-07 16:05:58 +00:00
Erich Keane 248ed07419 Make CPUDispatch resolver emit dependent functions.
Inline cpu_specific versions referenced before the cpu_dispatch function
weren't properly emitted, since they hadn't been referred to.  This
patch ensures that during resolver generation that all appropriate
versions are emitted.

Change-Id: I94c3766aaf9c75ca07a0ad8258efdbb834654ff8
llvm-svn: 348600
2018-12-07 15:31:23 +00:00
Erich Keane c6d5631cd5 Revert "Multiversioning- Ensure all MV functions are emitted."
This reverts commit 65df29f9318ac13a633c0ce13b2b0bccf06e79ca.

AS suggested by @rsmith here: https://reviews.llvm.org/rL345839
I'm reverting this and solving the initial problem in a different way.

llvm-svn: 348595
2018-12-07 14:56:50 +00:00
Gabor Marton 9419eb42c4 [CTU] Add DisplayCTUProgress analyzer switch
Summary:
With a new switch we may be able to print to stderr if a new TU is being loaded
during CTU.  This is very important for higher level scripts (like CodeChecker)
to be able to parse this output so they can create e.g. a zip file in case of
a Clang crash which contains all the related TU files.

Reviewers: xazax.hun, Szelethus, a_sidorin, george.karpenkov

Subscribers: whisperity, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp,

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

llvm-svn: 348594
2018-12-07 14:56:02 +00:00
Ilya Biryukov 143a9e0b12 [CodeComplete] Fix assertion failure
Summary:
...that fires when running completion inside an argument of
UnresolvedMemberExpr (see the added test).

The assertion that fires is from Sema::TryObjectArgumentInitialization:

    assert(FromClassification.isLValue());

This happens because Sema::AddFunctionCandidates does not account for
object types which are pointers. It ends up classifying them incorrectly.
All usages of the function outside code completion are used to run
overload resolution for operators. In those cases the object type being
passed is always a non-pointer type, so it's not surprising the function
did not expect a pointer in the object argument.

However, code completion reuses the same function and calls it with the
object argument coming from UnresolvedMemberExpr, which can be a pointer
if the member expr is an arrow ('->') access.

Extending AddFunctionCandidates to allow pointer object types does not
seem too crazy since all the functions down the call chain can properly
handle pointer object types if we properly classify the object argument
as an l-value, i.e. the classification of the implicitly dereferenced
pointer.

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: cfe-commits

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

llvm-svn: 348590
2018-12-07 13:17:52 +00:00
Gabor Marton b7f30dda39 [CTU] Add asserts to protect invariants
Reviewers: xazax.hun, a_sidorin

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

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

llvm-svn: 348586
2018-12-07 12:21:43 +00:00
Gabor Marton 700a29a153 [CTU] Add statistics
Reviewers: xazax.hun, a_sidorin

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

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

llvm-svn: 348584
2018-12-07 11:55:22 +00:00
Kang Zhang 9606d58a5f [PowerPC] VSX register support for inline assembly
Summary:
The patch is to add the VSX register support for inline assembly. After this 
patch, we can use VSX register in inline assembly clobber list without error.

Reviewed By: jsji,  nemanjai

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

llvm-svn: 348572
2018-12-07 08:58:12 +00:00
Hans Wennborg 86aba5eeee Fix thunks returning memptrs via sret by emitting also scalar return values directly in sret slot (PR39901)
Thunks that return member pointers via sret are broken due to using temporary
storage for the return value on the stack and then passing that pointer to a
tail call, violating the rule that a tail call can't access allocas in the
caller (see bug).

Since r90526, we put aggregate return values directly in the sret slot, but
this doesn't apply to member pointers which are considered scalar.

Unless I'm missing something subtle, we should be able to always use the sret
slot directly for indirect return values.

Differential revision: https://reviews.llvm.org/D55371

llvm-svn: 348569
2018-12-07 08:17:26 +00:00
Stephen Kelly 50e82875bc NFC: Move VisitExpr code to dumpStmt
Summary:
The call is duplicated in the handlers of all Expr subclasses.

This change makes it easy to split statement handling out to
TextNodeDumper.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 348546
2018-12-06 23:33:33 +00:00
Stephen Kelly b9d6a5eb4f NFC: Move VisitStmt code to dumpStmt
Summary: This call is duplicated in Visits of all direct subclasses of Stmt.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 348545
2018-12-06 23:33:27 +00:00
Alex Lorenz 2e7ab55e65 [frontend][darwin] warn_stdlibcxx_not_found: supress warning for preprocessed input
Addresses second post-commit feedback for r335081 from Nico

llvm-svn: 348540
2018-12-06 22:45:58 +00:00
George Karpenkov b0b61955a1 [analyzer] Rely on os_consumes_this attribute to signify that the method call consumes a reference for "this"
Differential Revision: https://reviews.llvm.org/D55158

llvm-svn: 348533
2018-12-06 22:07:12 +00:00
George Karpenkov da2c77f92b [attributes] Add an attribute os_consumes_this, with similar semantics to ns_consumes_self
The attribute specifies that the call of the C++ method consumes a
reference to "this".

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

llvm-svn: 348532
2018-12-06 22:06:59 +00:00
George Karpenkov a71ec6c00a [analyzer] Fix an infinite recursion bug while checking parent methods in RetainCountChecker
Differential Revision: https://reviews.llvm.org/D55351

llvm-svn: 348531
2018-12-06 22:06:44 +00:00
Nico Weber 4c9fa4a0a1 Allow forwarding -fdebug-compilation-dir to cc1as
The flag -fdebug-compilation-dir is useful to make generated .o files
independent of the path of the build directory, without making the compile
command-line dependent on the path of the build directory, like
-fdebug-prefix-map requires. This change makes it so that the driver can
forward the flag to -cc1as, like it already can for -cc1. We might want to
consider making -fdebug-compilation-dir a driver flag in a follow-up.

(Since -fdebug-compilation-dir defaults to PWD, it's already possible to get
this effect by setting PWD, but explicit compiler flags are better than env
vars, because e.g. ninja tracks command lines and reruns commands that change.)

Somewhat related to PR14625.

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

llvm-svn: 348515
2018-12-06 18:50:39 +00:00
Adrian Prantl 212c104ea3 Reapply "Avoid emitting redundant or unusable directories in DIFile metadata entries.""
This reverts commit r348280 and reapplies D55085 without modifications.

Original commit message:

    Avoid emitting redundant or unusable directories in DIFile metadata entries.

    As discussed on llvm-dev recently, Clang currently emits redundant
    directories in DIFile entries, such as

      .file      1 "/Volumes/Data/llvm" "/Volumes/Data/llvm/tools/clang/test/CodeGen/debug-info-abspath.c"

    This patch looks at any common prefix between the compilation
    directory and the (absolute) file path and strips the redundant
    part. More importantly it leaves the compilation directory empty if
    the two paths have no common prefix.

    After this patch the above entry is (assuming a compilation dir of "/Volumes/Data/llvm/_build"):

      .file 1 "/Volumes/Data/llvm" "tools/clang/test/CodeGen/debug-info-abspath.c"

    When building the FileCheck binary with debug info, this patch makes
    the build artifacts ~1kb smaller.

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

llvm-svn: 348513
2018-12-06 18:44:50 +00:00
Joel E. Denny 6dd34dc3dd [CUDA] Fix nvidia-cuda-toolkit detection on Ubuntu
This just extends D40453 (r319317) to Ubuntu.

Reviewed By: Hahnfeld, tra

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

llvm-svn: 348504
2018-12-06 17:46:17 +00:00
Alexey Bataev 6393eb7ec6 [OPENMP][NVPTX] Fix globalization of the mapped array sections.
If the array section is based on pointer and this sections is mapped in
target region + then it is used in the inner parallel region, it also
must be globalized as the pointer itself is passed by value, not by
reference.

llvm-svn: 348492
2018-12-06 15:35:13 +00:00
Serge Pavlov acfcd78aec Diagnose friend function template redefinitions.
Friend function template defined in a class template becomes available if
the enclosing class template is instantiated. Until the function template
is used, it does not have a body, but still is considered a definition for
the purpose of redeclaration checks.

This change modifies redefinition check so that it can find the friend
function template definitions in instantiated classes.

Differential Revision: http://reviews.llvm.org/D21508

llvm-svn: 348473
2018-12-06 09:35:04 +00:00
Richard Trieu 587c1cb9f7 Remove unnecessary include.
llvm-svn: 348459
2018-12-06 06:32:40 +00:00
Richard Trieu 5337c74825 Remove CodeGen dependencies on Sema.
Move diagnostics from Sema to Frontend (or Common) so that CodeGen no longer
needs to include the Sema diagnostic IDs.

llvm-svn: 348458
2018-12-06 06:12:20 +00:00
Saleem Abdulrasool f587857c88 ARM, AArch64: support `__attribute__((__swiftcall__))`
Support the Swift calling convention on Windows ARM and AArch64.  Both
of these conform to the AAPCS, AAPCS64 calling convention, and LLVM has
been adjusted to account for the register usage.  Ensure that the
frontend passes this into the backend.  This allows the swift runtime to
be built for Windows.

llvm-svn: 348454
2018-12-06 03:28:37 +00:00
Alex Lorenz 1ae9cd7e6a [darwin] remove version number check when enabling -fobjc-subscripting-legacy-runtime
This subscripting feature actually works on older OS versions anyway.

rdar://36287065

llvm-svn: 348448
2018-12-06 02:44:23 +00:00
Leonard Chan ad7ac964e5 [Sema/Attribute] Check for noderef attribute
This patch adds the noderef attribute in clang and checks for dereferences of
types that have this attribute. This attribute is currently used by sparse and
would like to be ported to clang.

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

llvm-svn: 348442
2018-12-06 01:05:54 +00:00
Leonard Chan bf5fe2dbba [Sema] Push and Pop Expression Evaluation Context Records at the start and end of function definitions
This patch creates a new context for every function definition we enter.
Currently we do not push and pop on these, usually working off of the global
context record added in the Sema constructor, which never gets popped.

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

llvm-svn: 348434
2018-12-06 00:10:36 +00:00
Krzysztof Parzyszek 2a0c7c9c30 [Hexagon] Add intrinsics for Hexagon V66
llvm-svn: 348419
2018-12-05 22:03:04 +00:00
Krzysztof Parzyszek 85393b28f9 [Hexagon] Add support for Hexagon V66
llvm-svn: 348415
2018-12-05 21:38:35 +00:00
Stephen Kelly d8744a7e9f NFC: Extract TextNodeDumper class
Summary:
Start by moving some utilities to it. It will eventually house dumping
of individual nodes (after indentation etc has already been accounted
for).

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 348412
2018-12-05 21:12:39 +00:00