Commit Graph

35765 Commits

Author SHA1 Message Date
Artem Dergachev 6c0b2ce1be [analyzer] MoveChecker: NFC: Remove the workaround for the "zombie symbols" bug.
The checker had extra code to clean up memory regions that were sticking around
in the checker without ever being cleaned up due to the bug that was fixed in
r347953. Because of that, if a region was moved from, then became dead,
and then reincarnated, there were false positives.

Why regions are even allowed to reincarnate is a separate story. Luckily, this
only happens for local regions that don't produce symbols when loaded from.

No functional change intended. The newly added test demonstrates that even
though no cleanup is necessary upon destructor calls, the early return
cannot be removed. It was not failing before the patch.

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

llvm-svn: 348208
2018-12-03 22:44:16 +00:00
Artem Dergachev 2c5945ca20 [analyzer] Rename MisusedMovedObjectChecker to MoveChecker
This follows the Static Analyzer's tradition to name checkers after
things in which they find bugs, not after bugs they find.

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

llvm-svn: 348201
2018-12-03 22:32:32 +00:00
Artem Dergachev ca3ace55dc [analyzer] Dump stable identifiers for objects under construction.
This continues the work that was started in r342313, which now gets applied to
object-under-construction tracking in C++. Makes it possible to debug
temporaries by dumping exploded graphs again.

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

llvm-svn: 348200
2018-12-03 22:23:21 +00:00
Artem Dergachev cf439eda2d Re-apply r347954 "[analyzer] Nullability: Don't detect post factum violation..."
Buildbot failures were caused by an unrelated UB that was introduced in r347943
and fixed in r347970.

Also the revision was incorrectly specified as r344580 during revert.

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

llvm-svn: 348188
2018-12-03 21:04:30 +00:00
Vedant Kumar 6b062cd694 [gcov/Darwin] Ensure external symbols are exported when using an export list
Make sure that symbols needed to implement runtime support for gcov are
exported when using an export list on Darwin.

Without the clang driver exporting these symbols, the linker hides them,
resulting in tapi verification failures.

rdar://45944768

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

llvm-svn: 348187
2018-12-03 20:53:58 +00:00
Aaron Ballman 64c8a2e312 Adding tests for -ast-dump; NFC.
This adds tests for struct and union declarations in C++.

llvm-svn: 348156
2018-12-03 18:00:31 +00:00
Adrian Prantl 40c04e4942 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: 348154
2018-12-03 17:55:27 +00:00
Pablo Barrio 1a6d6f053d [AArch64] Add command-line option for SSBS
Summary:
SSBS (Speculative Store Bypass Safe) is only mandatory from 8.5
onwards but is optional from Armv8.0-A. This patch adds testing for
the ssbs command line option, added to allow enabling the feature
in previous Armv8-A architectures to 8.5.

Reviewers: olista01, samparker, aemerson

Reviewed By: samparker

Subscribers: javed.absar, kristof.beyls, cfe-commits

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

llvm-svn: 348142
2018-12-03 14:40:37 +00:00
Ilya Biryukov f1822ec431 [CodeComplete] Cleanup access checking in code completion
Summary: Also fixes a crash (see the added 'accessibility-crash.cpp' test).

Reviewers: ioeric, kadircet

Reviewed By: kadircet

Subscribers: cfe-commits

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

llvm-svn: 348135
2018-12-03 13:29:17 +00:00
Ilya Biryukov 905a136fb1 [Analysis] Properly prepare test env in test/Analysis/undef-call.c
The test expectes the '%T/ctudir' to be present, but does not create it.

llvm-svn: 348124
2018-12-03 11:28:17 +00:00
Ilya Biryukov 378499d184 [clang] Do not read from 'test/SemaCXX/Inputs' inside 'test/AST'
Our integrate relies on test inputs being taken from the same diretory as the
test itself.

llvm-svn: 348123
2018-12-03 11:26:35 +00:00
Stephen Kelly e8e4f09add Fix whitespace
llvm-svn: 348094
2018-12-02 16:42:34 +00:00
Stephen Kelly 765e1a4472 Add dump tests for ArrayInitLoopExpr and ArrayInitIndexExpr
llvm-svn: 348093
2018-12-02 16:36:23 +00:00
Matt Arsenault 0ff50d49d1 OpenCL: Improve vector printf warnings
The vector modifier is considered separate, so
don't treat it as a conversion specifier.

This is still not warning on some cases, like
using a type that isn't a valid vector element.

Fixes bug 39652

llvm-svn: 348084
2018-12-01 22:16:27 +00:00
Matt Arsenault af07de4059 OpenCL: Extend argument promotion rules to vector types
The spec is ambiguous on whether vector types are allowed to be
implicitly converted. The only legal context I think this can
be used for OpenCL is printf, where it seems necessary.

llvm-svn: 348083
2018-12-01 21:56:10 +00:00
Bill Wendling 2a81f6670d Specify constant context in constant emitter
The constant emitter may need to evaluate the expression in a constant context.
For exasmple, global initializer lists.

llvm-svn: 348070
2018-12-01 08:29:36 +00:00
Adrian Prantl 33f0af35df Relax test to also work on Windows.
llvm-svn: 348062
2018-12-01 01:30:00 +00:00
Adrian Prantl bef4f92a3b Honor -fdebug-prefix-map when creating function names for the debug info.
This adds a callback to PrintingPolicy to allow CGDebugInfo to remap
file paths according to -fdebug-prefix-map. Otherwise the debug info
(particularly function names for C++ lambdas) may contain paths that
should have been remapped in the debug info.

<rdar://problem/46128056>

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

llvm-svn: 348060
2018-12-01 00:24:27 +00:00
Fangrui Song 407659ab0a Revert "Revert r347417 "Re-Reinstate 347294 with a fix for the failures.""
It seems the two failing tests can be simply fixed after r348037

Fix 3 cases in Analysis/builtin-functions.cpp
Delete the bad CodeGen/builtin-constant-p.c for now

llvm-svn: 348053
2018-11-30 23:41:18 +00:00
Kristof Umann f110a357ac [analyzer] Deleting unnecessary test file
That I really should've done in rC348031.

llvm-svn: 348044
2018-11-30 22:32:17 +00:00
Fangrui Song f5d3335d75 Revert r347417 "Re-Reinstate 347294 with a fix for the failures."
Kept the "indirect_builtin_constant_p" test case in test/SemaCXX/constant-expression-cxx1y.cpp
while we are investigating why the following snippet fails:

  extern char extern_var;
  struct { int a; } a = {__builtin_constant_p(extern_var)};

llvm-svn: 348039
2018-11-30 21:26:09 +00:00
Kristof Umann d1a4b06c20 [analyzer] Emit an error for invalid -analyzer-config inputs
Differential Revision: https://reviews.llvm.org/D53280

llvm-svn: 348038
2018-11-30 21:24:31 +00:00
Aaron Ballman 3b6fb6e846 Adding tests for -ast-dump; NFC.
This adds tests for struct and union declarations in C. It also points out a bug when dumping anonymous record types -- they are sometimes reported as being contained by something of the wrong tag type. e.g., an anonymous struct inside of a union named X reports the anonymous struct as being inside of 'struct X' rather than 'union X'.

llvm-svn: 348033
2018-11-30 20:55:26 +00:00
Bill Wendling 90a0563118 Revert r348029. I was git-ing and jumped the gun.
llvm-svn: 348032
2018-11-30 20:44:11 +00:00
Kristof Umann 549f9cd46f [analyzer] Evaluate all non-checker config options before analysis
In earlier patches regarding AnalyzerOptions, a lot of effort went into
gathering all config options, and changing the interface so that potential
misuse can be eliminited.

Up until this point, AnalyzerOptions only evaluated an option when it was
querried. For example, if we had a "-no-false-positives" flag, AnalyzerOptions
would store an Optional field for it that would be None up until somewhere in
the code until the flag's getter function is called.

However, now that we're confident that we've gathered all configs, we can
evaluate off of them before analysis, so we can emit a error on invalid input
even if that prticular flag will not matter in that particular run of the
analyzer. Another very big benefit of this is that debug.ConfigDumper will now
show the value of all configs every single time.

Also, almost all options related class have a similar interface, so uniformity
is also a benefit.

The implementation for errors on invalid input will be commited shorty.

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

llvm-svn: 348031
2018-11-30 20:44:00 +00:00
George Karpenkov be3f4bd36b Revert "Reverting r347949-r347951 because they broke the test bots."
This reverts commit 5bad6129c012fbf186eb055be49344e790448ecc.

Hopefully fixing the issue which was breaking the bots.

llvm-svn: 348030
2018-11-30 20:43:42 +00:00
Bill Wendling e64fe2abae We're in a constant context in the ConstantEmitter.
llvm-svn: 348029
2018-11-30 20:40:06 +00:00
Kristof Umann 5f9981f8a5 [analyzer][PlistMacroExpansion] Part 5.: Support for # and ##
From what I can see, this should be the last patch needed to replicate macro
argument expansions.

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

llvm-svn: 348025
2018-11-30 19:21:35 +00:00
Aaron Ballman e024c8b212 Updating this test, which changed after the reverts from r348020.
llvm-svn: 348023
2018-11-30 19:15:07 +00:00
Aaron Ballman cd5115b74d Reverting r347949-r347951 because they broke the test bots.
http://lab.llvm.org:8011/builders/clang-cmake-armv8-lld/builds/440/steps/ninja%20check%202/logs/FAIL%3A%20Clang%3A%3Aosobject-retain-release.cpp

llvm-svn: 348020
2018-11-30 18:52:51 +00:00
Aaron Ballman 4b5b0c0025 Move AST tests into their own test directory; NFC.
This moves everything primarily testing the functionality of -ast-dump and -ast-print into their own directory, rather than leaving the tests spread around the testing directory.

llvm-svn: 348017
2018-11-30 18:43:02 +00:00
Aaron Ballman e47b366900 Adding tests for -ast-dump; NFC.
This adds tests for GenericSelectionExpr; note that it points out a minor whitespace bug for selection expression cases.

llvm-svn: 348008
2018-11-30 17:19:06 +00:00
Aaron Ballman 7213cd14f5 Adding tests for -ast-dump; NFC.
This adds tests for DeclStmt and demonstrates that we don't create such an AST node for global declarations currently.

llvm-svn: 347996
2018-11-30 15:11:16 +00:00
Aaron Ballman 7278cc7d73 Adding tests for -ast-dump; NFC.
This adds tests for the majority of the functionality around FunctionDecl and CXXMethodDecl.

llvm-svn: 347994
2018-11-30 14:43:21 +00:00
Adam Balogh 471d0864df lyzer] [HOTFIX!] SValBuilder crash when `aggressive-binary-operation-simplification` enabled
During the review of D41938 a condition check with an early exit accidentally
slipped into a branch, leaving the other branch unprotected. This may result in
an assertion later on. This hotfix moves this contition check outside of the
branch.

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

llvm-svn: 347981
2018-11-30 10:37:44 +00:00
Artem Dergachev c076907384 Revert r344580 "[analyzer] Nullability: Don't detect post factum violation..."
Fails under ASan!

llvm-svn: 347956
2018-11-30 04:26:17 +00:00
Artem Dergachev 34d3576736 [analyzer] Nullability: Don't detect post factum violation on concrete values.
The checker suppresses warnings on paths on which a nonnull value is assumed
to be nullable. This probably deserves a warning, but it's a separate story.

Now, because dead symbol collection fires in pretty random moments,
there sometimes was a situation when dead symbol collection fired after
computing a parameter but before actually evaluating call enter into the
function, which triggered the suppression when the argument was null
in the first place earlier than the obvious warning for null-to-nonnull
was emitted, causing false negatives.

Only trigger the suppression for symbols, not for concrete values.

It is impossible to constrain a concrete value post-factum because
it is impossible to constrain a concrete value at all.

This covers all the necessary cases because by the time we reach the call,
symbolic values should be either not constrained to null, or already collapsed
into concrete null values. Which in turn happens because they are passed through
the Store, and the respective collapse is implemented as part of getSVal(),
which is also weird.

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

llvm-svn: 347954
2018-11-30 03:39:58 +00:00
Artem Dergachev bbc6d68297 [analyzer] Fix the "Zombie Symbols" bug.
It's an old bug that consists in stale references to symbols remaining in the
GDM if they disappear from other program state sections as a result of any
operation that isn't the actual dead symbol collection. The most common example
here is:

   FILE *fp = fopen("myfile.txt", "w");
   fp = 0; // leak of file descriptor

In this example the leak were not detected previously because the symbol
disappears from the public part of the program state due to evaluating
the assignment. For that reason the checker never receives a notification
that the symbol is dead, and never reports a leak.

This patch not only causes leak false negatives, but also a number of other
problems, including false positives on some checkers.

What's worse, even though the program state contains a finite number of symbols,
the set of symbols that dies is potentially infinite. This means that is
impossible to compute the set of all dead symbols to pass off to the checkers
for cleaning up their part of the GDM.

No longer compute the dead set at all. Disallow iterating over dead symbols.
Disallow querying if any symbols are dead. Remove the API for marking symbols
as dead, as it is no longer necessary. Update checkers accordingly.

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

llvm-svn: 347953
2018-11-30 03:27:50 +00:00
George Karpenkov 4908f9c0d0 [analyzer] Fixes after rebase.
llvm-svn: 347951
2018-11-30 02:19:29 +00:00
George Karpenkov 2620c60545 [analyzer] RetainCountChecker for OSObject model the "free" call
The "free" call frees the object immediately, ignoring the reference count.
Sadly, it is actually used in a few places, so we need to model it.

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

llvm-svn: 347950
2018-11-30 02:19:16 +00:00
George Karpenkov 2bd644ebbd [analyzer] RetainCountChecker: recognize that OSObject can be created directly using an operator "new"
Differential Revision: https://reviews.llvm.org/D55076

llvm-svn: 347949
2018-11-30 02:19:03 +00:00
George Karpenkov b43772d85c [analyzer] Switch retain count checker for OSObject to use OS_* attributes
Instead of generalized reference counting annotations.

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

llvm-svn: 347948
2018-11-30 02:18:50 +00:00
George Karpenkov 1657f36c7f [attributes] Add a family of OS_CONSUMED, OS_RETURNS and OS_RETURNS_RETAINED attributes
The addition adds three attributes for communicating ownership,
analogous to existing NS_ and CF_ attributes.
The attributes are meant to be used for communicating ownership of all
objects in XNU (Darwin kernel) and all of the kernel modules.
The ownership model there is very similar, but still different from the
Foundation model, so we think that introducing a new family of
attributes is appropriate.

The addition required a sizeable refactoring of the existing code for
CF_ and NS_ ownership attributes, due to tight coupling and the fact
that differentiating between the types was previously done using a
boolean.

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

llvm-svn: 347947
2018-11-30 02:18:37 +00:00
George Karpenkov 62db886062 [analyzer] [NFC] Minor refactoring of RetainCountDiagnostics
Move visitors to the implementation file, move a complicated logic into
a function.

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

llvm-svn: 347946
2018-11-30 02:18:23 +00:00
George Karpenkov 3bdbeb155b [analyzer] For OSObject, trust that functions starting with Get
(uppercase) are also getters.

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

llvm-svn: 347945
2018-11-30 02:18:10 +00:00
George Karpenkov e2f09542a5 [analyzer] Print a fully qualified name for functions in RetainCountChecker diagnostics
Attempt to get a fully qualified name from AST if an SVal corresponding
to the object is not available.

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

llvm-svn: 347944
2018-11-30 02:17:57 +00:00
George Karpenkov f893ea1592 [analyzer] Add the type of the leaked object to the diagnostic message
If the object is a temporary, and there is no variable it binds to,
let's at least print out the object name in order to help differentiate
it from other temporaries.

rdar://45175098

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

llvm-svn: 347943
2018-11-30 02:17:44 +00:00
George Karpenkov a1c3bb88ee [analyzer] Reference leaked object by name, even if it was created in an inlined function.
rdar://45532181

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

llvm-svn: 347942
2018-11-30 02:17:31 +00:00
George Karpenkov 58c3837ee3 [analyzer] [NFC] Test dumping trimmed graph
Differential Revision: https://reviews.llvm.org/D54972

llvm-svn: 347941
2018-11-30 02:17:18 +00:00
Adrian Prantl 55fcb4e90e [-gmodules] Honor -fdebug-prefix-map in the debug info inside PCMs.
This patch passes -fdebug-prefix-map (a feature for renaming source
paths in the debug info) through to the per-module codegen options and
adds the debug prefix map to the module hash.

<rdar://problem/46045865>

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

llvm-svn: 347926
2018-11-29 22:33:09 +00:00