[clang] [clang][dataflow] Skip array types when handling InitListExprs. (PR #83013)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 26 07:11:54 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Samira Bazuzi (bazuzi)
<details>
<summary>Changes</summary>
Crashes resulted from single-element InitListExprs for arrays with elements of a record type after #<!-- -->80970.
---
Full diff: https://github.com/llvm/llvm-project/pull/83013.diff
2 Files Affected:
- (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+3-3)
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+16-1)
``````````diff
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index fe13e919bddcd8..a5b8e9cbc18e64 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -671,9 +671,9 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
}
if (!Type->isStructureOrClassType()) {
- // Until array initialization is implemented, we don't need to care about
- // cases where `getNumInits() > 1`.
- if (S->getNumInits() == 1)
+ // Until array initialization is implemented, we skip arrays and don't need
+ // to care about cases where `getNumInits() > 1`.
+ if (!Type->isArrayType() && S->getNumInits() == 1)
propagateValueOrStorageLocation(*S->getInit(0), *S, Env);
return;
}
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index a65b0446ac7818..2be899f5b6da91 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2367,6 +2367,21 @@ TEST(TransferTest, InitListExprAsXValue) {
});
}
+TEST(TransferTest, ArrayInitListExprOneRecordElement) {
+ // This is a crash repro.
+ std::string Code = R"cc(
+ struct S {};
+
+ void target() { S foo[] = {S()}; }
+ )cc";
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ // Just verify that it doesn't crash.
+ });
+}
+
TEST(TransferTest, InitListExprAsUnion) {
// This is a crash repro.
std::string Code = R"cc(
@@ -3414,7 +3429,7 @@ TEST(TransferTest, AggregateInitializationFunctionPointer) {
struct S {
void (*const Field)();
};
-
+
void target() {
S s{nullptr};
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/83013
More information about the cfe-commits
mailing list