[PATCH] D97849: [AST][PCH][ASTImporter] Fix UB caused by uninited SwitchStmt member
Gabor Marton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 4 06:10:56 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e90fc2c407b: [AST][PCH][ASTImporter] Fix UB caused by uninited SwitchStmt member (authored by martong).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97849/new/
https://reviews.llvm.org/D97849
Files:
clang/include/clang/AST/Stmt.h
clang/test/Analysis/Inputs/ctu-other.c
clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
clang/test/Analysis/ctu-main.c
Index: clang/test/Analysis/ctu-main.c
===================================================================
--- clang/test/Analysis/ctu-main.c
+++ clang/test/Analysis/ctu-main.c
@@ -69,3 +69,8 @@
d.b = 0;
clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}}
}
+
+int switchWithoutCases(int);
+void testSwitchStmtCrash(int x) {
+ switchWithoutCases(x);
+}
Index: clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
===================================================================
--- clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
+++ clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
@@ -4,3 +4,4 @@
c:@F at enumCheck ctu-other.c.ast
c:@F at identImplicit ctu-other.c.ast
c:@F at structInProto ctu-other.c.ast
+c:@F at switchWithoutCases ctu-other.c.ast
Index: clang/test/Analysis/Inputs/ctu-other.c
===================================================================
--- clang/test/Analysis/Inputs/ctu-other.c
+++ clang/test/Analysis/Inputs/ctu-other.c
@@ -49,3 +49,9 @@
int structInProto(struct DataType {int a;int b; } * d) {
return 0;
}
+
+int switchWithoutCases(int x) {
+ switch (x) {
+ };
+ return 0;
+}
Index: clang/include/clang/AST/Stmt.h
===================================================================
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -2119,7 +2119,7 @@
friend TrailingObjects;
/// Points to a linked list of case and default statements.
- SwitchCase *FirstCase;
+ SwitchCase *FirstCase = nullptr;
// SwitchStmt is followed by several trailing objects,
// some of which optional. Note that it would be more convenient to
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97849.328150.patch
Type: text/x-patch
Size: 1700 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210304/c230a9cc/attachment.bin>
More information about the cfe-commits
mailing list