From f5b6c2b9cfcf40b5591d73707f530759a9159fa8 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Fri, 24 Dec 2021 13:08:40 -0500 Subject: [PATCH] Handle switch without cases --- tools/mlir-clang/Lib/CGStmt.cc | 7 +++++++ tools/mlir-clang/Test/Verification/switchnone.c | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tools/mlir-clang/Test/Verification/switchnone.c diff --git a/tools/mlir-clang/Lib/CGStmt.cc b/tools/mlir-clang/Lib/CGStmt.cc index 6937ac8..3c86a04 100644 --- a/tools/mlir-clang/Lib/CGStmt.cc +++ b/tools/mlir-clang/Lib/CGStmt.cc @@ -650,6 +650,13 @@ ValueCategory MLIRScanner::VisitSwitchStmt(clang::SwitchStmt *stmt) { } } + if (caseVals.size() == 0) { + delete &exitB; + er.erase(); + builder.setInsertionPoint(oldblock2, oldpoint2); + return nullptr; + } + if (inCase) loops.pop_back(); builder.create(loc, &exitB); diff --git a/tools/mlir-clang/Test/Verification/switchnone.c b/tools/mlir-clang/Test/Verification/switchnone.c new file mode 100644 index 0000000..0446b60 --- /dev/null +++ b/tools/mlir-clang/Test/Verification/switchnone.c @@ -0,0 +1,12 @@ +// RUN: mlir-clang %s --function=foo -S | FileCheck %s + +int foo(int t) { + switch (t) { + } + return t; +} + +// TODO the select should be canonicalized better +// CHECK: func @foo(%arg0: i32) -> i32 attributes {llvm.linkage = #llvm.linkage} { +// CHECK-NEXT: return %arg0 : i32 +// CHECK-NEXT: }