diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h index c2e69a91e55d0..2085904b7f01e 100644 --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -2119,7 +2119,7 @@ class SwitchStmt final : public Stmt, 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 diff --git a/clang/test/Analysis/Inputs/ctu-other.c b/clang/test/Analysis/Inputs/ctu-other.c index 16ebb3506f603..48a3f322cbd57 100644 --- a/clang/test/Analysis/Inputs/ctu-other.c +++ b/clang/test/Analysis/Inputs/ctu-other.c @@ -49,3 +49,9 @@ int identImplicit(int in) { int structInProto(struct DataType {int a;int b; } * d) { return 0; } + +int switchWithoutCases(int x) { + switch (x) { + }; + return 0; +} diff --git a/clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt b/clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt index 9abaa501a4cb1..a6de9304551b0 100644 --- a/clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt +++ b/clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt @@ -4,3 +4,4 @@ c:@F@f ctu-other.c.ast c:@F@enumCheck ctu-other.c.ast c:@F@identImplicit ctu-other.c.ast c:@F@structInProto ctu-other.c.ast +c:@F@switchWithoutCases ctu-other.c.ast diff --git a/clang/test/Analysis/ctu-main.c b/clang/test/Analysis/ctu-main.c index d991eb73a95c6..1415490668ba5 100644 --- a/clang/test/Analysis/ctu-main.c +++ b/clang/test/Analysis/ctu-main.c @@ -69,3 +69,8 @@ void testStructDefInArgument() { d.b = 0; clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}} } + +int switchWithoutCases(int); +void testSwitchStmtCrash(int x) { + switchWithoutCases(x); +}