Commit Graph

50153 Commits

Author SHA1 Message Date
Artem Dergachev 3da7205114 [analyzer] NFC: Assert that our fix for noreturn destructors keeps working.
Massive false positives were known to be caused by continuing the analysis
after a destructor with a noreturn attribute has been executed in the program
but not modeled in the analyzer due to being missing in the CFG.

Now that work is being done on enabling the modeling of temporary constructors
and destructors in the CFG, we need to make sure that the heuristic that
suppresses these false positives keeps working when such modeling is disabled.
In particular, different code paths open up when the corresponding constructor
is being inlined during analysis.

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

llvm-svn: 324802
2018-02-10 03:14:22 +00:00
Artem Dergachev afb158c207 [analyzer] NFC: Use CFG construction contexts instead of homemade lookahead.
The analyzer was relying on peeking the next CFG element during analysis
whenever it was trying to figure out what object is being constructed
by a given constructor. This information is now available in the current CFG
element in all cases that were previously supported by the analyzer,
so no complicated lookahead is necessary anymore.

No functional change intended - the context in the CFG should for now be
available if and only if it was previously discoverable via CFG lookahead.

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

llvm-svn: 324800
2018-02-10 02:55:08 +00:00
Artem Dergachev 08225bbed4 [CFG] Provide construction contexts when constructors have cleanups.
Now that we make it possible to query the CFG constructor element to find
information about the construction site, possible cleanup work represented by
ExprWithCleanups should not prevent us from providing this information.

This allows us to have a correct construction context for variables initialized
"by value" via elidable copy-constructors, such as 'i' in

  iterator i = vector.begin();

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

llvm-svn: 324798
2018-02-10 02:46:14 +00:00
Artem Dergachev 5a281bba40 [CFG] Add construction context for constructor initializers.
CFG elements for constructors of fields and base classes that are being
initialized before the body of the whole-class constructor starts can now be
queried to discover that they're indeed participating in initialization of their
respective fields or bases before the whole-class constructor kicks in.

CFG construction contexts are now capable of representing CXXCtorInitializer
triggers, which aren't considered to be statements in the Clang AST.

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

llvm-svn: 324796
2018-02-10 02:18:04 +00:00
Artem Dergachev 5fc10337a2 [CFG] Add construction context for simple variable declarations.
Constructors of simple variables now can be queried to discover that they're
constructing into simple variables.

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

llvm-svn: 324794
2018-02-10 01:55:23 +00:00
George Karpenkov 5a755b333d [analyzer] Serialize statistics to plist when serialize-stats=true is set
Differential Revision: https://reviews.llvm.org/D43131

llvm-svn: 324793
2018-02-10 01:49:20 +00:00
Artem Dergachev 4b0d160a09 [analyzer] Add missing pre-post-statement callbacks for OffsetOfExpr.
This expression may or may not be evaluated in compile time, so tracking the
result symbol is of potential interest. However, run-time offsetof is not yet
supported by the analyzer, so for now this callback is only there to assist
future implementation.

Patch by Henry Wong!

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

llvm-svn: 324790
2018-02-10 00:55:49 +00:00
Artem Dergachev f3e09bdaee [analyzer] Add support for __builtin_constant_p.
This builtin is evaluated in compile time. But in the analyzer we don't yet
automagically evaluate all calls that can be evaluated in compile time.

Patch by Felix Kostenzer!

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

llvm-svn: 324789
2018-02-10 00:51:47 +00:00
George Karpenkov 2a639858be [analyzer] Introduce statistics for the total number of visited basic blocks
Differential Revision: https://reviews.llvm.org/D43133

llvm-svn: 324785
2018-02-09 23:37:47 +00:00
George Karpenkov 441e8fdf94 [NFC] Extract method to SourceManager for traversing the macro "stack"
The code for going up the macro arg expansion is duplicated in many
places (and we need it for the analyzer as well, so I did not want to
duplicate it two more times).

This patch is an NFC, so the semantics should remain the same.

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

llvm-svn: 324780
2018-02-09 23:30:07 +00:00
Matt Davis 2930d7662e [CodeGen] Use the zero initializer instead of storing an all zero representation.
Summary:
This change avoids the overhead of storing, and later crawling,
an initializer list of all zeros for arrays. When LLVM
visits this (llvm/IR/Constants.cpp) ConstantArray::getImpl()
it will scan the list looking for an array of all zero.

We can avoid the store, and short-cut the scan, by detecting
all zeros when clang builds-up the initialization representation.

This was brought to my attention when investigating PR36030


Reviewers: majnemer, rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

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

llvm-svn: 324776
2018-02-09 22:10:09 +00:00
Adrian Prantl 70599030f8 Introduce an API for LLDB to compute the default module cache path
LLDB creates Clang modules and had an incomplete copy of the clang
Driver code that compute the -fmodule-cache-path. This patch makes the
clang driver code accessible to LLDB.

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

llvm-svn: 324761
2018-02-09 18:43:10 +00:00
Matt Arsenault e7da136a74 AMDGPU: Update for datalayout change
llvm-svn: 324748
2018-02-09 16:58:41 +00:00
Francois Ferrand 38d8013458 clang-format: keep ObjC colon alignment with short object name
Summary:
When the target object expression is short and the first selector name
is long, clang-format used to break the colon alignment:

  [I performSelectorOnMainThread:@selector(loadAccessories)
                       withObject:nil
                    waitUntilDone:false];

This happens because the colon is placed at `ContinuationIndent +
LongestObjCSelectorName`, so that any selector can be wrapped. This is
however not needed in case the longest selector is the firstone, and
not wrapped.

To overcome this, this patch does not include the first selector in
`LongestObjCSelectorName` computation (in TokenAnnotator), and lets
`ContinuationIndenter` decide how to account for the first selector
when wrapping. (Note this was already partly the case, see line 521
of ContinuationIndenter.cpp)

This way, the code gets properly aligned whenever possible without
breaking the continuation indent.

  [I performSelectorOnMainThread:@selector(loadAccessories)
                      withObject:nil
                   waitUntilDone:false];
  [I // force break
      performSelectorOnMainThread:@selector(loadAccessories)
                       withObject:nil
                    waitUntilDone:false];
  [I perform:@selector(loadAccessories)
      withSelectorOnMainThread:true
                 waitUntilDone:false];

Reviewers: krasimir, djasper, klimek

Subscribers: cfe-commits

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

llvm-svn: 324741
2018-02-09 15:41:56 +00:00
Andrew V. Tischenko 425f7b4894 Fif for an issue when Clang permits assignment to vector/extvector elements in a const method.
llvm-svn: 324721
2018-02-09 09:30:42 +00:00
Konstantin Zhuravlyov 76854e7daa AMDGPU/GCN: Bring processors in sync with AMDGPUUsage
- Remove gfx800
- Remove gfx804
- Remove gfx901
- Remove gfx903

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

llvm-svn: 324714
2018-02-09 07:02:28 +00:00
Saleem Abdulrasool bbce34a8dd AST: support ObjC lifetime qualifiers in MS ABI
Adjust the ObjC protocol conformance workaround to be more extensible.
Use a synthetic type for the protocol (`struct Protocol`).  Embed this
within a reserved namespace to permit extending the extended pointer
type qualifiers similarly for ObjC lifetime qualifiers.

Introduce additional special handling for `__autoreleasing`, `__strong`,
and `__weak` Objective C lifetime qualifiers.  We decorate these by
creating an artificial template type `Autoreleasing`, `Strong`, or
`Weak` in the `__ObjC` namespace.  These are only considered in the
template type specialization and not the function parameter.

llvm-svn: 324701
2018-02-09 03:23:54 +00:00
Artem Dergachev 675d6f4df2 [CFG] Squash an unused variable introduced in r324668.
Found by -Werror buildbot.

llvm-svn: 324697
2018-02-09 01:43:26 +00:00
Richard Smith 6c2b5a8ff0 [modules] Fix incorrect diagnostic mapping computation when a module changes
diagnostic settings using _Pragma within a macro.

The AST writer had previously been assuming that all diagnostic state
transitions would occur within a FileID corresponding to a file. When a
diagnostic state change occured within a macro, it was unable to form a
location for that state change and would instead corrupt the diagnostic state
of the "root" node (and thus that of the main compilation).

Also introduce a "#pragma clang __debug diag_mapping" debugging utility
that I added to track this issue down.

llvm-svn: 324695
2018-02-09 01:15:13 +00:00
Reid Kleckner b75a3f04ec [WinEH] Put funclet bundles on inline asm calls
Summary:
Fixes PR36247, which is where WinEHPrepare replaces inline asm in
funclets with unreachable.

Make getBundlesForFunclet return by value to simplify some call sites.

Reviewers: smeenai, majnemer

Subscribers: eraman, cfe-commits

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

llvm-svn: 324689
2018-02-09 00:16:41 +00:00
Erich Keane fa69c71dce Fix UBSan issue with PPC::isValidCPUName
Apparently storing the pointer to a StringLiteral as
a StringRef caused this section of code to issue a ubsan
warning.  This will hopefully fix that.

llvm-svn: 324687
2018-02-09 00:13:49 +00:00
Erich Keane 086331b4ff Add size to constexpr Arrays
What seems to be a bug in older versions of MSVC, constexpr
member arrays with a redefinition (to force emission) require
their initial definition to have the size between the brackets.

llvm-svn: 324682
2018-02-08 23:49:40 +00:00
Artem Dergachev 9849f595b9 [analyzer] MallocChecker: Fix one more bug category.
Even though most of the inconsistencies in MallocChecker's bug categories were
fixed in r302016, one more was introduced in r301913 which was later missed.

Patch by Henry Wong!

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

llvm-svn: 324680
2018-02-08 23:28:29 +00:00
Erich Keane e44bdb3f70 Add Rest of Targets Support to ValidCPUList (enabling march notes)
A followup to: https://reviews.llvm.org/D42978

Most of the rest of the Targets were pretty rote, so this
patch knocks them all out at once. 

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

llvm-svn: 324676
2018-02-08 23:16:55 +00:00
Erich Keane d45879d8ad Add NVPTX Support to ValidCPUList (enabling march notes)
A followup to: https://reviews.llvm.org/D42978
This patch adds NVPTX support for
enabling the march notes.

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

llvm-svn: 324675
2018-02-08 23:16:00 +00:00
Erich Keane d1d85f50d0 Add X86 Support to ValidCPUList (enabling march notes)
A followup to: https://reviews.llvm.org/D42978
This patch adds X86 and X86_64 support for
enabling the march notes.

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

llvm-svn: 324674
2018-02-08 23:15:02 +00:00
Erich Keane 3ec1743d0d Make march/target-cpu print a note with the list of valid values for ARM
When rejecting a march= or target-cpu command line parameter,
the message is quite lacking. This patch adds a note that prints
all possible values for the current target, if the target supports it.

This adds support for the ARM/AArch64 targets (more to come!). 

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

llvm-svn: 324673
2018-02-08 23:14:15 +00:00
Artem Dergachev 41ffb30716 [CFG] Add extra context to C++ constructor statement elements.
This patch adds a new CFGStmt sub-class, CFGConstructor, which replaces
the regular CFGStmt with CXXConstructExpr in it whenever the CFG has additional
information to provide regarding what sort of object is being constructed.

It is useful for figuring out what memory is initialized in client of the
CFG such as the Static Analyzer, which do not operate by recursive AST
traversal, but instead rely on the CFG to provide all the information when they
need it. Otherwise, the statement that triggers the construction and defines
what memory is being initialized would normally occur after the
construct-expression, and the client would need to peek to the next CFG element
or use statement parent map to understand the necessary facts about
the construct-expression.

As a proof of concept, CFGConstructors are added for new-expressions
and the respective test cases are provided to demonstrate how it works.

For now, the only additional data contained in the CFGConstructor element is
the "trigger statement", such as new-expression, which is the parent of the
constructor. It will be significantly expanded in later commits. The additional
data is organized as an auxiliary structure - the "construction context",
which is allocated separately from the CFGElement.

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

llvm-svn: 324668
2018-02-08 22:58:15 +00:00
Artem Dergachev af84ce162c [analyzer] Self-debug: Dump the core's internal state traits to the egraph.
It is useful for debugging problems with C++ operator new() or temporaries.

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

llvm-svn: 324663
2018-02-08 22:32:38 +00:00
Artem Dergachev be07303569 [analyzer] Self-debug: Dump environment frame-by-frame.
It makes it easier to discriminate between values of similar expressions
in different stack frames.

It also makes the separate backtrace section in ExplodedGraph dumps redundant.

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

llvm-svn: 324660
2018-02-08 22:24:38 +00:00
Alex Lorenz 692821afec PR36307: Consume the #pragma options align annotation token after
semantic analysis to prevent incorrect -Wpragma-pack warning for an included
file

rdar://37354951

llvm-svn: 324651
2018-02-08 21:20:43 +00:00
Craig Topper c0b2e982d9 [X86] Replace kortest intrinsics with native IR.
llvm-svn: 324647
2018-02-08 20:16:17 +00:00
Erich Keane 30994d2448 Fix improper indentation issue in CodeGenModule [NFC]
llvm-svn: 324644
2018-02-08 20:04:22 +00:00
Matt Arsenault 935574a490 Fix crash on array initializer with non-0 alloca addrspace
llvm-svn: 324641
2018-02-08 19:37:09 +00:00
Ben Hamilton 09051f2925 [clang-format] Do not break Objective-C string literals inside array literals
Summary:
Concatenating Objective-C string literals inside an array literal
raises the warning -Wobjc-string-concatenation (which is enabled by default).

clang-format currently splits and concatenates string literals like
the following:

  NSArray *myArray = @[ @"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ];

into:

  NSArray *myArray =
        @[ @"aaaaaaaaaaaaaaaaaaaaaaaaaaaa"
           @"aaaaaaaaa" ];

which raises the warning. This is https://bugs.llvm.org/show_bug.cgi?id=36153 .

The options I can think of to fix this are:

1) Have clang-format disable Wobjc-string-concatenation by emitting
pragmas around the formatted code
2) Have clang-format wrap the string literals in a macro (which
disables the warning)
3) Disable string splitting for Objective-C string literals inside
array literals

I think 1) has no precedent, and I couldn't find a good
identity() macro for 2). So, this diff implements 3).

Test Plan: make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: jolesiak, stephanemoore, djasper

Reviewed By: jolesiak

Subscribers: klimek, cfe-commits

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

llvm-svn: 324618
2018-02-08 16:07:25 +00:00
Jan Korous 3a98e51823 [Parser][FixIt] Better diagnostics for "typedef" instead of "typename" typo
rdar://problem/10214588

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

llvm-svn: 324607
2018-02-08 14:37:58 +00:00
Alexander Ivchenko 4b20b3c80c Fix for #31362 - ms_abi is implemented incorrectly for values >=16 bytes.
Summary:
This patch is a fix for following issue:
https://bugs.llvm.org/show_bug.cgi?id=31362 The problem was caused by front end
lowering C calling conventions without taking into account calling conventions
enforced by attribute. In this case win64cc was no correctly lowered on targets
other than Windows.

Reviewed By: rnk (Reid Kleckner)

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

Author: belickim <mateusz.belicki@intel.com>
llvm-svn: 324594
2018-02-08 11:15:21 +00:00
Krasimir Georgiev 374e6de8e0 [clang-format] Do not break before long string literals in protos
Summary:
This patch is a follow-up to r323319 (which disables string literal breaking for
text protos) and it disables breaking before long string literals.

For example this:
```
keyyyyy: "long string literal"
```
used to get broken into:
```
keyyyyy:
    "long string literal"
```

While at it, I also enabled it for LK_Proto and fixed a bug in the mustBreak code.

Reviewers: djasper, sammccall

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 324591
2018-02-08 10:47:12 +00:00
Ben Hamilton 3a47fddfd3 [clang-format] Set ObjCBinPackProtocolList to Never for google style
Summary:
This is split off from D42650, and sets ObjCBinPackProtocolList
to Never for the google style.

Depends On D42650

Test Plan: New tests added. make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: krasimir, jolesiak, stephanemoore

Reviewed By: krasimir, jolesiak, stephanemoore

Subscribers: klimek, cfe-commits, hokein, Wizard

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

llvm-svn: 324553
2018-02-08 01:49:10 +00:00
Erich Keane 9176f669b4 [NFCi] Replace a couple of usages of const StringRef& with StringRef
No sense passing these by reference when a copy is about as free, and
saves on potential indirection later.

llvm-svn: 324540
2018-02-07 23:04:38 +00:00
Rafael Espindola 75e5736926 Don't try to use copy relocations with tls variables.
Should fix the lldb bot.

llvm-svn: 324539
2018-02-07 23:04:06 +00:00
Richard Smith f3b4ca89e7 PR36055: fix computation of *-dependence in nested initializer lists.
When we synthesize an implicit inner initializer list when analyzing an outer
initializer list, we add it to the outer list immediately, and then fill in the
inner list. This gives the outer list no chance to update its *-dependence bits
with those of the completed inner list. To fix this, re-add the inner list to
the outer list once it's completed.

Note that we do not recompute the *-dependence bits from scratch when we
complete an outer list; this would give the wrong result for the case where a
designated initializer overwrites a dependent initializer with a non-dependent
one. The resulting list in that case should still be dependent, even though all
traces of the dependence were removed from the semantic form.

llvm-svn: 324537
2018-02-07 22:25:16 +00:00
Rafael Espindola 699f5d6bbc Recommit r324107 again.
The difference from the previous try is that we no longer directly
access function declarations from position independent executables. It
should work, but currently doesn't with some linkers.

It now includes a fix to not mark available_externally definitions as
dso_local.

Original message:

Start setting dso_local in clang.

This starts adding dso_local to clang.

The hope is to eventually have TargetMachine::shouldAssumeDsoLocal go
away. My objective for now is to move enough of it to clang to remove
the need for the TargetMachine one to handle PIE copy relocations and
-fno-plt. With that it should then be easy to implement a
-fno-copy-reloc in clang.

This patch just adds the cases where we assume a symbol to be local
based on the file being compiled for an executable or a shared
library.

llvm-svn: 324535
2018-02-07 22:15:33 +00:00
Alex Lorenz b57409f2b6 [PR36008] Avoid -Wsign-compare warning for enum constants in
typeof expressions

This commit looks through typeof type at the original expression when diagnosing
-Wsign-compare to avoid an unfriendly diagnostic.

rdar://36588828

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

llvm-svn: 324514
2018-02-07 20:45:39 +00:00
Momchil Velikov cd0ac25124 Revert [DebugInfo] Improvements to representation of enumeration types (PR36168)"
Revert due to breaking buildbots (LLDB tests)

llvm-svn: 324508
2018-02-07 19:57:04 +00:00
George Karpenkov 46163786e5 [analyzer] [NFC] Factor out generating path diagnostics for a statement into a function
Differential Revision: https://reviews.llvm.org/D42558

llvm-svn: 324507
2018-02-07 19:56:52 +00:00
Rafael Espindola 880c3b24c5 Revert "Recommit r324107."
This reverts commit r324500.

The bots found two failures:

    ThreadSanitizer-x86_64 :: Linux/pie_no_aslr.cc
    ThreadSanitizer-x86_64 :: pie_test.cc

when using gold. The issue is a limitation in gold when building pie
binaries. I will investigate how to work around it.

llvm-svn: 324505
2018-02-07 19:44:15 +00:00
Eric Fiselier cca7dddcd3 Fix r324498: the commit removed the '-' before the disable-llvm-verifier flag
llvm-svn: 324501
2018-02-07 19:17:03 +00:00
Rafael Espindola fa9874c33b Recommit r324107.
It now includes a fix to not mark available_externally definitions as
dso_local.

Original message:

Start setting dso_local in clang.

This starts adding dso_local to clang.

The hope is to eventually have TargetMachine::shouldAssumeDsoLocal go
away. My objective for now is to move enough of it to clang to remove
the need for the TargetMachine one to handle PIE copy relocations and
-fno-plt. With that it should then be easy to implement a
-fno-copy-reloc in clang.

This patch just adds the cases where we assume a symbol to be local
based on the file being compiled for an executable or a shared
library.

llvm-svn: 324500
2018-02-07 19:16:49 +00:00
Rafael Espindola deb10becf3 Don't pass ForDefinition_t in places it is redundant.
I found this while looking at the ppc failures caused by the dso_local
change.

The issue was that the patch would produce the wrong answer for
available_externally. Having ForDefinition_t available in places where
the code can just check the linkage is a bit of a foot gun.

This patch removes the ForDefiniton_t argument in places where the
linkage is already know.

llvm-svn: 324499
2018-02-07 19:04:41 +00:00