Skip to content

Commit 49999da

Browse files
committed
Fail when clang FE returned an error
- Add check if clang diagnostics engine reported any errors - Add basic tests for handling invalid C++ code by cgeist
1 parent e971ea4 commit 49999da

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

tools/cgeist/Lib/clang-mlir.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6136,6 +6136,10 @@ static bool parseMLIR(const char *Argv0, std::vector<std::string> filenames,
61366136
Act.EndSourceFile();
61376137
}
61386138
}
6139+
6140+
if (Clang->getDiagnostics().hasErrorOccurred()) {
6141+
return false;
6142+
}
61396143
}
61406144
return true;
61416145
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: not cgeist %s --function=* -S
2+
3+
int main() {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: not cgeist %s --function=* -S
2+
3+
#include "non-existing-header.h"

tools/cgeist/Test/Verification/ompParallelNumThreads.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: cgeist %s --function=* -fopenmp -S | FileCheck %s
2-
#include <omp.h>
2+
3+
int omp_get_thread_num();
34

45
void test_parallel_num_threads(double* x, int sinc) {
56
// CHECK: %[[c32:.+]] = arith.constant 32 : i32

tools/cgeist/driver.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,11 @@ int main(int argc, char **argv) {
571571
llvm::DataLayout DL("");
572572
llvm::Triple gpuTriple;
573573
llvm::DataLayout gpuDL("");
574-
parseMLIR(argv[0], files, cfunction, includeDirs, defines, module, triple, DL,
575-
gpuTriple, gpuDL);
574+
if (!parseMLIR(argv[0], files, cfunction, includeDirs, defines, module,
575+
triple, DL, gpuTriple, gpuDL)) {
576+
llvm::errs() << "parseMLIR failed\n";
577+
return 1;
578+
}
576579

577580
auto convertGepInBounds = [](llvm::Module &llvmModule) {
578581
for (auto &F : llvmModule) {

0 commit comments

Comments
 (0)