3862 Commits

Author SHA1 Message Date
Craig Topper
b88b480640 [RISCV] Remove Type::isRVVType() and replace with isRVVSizelessBuiltinType(). NFC
These both do the same thing, but some profiling on a
Releast+Asserts build suggests isRVVSizelessBuiltinType() is the
more efficient version so lets keep that one.
2023-12-08 18:44:26 -08:00
Ziqing Luo
a341e177ce
Thread safety analysis: Fix a bug in handling temporary constructors (#74020)
Extends the lifetime of the map `ConstructedObjects` to be of the
whole CFG so that the map can connect temporary Ctor and Dtor in
different CFG blocks.
2023-12-08 10:29:37 -08:00
Kazu Hirata
46a5693125 [FlowSensitive] Fix warnings
This patch fixes:

  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp:376:22: error:
  comparison of integers of different signs: 'unsigned int' and
  'TokenInfo::(unnamed enum at
  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp:356:7)'
  [-Werror,-Wsign-compare]

  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp:385:23: error:
  comparison of integers of different signs: 'unsigned int' and
  'TokenInfo::(unnamed enum at
  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp:356:7)'
  [-Werror,-Wsign-compare]

etc
2023-12-08 07:56:45 -08:00
Aaron Ballman
11dfb3cb32 Work around an ICE in MSVC; NFC 2023-12-08 10:20:31 -05:00
Samira Bazuzi
40381d1264
[clang][dataflow] Re-land: Retrieve members from accessors called usi… (#74336)
…ng member pointers.

This initially landed with a broken test due to a mid-air collision with
a new requirement for Environment initialization before field modeling.
Have added that initialization in the test.

From first landing:

getMethodDecl does not handle pointers to members and returns nullptr
for them. getMethodDecl contains a decade-plus-old FIXME to handle
pointers to members, but two approaches I looked at for fixing it are
more invasive or complex than simply swapping to getCalleeDecl.

The first, have getMethodDecl call getCalleeDecl, creates a large tree
of const-ness mismatches due to getMethodDecl returning a non-const
value while being a const member function and getCalleeDecl only being a
const member function when it returns a const value.

The second, implementing an AST walk to match how
CXXMemberCallExpr::getImplicitObjectArgument grabs the LHS of the binary
operator, is basically reimplementing Expr::getReferencedDeclOfCallee,
which is used by Expr::getCalleeDecl. We don't need another copy of that
code.
2023-12-05 12:09:33 +01:00
martinboehme
3b6d63c519
Revert "[clang][dataflow] Retrieve members from accessors called using member…" (#74299)
Reverts llvm/llvm-project#73978
2023-12-04 11:27:31 +01:00
Samira Bazuzi
a3fe9cb24d
[clang][dataflow] Retrieve members from accessors called using member… (#73978)
… pointers.

getMethodDecl does not handle pointers to members and returns nullptr
for them. getMethodDecl contains a decade-plus-old FIXME to handle
pointers to members, but two approaches I looked at for fixing it are
more invasive or complex than simply swapping to getCalleeDecl.

The first, have getMethodDecl call getCalleeDecl, creates a large tree
of const-ness mismatches due to getMethodDecl returning a non-const
value while being a const member function and getCalleeDecl only being a
const member function when it returns a const value.

The second, implementing an AST walk to match how
CXXMemberCallExpr::getImplicitObjectArgument grabs the LHS of the binary
operator, is basically reimplementing Expr::getReferencedDeclOfCallee,
which is used by Expr::getCalleeDecl. We don't need another copy of that
code.
2023-12-04 10:10:07 +01:00
martinboehme
71f2ec2db1
[clang][dataflow] Add synthetic fields to RecordStorageLocation (#73860)
Synthetic fields are intended to model the internal state of a class
(e.g. the value stored in a `std::optional`) without having to depend on
that class's implementation details.

Today, this is typically done with properties on `RecordValue`s, but
these have several drawbacks:

* Care must be taken to call `refreshRecordValue()` before modifying a
property so that the modified property values aren’t seen by other
environments that may have access to the same `RecordValue`.

* Properties aren’t associated with a storage location. If an analysis
needs to associate a location with the value stored in a property (e.g.
to model the reference returned by `std::optional::value()`), it needs
to manually add an indirection using a `PointerValue`. (See for example
the way this is done in UncheckedOptionalAccessModel.cpp, specifically
in `maybeInitializeOptionalValueMember()`.)

* Properties don’t participate in the builtin compare, join, and widen
operations. If an analysis needs to apply these operations to
properties, it needs to override the corresponding methods of
`ValueModel`.

* Longer-term, we plan to eliminate `RecordValue`, as by-value
operations on records aren’t really “a thing” in C++ (see
https://discourse.llvm.org/t/70086#changed-structvalue-api-14). This
would obviously eliminate the ability to set properties on
`RecordValue`s.

To demonstrate the advantages of synthetic fields, this patch converts
UncheckedOptionalAccessModel.cpp to synthetic fields. This greatly
simplifies the implementation of the check.

This PR is pretty big; to make it easier to review, I have broken it
down into a stack of three commits, each of which contains a set of
logically related changes. I considered submitting each of these as a
separate PR, but the commits only really make sense when taken together.

To review, I suggest first looking at the changes in
UncheckedOptionalAccessModel.cpp. This gives a flavor for how the
various API changes work together in the context of an analysis. Then,
review the rest of the changes.
2023-12-04 09:29:22 +01:00
martinboehme
5bd643e145
[clang][dataflow] Strengthen widening of boolean values. (#73484)
Before we widen to top, we now check if both values can be proved either
true or
false in their respective environments; if so, widening returns a true
or false
literal. The idea is that we avoid losing information if posssible.

This patch includes a test that fails without this change to widening.

This change does mean that we call the SAT solver in more places, but
this seems
acceptable given the additional precision we gain.

In tests on an internal codebase, the number of SAT solver timeouts we
observe
with Crubit's nullability checker does increase by about 25%. They can
be
brought back to the previous level by doubling the SAT solver work
limit.
2023-11-27 14:55:49 +01:00
martinboehme
c4c59192e6
[clang][dataflow] Clear ExprToLoc and ExprToVal at the start of a block. (#72985)
We never need to access entries from these maps outside of the current
basic
block. This could only ever become a consideration when flow control
happens
inside a full-expression (i.e. we have multiple basic blocks for a full
expression); there are two kinds of expression where this can happen,
but we
already deal with these in other ways:

* Short-circuiting logical operators (`&&` and `||`) have operands that
live in
different basic blocks than the operator itself, but we already have
code in
the framework to retrieve the value of these operands from the
environment
for the block they are computed in, rather than in the environment of
the
   block containing the operator.

* The conditional operator similarly has operands that live in different
basic
blocks. However, we currently don't implement a transfer function for
the
conditional operator. When we do this, we need to retrieve the values of
the
operands from the environments of the basic blocks they live in, as we
already do for logical operators. This patch adds a comment to this
effect
   to the code.

Clearing out `ExprToLoc` and `ExprToVal` has two benefits:

* We avoid performing joins on boolean expressions contained in
`ExprToVal` and
hence extending the flow condition in cases where this is not needed.
Simpler
flow conditions should reduce the amount of work we do in the SAT
solver.

* Debugging becomes easier when flow conditions are simpler and
`ExprToLoc` /
  `ExprToVal` don’t contain any extraneous entries.

Benchmark results on Crubit's `pointer_nullability_analysis_benchmark
show a
slight runtime increase for simple benchmarks, offset by substantial
runtime
reductions for more complex benchmarks:

```
name                              old cpu/op   new cpu/op   delta
BM_PointerAnalysisCopyPointer     29.8µs ± 1%  29.9µs ± 4%     ~     (p=0.879 n=46+49)
BM_PointerAnalysisIntLoop          101µs ± 3%   104µs ± 4%   +2.96%  (p=0.000 n=55+57)
BM_PointerAnalysisPointerLoop      378µs ± 3%   245µs ± 3%  -35.09%  (p=0.000 n=47+55)
BM_PointerAnalysisBranch           118µs ± 2%   122µs ± 3%   +3.37%  (p=0.000 n=59+59)
BM_PointerAnalysisLoopAndBranch    779µs ± 3%   413µs ± 5%  -47.01%  (p=0.000 n=56+45)
BM_PointerAnalysisTwoLoops         187µs ± 3%   192µs ± 5%   +2.80%  (p=0.000 n=57+58)
BM_PointerAnalysisJoinFilePath    17.4ms ± 3%   7.2ms ± 3%  -58.75%  (p=0.000 n=58+57)
BM_PointerAnalysisCallInLoop      14.7ms ± 4%  10.3ms ± 2%  -29.87%  (p=0.000 n=56+58)
```
2023-11-22 16:34:24 +01:00
Julian Schmidt
a3d76b3fa3
[clang-tidy] fix match for binaryOperator in ExprMutationAnalyzer for misc-const-correctness (#70559)
The `ExprMutationAnalyzer`s matcher of `binaryOperator`s
that contained the variable expr, were previously narrowing the
variable to be type dependent, when the `binaryOperator` should
have been narrowed as dependent.
The variable we are trying to find mutations for does
not need to be the dependent type, the other operand of
the `binaryOperator` could be dependent.

Fixes #57297
2023-11-14 23:00:18 +01:00
Samira Bazuzi
3001d6ddaa
[clang][dataflow] Fix buggy assertion: Compare an unqualified type to an unqualified type. (#71573)
Includes crash-reproducing test case.

---------

Co-authored-by: martinboehme <mboehme@google.com>
2023-11-09 16:57:04 +01:00
Simon Pilgrim
8d72079077 Fix MSVC "not all control paths return a value" warning. NFC. 2023-11-08 10:45:20 +00:00
martinboehme
64ed4edca8
[clang][dataflow] Expand debug dumping of Values. (#71527) 2023-11-08 05:41:26 +01:00
martinboehme
a0700532dd
[clang][dataflow] Replace one remaining call to deprecated addToFlowCondition(). (#71547) 2023-11-08 05:32:04 +01:00
Aaron Ballman
24060db3a9 Silence diagnostics about not all control paths returning a value; NFC 2023-11-07 10:42:50 -05:00
Jie Fu
a737a33eb9 [clang][dataflow] Fix -Wrange-loop-construct in DataflowAnalysisContext.cpp (NFC)
/llvm-project/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp:247:10: note: use reference type 'const llvm::Sma
llVector<Atom> &' to prevent copying
    for (const llvm::SmallVector<Atom> Class : Info.EquivalentAtoms)
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                       &
1 error generated.
2023-11-07 22:32:11 +08:00
martinboehme
7c636728c0
[clang][dataflow] Simplify flow conditions displayed in HTMLLogger. (#70848)
This can make the flow condition significantly easier to interpret; see
below
for an example.

I had hoped that adding the simplification as a preprocessing step
before the
SAT solver (in `DataflowAnalysisContext::querySolver()`) would also
speed up SAT
solving and maybe even eliminate SAT solver timeouts, but in my testing,
this
actually turns out to be a pessimization. It appears that these
simplifications
are easy enough for the SAT solver to perform itself.

Nevertheless, the improvement in debugging alone makes this a worthwhile
change.

Example of flow condition output with these changes:

```
Flow condition token: V37
Constraints:
(V16 = (((V15 & (V19 = V12)) & V22) & V25))
(V15 = ((V12 & ((V14 = V9) | (V14 = V4))) & (V13 = V14)))
True atoms: (V0, V1, V2, V5, V6, V7, V29, V30, V32, V34, V35, V37)
False atoms: (V3, V8, V17)
Equivalent atoms:
(V11, V15)

Flow condition constraints before simplification:
V37
((!V3 & !V8) & !V17)
(V37 = V34)
(V34 = (V29 & (V35 = V30)))
(V29 = (((V16 | V2) & V32) & (V30 = V32)))
(V16 = (((V15 & (V19 = V12)) & V22) & V25))
(V15 = V11)
(V11 = ((((V7 | V2) & V12) & ((V7 & (V14 = V9)) | (V2 & (V14 = V4)))) & (V13 = V14)))
(V2 = V1)
(V1 = V0)
V0
(V7 = V6)
(V6 = V5)
(V5 = V2)
```
2023-11-07 15:18:34 +01:00
martinboehme
6b573f4611
[clang][dataflow] Fix assert-fail when calling assignment operator with by-value parameter. (#71384)
The code assumed that the source parameter of an assignment operator is
always
passed by reference, but it is legal for it to be passed by value.

This patch includes a test that assert-fails without the fix.
2023-11-07 09:48:40 +01:00
martinboehme
526c9b7e37
[clang][nullability] Use proves() and assume() instead of deprecated synonyms. (#70297) 2023-10-30 13:18:57 +01:00
martinboehme
d1f59544cf
[clang][dataflow] Add Environment::allows(). (#70046)
This allows querying whether, given the flow condition, a certain
formula still
has a solution (though it is not necessarily implied by the flow
condition, as
`flowConditionImplies()` would check).

This can be checked today, but only with a double negation, i.e. to
check
whether, given the flow condition, a formula F has a solution, you can
check
`!Env.flowConditionImplies(Arena.makeNot(F))`. The double negation makes
this
hard to reason about, and it would be nicer to have a way of directly
checking
this.

For consistency, this patch also renames `flowConditionImplies()` to
`proves()`;
the old name is kept around for compatibility but deprecated.
2023-10-25 16:02:22 +02:00
Kazu Hirata
f9306f6de3
[ADT] Rename llvm::erase_value to llvm::erase (NFC) (#70156)
C++20 comes with std::erase to erase a value from std::vector.  This
patch renames llvm::erase_value to llvm::erase for consistency with
C++20.

We could make llvm::erase more similar to std::erase by having it
return the number of elements removed, but I'm not doing that for now
because nobody seems to care about that in our code base.

Since there are only 50 occurrences of erase_value in our code base,
this patch replaces all of them with llvm::erase and deprecates
llvm::erase_value.
2023-10-24 23:03:13 -07:00
martinboehme
14b039c1dd
[clang][dataflow] Remove declToLocConsistent() assertion. (#69819)
As described [here](https://discourse.llvm.org/t/70086/6), there are
legitimate
non-bug scenarios where two `DeclToLoc` maps to be joined contain
different
storage locations for the same declaration. This patch also adds a test
containing an example of such a situation. (The test fails without the
other
changes in this patch.)

With the assertion removed, the existing logic in `intersectDenseMaps()`
will
remove the corresponding declaration from the joined DeclToLoc map.

We also remove `removeDecl()`'s precondition (that the declaration must
be
associated with a storage location) because this may no longer hold if
the
declaration was previously removed during a join, as described above.
2023-10-24 08:42:30 +02:00
martinboehme
3eed23d31c
[clang][dataflow] Remove DataflowAnalysisContext::flowConditionIsTautology(). (#69601)
It's only used in its own unit tests.
2023-10-23 08:18:12 +02:00
Qizhi Hu
14bc11a651
[clang][dataflow]Use cast_or_null instead of cast to prevent crash (#68510)
`getStorageLocation` may return `nullptr` and this will produce crash
when use `cast`, use `dyn_cast_or_null` instead. I test it locally using
[FTXUI](https://github.com/ArthurSonzogni/FTXUI) and it may be the cause
of issue [issue](https://github.com/llvm/llvm-project/issues/68412), but
I am not sure.

Co-authored-by: huqizhi <huqizhi@836744285@qq.com>
2023-10-21 09:39:30 +08:00
ziqingluo-90
a4323586fc [-Wunsafe-buffer-usage] Add AST info to the unclaimed DRE debug notes for analysis
- For a better understand of what the unsupported cases are, we add
  more information to the debug note---a string of ancestor AST nodes
  of the unclaimed DRE. For example, an unclaimed DRE p in an
  expression `*(p++)` will result in a string starting with
  `DRE ==> UnaryOperator(++) ==> Paren ==> UnaryOperator(*)`.

- To find out the most common patterns of those unsupported use cases,
  we add a simple script to build a prefix tree over those strings and
  count each prefix. The script reads input line by line, assumes a
  line is a list of words separated by `==>`s, and builds a prefix tree
  over those lists.

Reviewed by: t-rasmud (Rashmi Mudduluru), NoQ (Artem Dergachev)

Differential revision: https://reviews.llvm.org/D158561
2023-10-20 14:27:14 -07:00
Sam McCall
7338eb561c Reapply "[dataflow] use true/false literals in formulas, rather than variables"
This reverts commit 3353f7dd3d91c9b2b6a15ba9229bee53e0cb8196.

Fixed test bug (unspecified order of arg evaluation)
2023-10-19 11:34:08 +02:00
Clement Courbet
39427b1098
Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (#68572)
…… (#68394)"

The new warnings are now under a separate flag
`-Wthread-safety-reference-return`, which is on by default under
`-Wthread-safety-reference`.

- People can opt out via `-Wthread-safety-reference
-Wnothread-safety-reference-return`.
This reverts commit 859f2d032386632562521a99db20923217d98988.
2023-10-19 08:34:59 +02:00
Yitzhak Mandelbaum
342dca7528
[clang][dataflow] Check for backedges directly (instead of loop statements). (#68923)
Widen on backedge nodes, instead of nodes with a loop statement as
terminator.
This fixes #67834 and a precision loss from assignment in a loop
condition. The
commit contains tests for both of these issues.
2023-10-16 14:07:16 -04:00
martinboehme
e54b0bef53
[clang][dataflow] Various formatting tweaks to HTMLLogger. (#68392)
*  Ensure timeline entries don't have linebreaks by setting
   `min-width: max-content`.

* Give the timeline header some padding on the right so it doesn't run
into the
   "Function" header.

* Put some padding around the iteration choosers so they don't run into
each
   other.

* Eliminate the "Iteration" text from the iteration choosers, which took
up a
lot of space. It should be clear what these are without the "Iteration"
text. (This makes the above problem of iteration choosers running into
each
   other less likely, but also add the padding nonetheless.)

Before:


![html_logger_before](https://github.com/llvm/llvm-project/assets/29098113/b938360f-c943-4552-829f-7b4857260959)

After:


![html_logger_after](https://github.com/llvm/llvm-project/assets/29098113/fecf4eab-7992-4e7d-a6e1-451887b699ab)
2023-10-12 13:12:21 +02:00
Stanislav Gatev
52d0696355
[clang][dataflow] Add support for lambda captures (#68558)
This adds support for copy, ref, and this lambda captures to the core
framework and also adds relevant tests in UncheckedOptionalAccessTest.
2023-10-11 22:18:46 +02:00
Caroline Tice
859f2d0323 Revert "Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (#68394)"
This reverts commit cd184c866e0aad1f957910b8c7a94f98a2b21ceb.
2023-10-06 22:23:02 -07:00
Clement Courbet
cd184c866e
Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (#68394)
…. (#67776)"

Now that `scudo` issues have been fixed (#68273).

This reverts commit 462bdd5bf0861a27f451f7917802a954e2046bc7.
2023-10-06 10:50:08 +02:00
martinboehme
2be7c651c4
[clang][dataflow] HTML logger: Mark iterations that have converged. (#68204)
I've eliminated the `logText("Block converged")` call entirely because

a) These logs are associated with an individual `CFGElement`, while
convergence
   should be associated with a block, and

b) The log message was being associated with the wrong block:
`recordState()`
dumps all of the pending log messages, but `blockConverged()` is called
after
   the last `recordState()` call for a given block, so that the "Block
converged" log message was being associated with the first element of
the
   _next_ block to be processed.

Example:


![image](https://github.com/llvm/llvm-project/assets/29098113/6a19095c-2dbb-4771-9485-e8e45c9d26fb)
2023-10-04 13:47:24 +02:00
Corentin Jabot
af4751738d [C++] Implement "Deducing this" (P0847R7)
This patch implements P0847R7 (partially),
CWG2561 and CWG2653.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D140828
2023-10-02 14:33:02 +02:00
Clement Courbet
00f2d9b0eb
Revert "[clang analysis][thread-safety] Handle return-by-reference...… (#67795)
… (#67776)"

This detects issues in `scudo`. Reverting until these are fixed.

```
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/tsd.h:74:12: error: returning variable 'QuarantineCache' by reference requires holding mutex 'Mutex' exclusively [-Werror,-Wthread-safety-reference]
   74 |     return QuarantineCache;
      |            ^
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/combined.h:248:28: note: in instantiation of member function 'scudo::TSD<scudo::Allocator<scudo::DefaultConfig, &malloc_postinit>>::getQuarantineCache' requested here
  248 |     Quarantine.drain(&TSD->getQuarantineCache(),
      |                            ^
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/tsd.h:57:15: note: in instantiation of member function 'scudo::Allocator<scudo::DefaultConfig, &malloc_postinit>::commitBack' requested here
   57 |     Instance->commitBack(this);
      |               ^
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/tsd_exclusive.h:172:27: note: in instantiation of member function 'scudo::TSD<scudo::Allocator<scudo::DefaultConfig, &malloc_postinit>>::commitBack' requested here
  172 |   TSDRegistryT::ThreadTSD.commitBack(Instance);
      |                           ^
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/tsd_exclusive.h:33:46: note: in instantiation of function template specialization 'scudo::teardownThread<scudo::Allocator<scudo::DefaultConfig, &malloc_postinit>>' requested here
   33 |     CHECK_EQ(pthread_key_create(&PThreadKey, teardownThread<Allocator>), 0);
      |                                              ^
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/tsd_exclusive.h:42:5: note: in instantiation of member function 'scudo::TSDRegistryExT<scudo::Allocator<scudo::DefaultConfig, &malloc_postinit>>::init' requested here
   42 |     init(Instance); // Sets Initialized.
      |     ^
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/tsd_exclusive.h:130:5: note: in instantiation of member function 'scudo::TSDRegistryExT<scudo::Allocator<scudo::DefaultConfig, &malloc_postinit>>::initOnceMaybe' requested here
  130 |     initOnceMaybe(Instance);
      |     ^
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/tsd_exclusive.h:74:5: note: in instantiation of member function 'scudo::TSDRegistryExT<scudo::Allocator<scudo::DefaultConfig, &malloc_postinit>>::initThread' requested here
   74 |     initThread(Instance, MinimalInit);
      |     ^
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/combined.h:221:17: note: in instantiation of member function 'scudo::TSDRegistryExT<scudo::Allocator<scudo::DefaultConfig, &malloc_postinit>>::initThreadMaybe' requested here
  221 |     TSDRegistry.initThreadMaybe(this, MinimalInit);
      |                 ^
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/combined.h:790:5: note: in instantiation of member function 'scudo::Allocator<scudo::DefaultConfig, &malloc_postinit>::initThreadMaybe' requested here
  790 |     initThreadMaybe();
      |     ^
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c.inc:36:25: note: in instantiation of member function 'scudo::Allocator<scudo::DefaultConfig, &malloc_postinit>::canReturnNull' requested here
   36 |     if (SCUDO_ALLOCATOR.canReturnNull()) {
```

This reverts commit 6dd96d6e80e9b3679a6161c590c60e0e99549b89.
2023-09-29 14:13:53 +02:00
Clement Courbet
6dd96d6e80
[clang analysis][thread-safety] Handle return-by-reference... (#67776)
...of guarded variables, when the function is not marked as requiring
locks:

```
class Return {
  Mutex mu;
  Foo foo GUARDED_BY(mu);

  Foo &returns_ref_locked() {
    MutexLock lock(&mu);
    return foo;  // BAD
  }

  Foo &returns_ref_locks_required() SHARED_LOCKS_REQUIRED(mu) {
    return foo;  // OK
  }
};
```

Review on Phabricator: https://reviews.llvm.org/D153131
2023-09-29 13:11:04 +02:00
Clement Courbet
a0ea5a4af9
Reland "[clang analysis][NFCI] Preparatory work for D153131. (#67420)… (#67775)
…" (#67523)

Discussion in https://reviews.llvm.org/D153132.

This reverts commit f70377471c990aa567584ae429e77adc9a55491b.
2023-09-29 10:30:26 +02:00
Manna, Soumi
06c9cc7eaa [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto
Reviewed By: tahonermann

Differential Revision: https://reviews.llvm.org/D159474
2023-09-28 09:00:55 -07:00
martinboehme
53e3180b6e
[clang][dataflow] Show triangle in <details> element (#67655)
Also, change the mouse cursor into a pointer instead of a text cursor.

This makes it more discoverable that the element can be opened and
closed.
2023-09-28 14:50:51 +02:00
Martin Braenne
3214f7bf6c Revert "[clang][dataflow] Show triangle in <details> element. (#67431)"
This reverts commit fb933fc6d76de854cb9eadf984f8900b9304d347.

The commit broke buildbots due to non-ASCII characters in
HTMLLogger.css.
2023-09-28 09:07:20 +00:00
martinboehme
fb933fc6d7
[clang][dataflow] Show triangle in <details> element. (#67431)
Also, change the mouse cursor into a pointer instead of a text cursor.

This makes it more discoverable that the element can be opened and
closed.
2023-09-28 10:55:02 +02:00
martinboehme
3cbadc5cda
[clang][dataflow] Tweak styling of iteration tabs. (#67637)
- On non-selected tabs, set cursor to 'pointer' to indicate they're
clickable

- Selected tab shares the same background as the contents to emphasize
that it's
associated with that content. (Compare with Google Chrome or VS Code,
which do
  this similarly.)

- Hovered-over tab becomes slightly brighter to indicate that clicking
it will
  make it even brighter (again, Chrome does this in a similar way).

Example:


![image](https://github.com/llvm/llvm-project/assets/29098113/e588068d-edff-49a8-b468-09dbb3255c3e)

(Mouse cursor is over "Iteration 2", but unfortunately I couldn't get
the screenshot to include the cursor.)
2023-09-28 10:34:00 +02:00
martinboehme
977289e44e
[clang][dataflow] Remove buggy assertion. (#67311)
The assertion fails on the test
TransferTest.EvaluateBlockWithUnreachablePreds
(which I think, ironically, was introuced in the same patch as the
assertion).

This just wasn't obvious because the assertion is inside an `LLVM_DEBUG`
block
and is thus only executed if the command-line flag `-debug` is passed.
We don't
have any CI builds that do this, so it's almost guaranteed that
assertions like
this will start failing over time (if they ever passed in the first
place --
which I'm not sure about here).

It's not clear to me whether there's _some_ assertion we might be able
to make
here -- I've looked at this for a while but haven't been able to come up
with
anything obvious. For the time being, I think it's best to simply delete
the
assertion.
2023-09-27 09:58:49 +02:00
Clement Courbet
f70377471c
Revert "[clang analysis][NFCI] Preparatory work for D153131. (#67420)" (#67523)
There was a misunderstanding as to whether we wanted those base NFC
changes or not.

This reverts commit 166074eff2e9a5f79b791f1cc9b641a4e2968616.
2023-09-27 09:48:44 +02:00
Clement Courbet
166074eff2
[clang analysis][NFCI] Preparatory work for D153131. (#67420)
This was ported over from phabricator.

Review https://reviews.llvm.org/D153131.
2023-09-26 15:05:14 +02:00
martinboehme
9f276d4ddd
[clang][dataflow] Avoid putting an assertion in an LLVM_DEBUG block. (#67313)
`LLVM_DEBUG` blocks are only run if the `-debug` command line flag is
passed.
We don't do this in any of our CI builds, so the assertion has limited
value and
it's likely it will start failing over time.
2023-09-26 08:49:11 +02:00
martinboehme
834cb919b3
[clang][dataflow] Remove declarations from DeclToLoc when their lifetime ends. (#67300)
After https://reviews.llvm.org/D153273, we're now able to use
`CFGLifetimeEnds`
together with the other CFG options we use.
2023-09-26 08:41:09 +02:00
Congcong Cai
feb7b1914d
[clang-analysis]Fix false positive in mutation check when using pointer to member function (#66846)
Fixes: #66204
2023-09-26 07:40:15 +08:00
Douglas Yung
3353f7dd3d Revert "[dataflow] use true/false literals in formulas, rather than variables"
This reverts commit 36bd5bd888f193b70abf43a09bb4fc04cd2a2ff1.

This change is causing a test failure on several build bots:
- https://lab.llvm.org/buildbot/#/builders/139/builds/50255
- https://lab.llvm.org/buildbot/#/builders/216/builds/27735
- https://lab.llvm.org/buildbot/#/builders/247/builds/9334
2023-09-22 11:43:27 -07:00