llvm-project/clang/lib/StaticAnalyzer/Core
Balazs Benics aa12a48c82 [analyzer] Fix assertion failure with conflicting prototype calls
It turns out we can reach the `Init.castAs<nonlock::CompoundVal>()`
expression with other kinds of SVals. Such as by `nonloc::ConcreteInt`
in this example: https://godbolt.org/z/s4fdxrcs9

```lang=C++
int buffer[10];
void b();
void top() {
  b(&buffer);
}
void b(int *c) {
  *c = 42; // would crash
}
```
In this example, we try to store `42` to the `Elem{buffer, 0}`.

This situation can appear if the CallExpr refers to a function
declaration without prototype. In such cases, the engine will pick the
redecl of the referred function decl which has function body, hence has
a function prototype.

This weird situation will have an interesting effect to the AST, such as
the argument at the callsite will miss a cast, which would cast the
`int (*)[10]` expression into `int *`, which means that when we evaluate
the `*c = 42` expression, we want to bind `42` to an array, causing the
crash.

Look at the AST of the callsite with and without the function prototype:
https://godbolt.org/z/Gncebcbdb
The only difference is that without the proper function prototype, we
will not have the `ImplicitCastExpr` `BitCasting` from `int (*)[10]`
to `int *` to match the expected type of the parameter declaration.

In this patch, I'm proposing to emit a cast in the mentioned edge-case,
to bind the argument value of the expected type to the parameter.

I'm only proposing this if the runtime definition has exactly the same
number of parameters as the callsite feeds it by arguments.
If that's not the case, I believe, we are better off by binding `Unknown`
to those parameters.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D136162
2022-10-26 11:27:01 +02:00
..
APSIntType.cpp
AnalysisManager.cpp
AnalyzerOptions.cpp [clang] Use value instead of getValue (NFC) 2022-07-13 23:39:33 -07:00
BasicValueFactory.cpp
BlockCounter.cpp
BugReporter.cpp [clang] Use llvm::reverse (NFC) 2022-10-15 21:54:13 -07:00
BugReporterVisitors.cpp [analyzer] Support implicit parameter 'self' in path note 2022-09-21 17:26:09 -07:00
CMakeLists.txt [analyzer][NFC] Separate CallDescription from CallEvent 2021-11-15 19:10:46 +01:00
CallDescription.cpp [clang] Don't use Optional::getValue (NFC) 2022-06-20 22:59:26 -07:00
CallEvent.cpp [analyzer] Fix assertion failure with conflicting prototype calls 2022-10-26 11:27:01 +02:00
Checker.cpp
CheckerContext.cpp [analyzer][NFC] Prefer using isa<> instead getAs<> in conditions 2022-06-15 16:58:13 +02:00
CheckerHelpers.cpp [analyzer] Model comparision methods of std::unique_ptr 2021-07-16 09:54:05 +05:30
CheckerManager.cpp [analyzer] Dump checker name if multiple checkers evaluate the same call 2021-11-02 14:42:14 +01:00
CheckerRegistryData.cpp
CommonBugCategories.cpp
ConstraintManager.cpp [analyzer][NFC] Add LLVM_UNLIKELY to assumeDualImpl 2022-06-07 12:48:48 +02:00
CoreEngine.cpp [clang] Qualify auto in range-based for loops (NFC) 2022-09-03 23:27:27 -07:00
DynamicExtent.cpp
DynamicType.cpp [clang] Add a raw_ostream operator<< overload for QualType 2022-04-20 22:09:05 +01:00
Environment.cpp [analyzer] Dump the environment entry kind as well 2022-09-13 09:04:27 +02:00
ExplodedGraph.cpp [analyzer][NFC] Refactor llvm::isa<> usages in the StaticAnalyzer 2021-10-20 17:43:31 +02:00
ExprEngine.cpp [analyzer] Workaround crash on encountering Class non-type template parameters 2022-10-13 08:41:31 +02:00
ExprEngineC.cpp [clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-08 09:12:46 -07:00
ExprEngineCXX.cpp [analyzer] Pass correct bldrCtx to computeObjectUnderConstruction 2022-09-26 11:39:10 +02:00
ExprEngineCallAndReturn.cpp [analyzer] Pass correct bldrCtx to computeObjectUnderConstruction 2022-09-26 11:39:10 +02:00
ExprEngineObjC.cpp [clang] Qualify auto in range-based for loops (NFC) 2022-09-03 23:27:27 -07:00
FunctionSummary.cpp
HTMLDiagnostics.cpp [clang] Use llvm::reverse (NFC) 2021-12-17 16:51:42 -08:00
LoopUnrolling.cpp [Clang][C++20] Support capturing structured bindings in lambdas 2022-08-04 10:12:53 +02:00
LoopWidening.cpp [analyzer][NFC] Refactor llvm::isa<> usages in the StaticAnalyzer 2021-10-20 17:43:31 +02:00
MemRegion.cpp [clang][NFC] Use enum for -fstrict-flex-arrays 2022-10-06 10:45:41 -07:00
PlistDiagnostics.cpp [clang] Use value instead of getValue (NFC) 2022-07-13 23:39:33 -07:00
PrettyStackTraceLocationContext.h
ProgramState.cpp [analyzer] Process non-POD array element destructors 2022-08-24 01:28:21 +02:00
RangeConstraintManager.cpp [clang][clang-tools-extra] LLVM_NODISCARD => [[nodiscard]]. NFC 2022-08-09 07:11:18 +00:00
RangedConstraintManager.cpp [analyzer] Fix crash in RangedConstraintManager.cpp 2022-03-23 08:26:40 -05:00
RegionStore.cpp [analyzer] Make directly bounded LazyCompoundVal as lazily copied 2022-10-19 16:06:32 +02:00
SMTConstraintManager.cpp [llvm][clang][NFC] updates inline licence info 2021-08-11 02:48:53 +00:00
SValBuilder.cpp [clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-08 09:12:46 -07:00
SVals.cpp [analyzer] Add new function `clang_analyzer_value` to ExprInspectionChecker 2022-07-15 20:07:04 +03:00
SarifDiagnostics.cpp [clang] Convert for_each to range-based for loops (NFC) 2022-06-10 22:39:45 -07:00
SimpleConstraintManager.cpp [analyzer] Remove NotifyAssumeClients 2022-06-07 13:02:03 +02:00
SimpleSValBuilder.cpp [clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-08 09:12:46 -07:00
Store.cpp [analyzer][NFC] Prefer using isa<> instead getAs<> in conditions 2022-06-15 16:58:13 +02:00
SymbolManager.cpp [analyzer] Fix the liveness of Symbols for values in regions referred by LazyCompoundVal 2022-10-19 16:06:32 +02:00
TextDiagnostics.cpp Fix a typo (occured => occurred) 2022-02-08 21:35:26 +01:00
WorkList.cpp Use llvm::less_second (NFC) 2022-06-04 22:48:32 -07:00