diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h --- a/clang/include/clang/AST/Stmt.h +++ b/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 diff --git a/clang/test/Analysis/Inputs/ctu-other.c b/clang/test/Analysis/Inputs/ctu-other.c --- a/clang/test/Analysis/Inputs/ctu-other.c +++ b/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; +} 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 --- 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@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 --- a/clang/test/Analysis/ctu-main.c +++ b/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); +}