3827 Commits

Author SHA1 Message Date
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
Sam McCall
36bd5bd888 [dataflow] use true/false literals in formulas, rather than variables
And simplify formulas containing true/false
It's unclear to me how useful this is, it does make formulas more
conveniently self-contained now (we can usefully print them without
carrying around the "true/false" labels)

(while here, simplify !!X to X, too)

Differential Revision: https://reviews.llvm.org/D153485
2023-09-22 17:12:20 +02:00
Sam McCall
3f78d6ab14
[dataflow] Parse formulas from text (#66424)
My immediate use for this is not in checked-in code, but rather the
ability to plug printed flow conditions (from analysis logs) back into
sat solver unittests to reproduce slowness.

It does allow simplifying some of the existing solver tests, though.
2023-09-22 11:24:24 +02:00
Ziqing Luo
700baeb765 [-Wunsafe-buffer-usage] Use Strategy to determine whether to fix a parameter
- Use Strategy to determine whether to fix a parameter
- Fix the `Strategy` construction so that only variables on the graph
are assigned the `std::span` strategy

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

Differential revision: https://reviews.llvm.org/D157441
2023-09-21 15:06:22 -07:00
Ziqing Luo
33f6161d9e [-Wunsafe-buffer-usage] Group parameter fix-its
For a function `F` whose parameters need to be fixed, we group fix-its
of F's parameters together so that either all of the parameters get
fixed or none of them gets fixed.

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

Differential revision: https://reviews.llvm.org/D153059
2023-09-21 12:45:30 -07:00
martinboehme
ed65ced22a
[clang][dataflow] Identify post-visit state changes in the HTML logger. (#66746)
Previously, post-visit state changes were indistinguishable from
ordinary
iterations, which could give a confusing picture of how many iterations
a block
needs to converge.

Now, post-visit state changes are marked with "post-visit" instead of an
iteration number:


![screenshot](https://github.com/llvm/llvm-project/assets/29098113/5e9553d6-dfaa-45d3-8ea4-e623a14ee4c5))
2023-09-20 15:18:57 +02:00
martinboehme
a93e76dd87
[clang][dataflow] Reorder checks to protect against a null pointer dereference. (#66764)
I've received a report of a null pointer dereference happening on the
`LocDst->getType()` dereference. I wasn't unfortunately able to find a
repro,
but I'd argue the new version is better for the reduced indentation
alone.
2023-09-19 21:28:21 -07:00
Timm Bäder
cf8e189a99 [clang][TSA] Thread safety cleanup functions
Consider cleanup functions in thread safety analysis.

Differential Revision: https://reviews.llvm.org/D152504
2023-09-19 16:00:33 +02:00
Timm Bäder
ad4a513027 [clang][CFG] Cleanup functions
Add declarations declared with attribute(cleanup(...)) to the CFG,
similar to destructors.

Differential Revision: https://reviews.llvm.org/D157385
2023-09-19 11:56:44 +02:00
Clement Courbet
c809051215
[NFC] Preparatory work for D153131 (#66750) 2023-09-19 11:02:00 +02:00
martinboehme
1d7b59ca8d
[clang][dataflow] Fix two null pointer dereferences in getMemberForAccessor(). (#66742)
The additions to the test trigger crashes without the fixes.
2023-09-19 09:03:20 +02:00
Kinuko Yasuda
03be486ecc
[clang][dataflow] Model the fields that are accessed via inline accessors (#66368)
So that the values that are accessed via such accessors can be analyzed
as a limited version of context-sensitive analysis. We can potentially
do this only when some option is set, but doing additional modeling like
this won't be expensive and intrusive, so we do it by default for now.
2023-09-18 10:46:36 +02:00
Kinuko Yasuda
0612c9b09a
[clang][dataflow] Ignore assignment where base class's operator is used (#66364)
In C++ it seems it is legit to use base class's operator (e.g. `using
Base::operator=`) to perform copy if the base class is the common
ancestor of the source and destination object. In such a case we
shouldn't try to access fields beyond that of the base class, however
such a case seems to be very rare (typical code would implement a copy
constructor instead), and could add complexities, so in this patch we
simply bail if the method operator's parent class is different from the
type of the destination object that this framework recognizes.
2023-09-14 20:45:56 +02:00
Sam McCall
21ab252f97
[dataflow] Add global invariant condition to DataflowAnalysisContext (#65949)
This records facts that are not sensitive to the current flow condition,
and should apply to all environments.

The motivating case is recording information about where a Value
originated, such as nullability:
 - we may see the same Value for multiple expressions (e.g. reads of the
   same field) in multiple environments (multiple blocks or iterations)
 - we want to record information only when we first see the Value
   (e.g. Nullability annotations on fields only add information if we
   don't know where the value came from)
 - this information should be expressible as a SAT condition
 - we must add this SAT condition to every environment where the
   Value may appear

We solve this by recording the information in the global condition.
This doesn't seem particularly elegant, but solves the problem and is
a fairly small and natural extension of the Environment.

Alternatives considered:
 - store the constraint directly as a property on the Value.
   But it's more composable for such properties to always be variables
   (AtomicBoolValue), and constrain them with SAT conditions.
 - add a hook whenever values are created, giving the analysis the
   chance to populate them.
   However the framework relies on/provides the ability to construct
   values in arbitrary places without providing the context such a hook
   would need, this would be a very invasive change.
2023-09-14 19:30:04 +02:00
Artem Dergachev
8b8841e15a [analyzer] RetainRelease: Extend the workaround for VTCompressionSessionEncode{,MultiImage}Frame.
This is a new API that has the same ownership quirk as the old API.

This is a tiny one-liner patch; changes in plists are entirely about
line numbers.
2023-09-13 17:43:33 -07:00
Yitzhak Mandelbaum
004a7cea70
[clang][dataflow] Change diagnoseFunction to use llvm::SmallVector instead of std::vector. (#66014)
The template is agnostic as to the type used by the list, as long as it
is
compatible with `llvm::move` and `std::back_inserter`. In practice,
we've
encountered analyses which use different types (`llvm::SmallVector` vs
`std::vector`), so it seems preferable to leave this open to the caller.
2023-09-13 13:10:58 -04:00
Kinuko Yasuda
e791535b13
[clang][dataflow] Remove RecordValue.getLog() usage in HTMLLogger (#65645)
We can dump the same information from RecordStorageLocation.

Tested the behavior before and after patch, that generates the field
values in the HTML
in both cases (and also made sure that removing the relevant code makes
the field values
in the HTML go away)
2023-09-12 11:25:40 +02:00
martinboehme
7f66cc7d7a
[clang][dataflow] Merge RecordValues with different locations correctly. (#65319)
Now that prvalue expressions map directly to values (see
https://reviews.llvm.org/D158977), it's no longer guaranteed that
`RecordValue`s
associated with the same expression will always have the same storage
location.

In other words, D158977 invalidated the assertion in
`mergeDistinctValues()`.
The newly added test causes this assertion to fail without the other
changes in
the patch.

This patch fixes the issue. However, the real fix will be to eliminate
the
`StorageLocation` from `RecordValue` entirely.
2023-09-12 08:43:29 +02:00
martinboehme
2757085e90
[clang][dataflow][NFC] Delete unused function. (#65602)
I'm not sure why we had this originally, but the function seems to have
a pretty
onerous contract anyway for a function that is externally available, so
it seems
better not to keep it around.
2023-09-11 09:54:50 +02:00
Jan Svoboda
523c471250 Reapply "[clang] NFCI: Adopt SourceManager::getFileEntryRefForID()"
This reapplies ddbcc10b9e26b18f6a70e23d0611b9da75ffa52f, except for a tiny part that was reverted separately: 65331da0032ab4253a4bc0ddcb2da67664bd86a9. That will be reapplied later on, since it turned out to be more involved.

This commit is enabled by 5523fefb01c282c4cbcaf6314a9aaf658c6c145f and f0f548a65a215c450d956dbcedb03656449705b9, specifically the part that makes 'clang-tidy/checkers/misc/header-include-cycle.cpp' separator agnostic.
2023-09-08 19:04:01 -07:00
Kinuko Yasuda
8e1d2f2f12
[clang][dataflow] Don't crash when BlockToState is called from unreachable path (#65732)
When we call `getEnvironment`, `BlockToState[BlockId]` for the block can
return null even if CFCtx.isBlockReachable(B) returns true if it is
called from a particular block that is marked unreachable to the block.
2023-09-08 10:24:08 -04:00
Yitzhak Mandelbaum
80f0dc3aa4 [clang][dataflow] Unsoundly treat "Unknown" as "Equivalent" in widening.
This change makes widening act the same as equivalence checking. When the
analysis does not provide an answer regarding the equivalence of two distinct
values, the framework treats them as equivalent. This is an unsound choice that
enables convergence.

Differential Revision: https://reviews.llvm.org/D159355
2023-09-07 19:06:35 +00:00
Kinuko Yasuda
f9026cfb76 [clang][dataflow] Fix Record initialization with InitListExpr and inheritances
Usually RecordValues for record objects (e.g. struct) are initialized with
`Environment::createValue()` which internally calls `getObjectFields()` to
collects all fields from the current and base classes, and then filter them
with `ModeledValues` via `DACtx::getModeledFields()` so that the fields that
are actually referenced are modeled.

The consistent set of fields should be initialized when a record is initialized
with an initializer list (InitListExpr), however the existing code's behavior
was different.

Before this patch:
* When a struct is initialized with InitListExpr, its fields are
  initialized based on what is returned by `getFieldsForInitListExpr()`, which
  only collects the direct fields in the current class, but not from the base
  classes. Moreover, if the base classes have their own InitListExpr, values
  that are initialized by their InitListExpr's weren't merged into the
  child objects.

After this patch:
* When a struct is initialized with InitListExpr, it collects and merges the
  fields in the base classes that were initialized by their InitListExpr's.
  The code also asserts that the consistent set of fields are initialized
  with the ModeledFields.

Reviewed By: mboehme

Differential Revision: https://reviews.llvm.org/D159284
2023-09-07 07:37:50 +00:00
Jan Svoboda
0a9611fd8d Revert "[clang] NFCI: Adopt SourceManager::getFileEntryRefForID()"
This reverts commit ddbcc10b9e26b18f6a70e23d0611b9da75ffa52f.

The 'clang-tidy/checkers/misc/header-include-cycle.cpp' test started failing on Windows: https://lab.llvm.org/buildbot/#/builders/216/builds/26855.
2023-09-06 13:23:23 -07:00
Jan Svoboda
ddbcc10b9e [clang] NFCI: Adopt SourceManager::getFileEntryRefForID()
This commit replaces some calls to the deprecated `FileEntry::getName()` with `FileEntryRef::getName()` by swapping current usages of `SourceManager::getFileEntryForID()` with `SourceManager::getFileEntryRefForID()`. This lowers the number of usages of the deprecated `FileEntry::getName()` from 95 to 50.
2023-09-06 10:49:48 -07:00
martinboehme
c0703eaec1
[clang][dataflow] Emit an error if source code is not compiled as C++. (#65301)
The shape of certain elements of the AST can vary depending on the
langugage.
We currently only support C++.
2023-09-06 10:02:21 +02:00
Chris Bieneman
400d3261a0 [HLSL] Cleanup support for this as an l-value
The goal of this change is to clean up some of the code surrounding
HLSL using CXXThisExpr as a non-pointer l-value. This change cleans up
a bunch of assumptions and inconsistencies around how the type of
`this` is handled through the AST and code generation.

This change is be mostly NFC for HLSL, and completely NFC for other
language modes.

This change introduces a new member to query for the this object's type
and seeks to clarify the normal usages of the this type.

With the introudction of HLSL to clang, CXXThisExpr may now be an
l-value and behave like a reference type rather than C++'s normal
method of it being an r-value of pointer type.

With this change there are now three ways in which a caller might need
to query the type of `this`:

* The type of the `CXXThisExpr`
* The type of the object `this` referrs to
* The type of the implicit (or explicit) `this` argument

This change codifies those three ways you may need to query
respectively as:

* CXXMethodDecl::getThisType()
* CXXMethodDecl::getThisObjectType()
* CXXMethodDecl::getThisArgType()

This change then revisits all uses of `getThisType()`, and in cases
where the only use was to resolve the pointee type, it replaces the
call with `getThisObjectType()`. In other cases it evaluates whether
the desired returned type is the type of the `this` expr, or the type
of the `this` function argument. The `this` expr type is used for
creating additional expr AST nodes and for member lookup, while the
argument type is used mostly for code generation.

Additionally some cases that used `getThisType` in simple queries could
be substituted for `getThisObjectType`. Since `getThisType` is
implemented in terms of `getThisObjectType` calling the later should be
more efficient if the former isn't needed.

Reviewed By: aaron.ballman, bogner

Differential Revision: https://reviews.llvm.org/D159247
2023-09-05 19:38:50 -05:00
Jie Fu
5f667a57b5 [clang][dataflow] Fix -Wunused-const-variable in WatchedLiteralsSolver.cpp (NFC)
/data/llvm-project/clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:62:26: error: unused variable 'NullLit' [-Werror,-Wunused-const-variable]
static constexpr Literal NullLit = 0;
2023-09-05 15:03:07 +08:00
Burak Emir
b50c87d1e6 [clang][dataflow] #llvm #flow-analysis Simplify formula at CNF construction time, and short-cut solving of known contradictory formulas.
In dataflow analysis, SAT solver: simplify formula during CNF construction and short-cut
solving when the formula has been recognized as contradictory.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D158407
2023-09-05 06:23:04 +00:00
Martin Braenne
bf46b0b551 [clang][dataflow] Eliminate deprecated ControlFlowContext::build() overload.
Reviewed By: ymandel, xazax.hun

Differential Revision: https://reviews.llvm.org/D159262
2023-09-04 08:30:54 +00:00
Martin Braenne
266c12a1bd [clang][dataflow] When dumping ExprToVal, dump the Value, not just its location.
This makes `ExprToVal` dumping consistent with `LocToVal` dumping.

Reviewed By: ymandel, xazax.hun

Differential Revision: https://reviews.llvm.org/D159274
2023-09-04 07:38:33 +00:00
Martin Braenne
6eb1b237f5 [clang][dataflow][NFC] Remove obsolete references to ReferenceValue from comments.
`ReferenceValue` was removed in https://reviews.llvm.org/D155922.

Reviewed By: xazax.hun

Differential Revision: https://reviews.llvm.org/D159090
2023-08-30 06:55:40 +00:00
Elizabeth Andrews
39191c4577 [NFC][Clang] Fix static analyzer concerns
Fix static analyzer concerns about dereferencing null values.

Differential Revision: https://reviews.llvm.org/D157118
2023-08-29 12:23:26 -07:00
Martin Braenne
330d5bcbf6 [clang][dataflow] Don't associate prvalue expressions with storage locations.
Instead, map prvalue expressions directly to values in a newly introduced map `Environment::ExprToVal`.

This change introduces an additional member variable in `Environment` but is an overall win:

- It is more conceptually correctly, since prvalues don't have storage
  locations.

- It eliminates complexity from
  `Environment::setValue(const Expr &E, Value &Val)`.

- It reduces the amount of data stored in `Environment`: A prvalue now has a
  single entry in `ExprToVal` instead of one in `ExprToLoc` and one in
  `LocToVal`.

- Not allocating `StorageLocation`s for prvalues additionally reduces memory
  usage.

This patch is the last step in the migration to strict handling of value categories (see https://discourse.llvm.org/t/70086 for details). The changes here are almost entirely internal to `Environment`.

The only externally observable change is that when associating a `RecordValue` with the location returned by `Environment::getResultObjectLocation()` for a given expression, callers additionally need to associate the `RecordValue` with the expression themselves.

Reviewed By: xazax.hun

Differential Revision: https://reviews.llvm.org/D158977
2023-08-29 07:28:46 +00:00
Martin Braenne
aef05a1232 [clang][dataflow][NFC] Eliminate getStorageLocation() / setStorageLocation() in DataflowAnalysisContext.
Instead, inline them into the `getStableStorageLocation()` overloads, which is the only place they were called from (and should be called from).

`getStorageLocation()` / `setStorageLocation()` were confusing because neither their name nor their documentation made reference to the fact that the storage location is stable.

It didn't make sense to keep these as private member functions either. The code for the two `getStableStorageLocation()` overloads has become only marginally more complex by inlining these functions, and the `Expr` version is actually more efficient because we only call `ignoreCFGOmittedNodes()` once instead of twice.

Reviewed By: ymandel, xazax.hun

Differential Revision: https://reviews.llvm.org/D158981
2023-08-29 06:53:48 +00:00
Yitzhak Mandelbaum
824b136591 [clang][dataflow] Support range-for loops in fixpoint algorithm.
Adds support for recognizing range-for loops in the main algorithm for computing
the model fixpoint.

Differential Revision: https://reviews.llvm.org/D158848
2023-08-28 17:35:34 +00:00