Skip to content

Commit

Permalink
Fail when clang FE returned an error (#377)
Browse files Browse the repository at this point in the history
* 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

* Address review comments
  • Loading branch information
aobolensk authored Jan 2, 2024
1 parent e971ea4 commit bc788a0
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions tools/cgeist/Lib/clang-mlir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6136,6 +6136,10 @@ static bool parseMLIR(const char *Argv0, std::vector<std::string> filenames,
Act.EndSourceFile();
}
}

if (Clang->getDiagnostics().hasErrorOccurred()) {
return false;
}
}
return true;
}
2 changes: 1 addition & 1 deletion tools/cgeist/Test/Verification/freecst.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: cgeist %s --function=* -S | FileCheck %s
// RUN: cgeist %s %stdinclude --function=* -S | FileCheck %s

#include <stdlib.h>
struct band {
Expand Down
4 changes: 4 additions & 0 deletions tools/cgeist/Test/Verification/invalid/basic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// RUN: cgeist %s --function=* -S
// XFAIL: *

int main() {
4 changes: 4 additions & 0 deletions tools/cgeist/Test/Verification/invalid/invalid_include.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// RUN: cgeist %s --function=* -S
// XFAIL: *

#include "non-existing-header.h"
2 changes: 1 addition & 1 deletion tools/cgeist/Test/Verification/memref-fullrank.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: cgeist %s -S --function=main -memref-fullrank -O0 | FileCheck %s
// RUN: cgeist %s -S %stdinclude --function=main -memref-fullrank -O0 | FileCheck %s

#include <stdio.h>

Expand Down
3 changes: 2 additions & 1 deletion tools/cgeist/Test/Verification/ompParallelNumThreads.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: cgeist %s --function=* -fopenmp -S | FileCheck %s
#include <omp.h>

int omp_get_thread_num();

void test_parallel_num_threads(double* x, int sinc) {
// CHECK: %[[c32:.+]] = arith.constant 32 : i32
Expand Down
4 changes: 2 additions & 2 deletions tools/cgeist/Test/Verification/raiseToAffineUnsignedCmp.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: cgeist %s --function=matmul --raise-scf-to-affine -S | FileCheck %s
// RUN: cgeist %s %stdinclude --function=matmul --raise-scf-to-affine -S | FileCheck %s

void matmul(float A[100][200], float B[200][300], float C[100][300]) {
int i, j, k;
Expand All @@ -21,4 +21,4 @@ void matmul(float A[100][200], float B[200][300], float C[100][300]) {
}
}
}

}
4 changes: 2 additions & 2 deletions tools/cgeist/Test/Verification/triple.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: cgeist --target aarch64-unknown-linux-gnu %s %stdinclude -S -o - | FileCheck %s -check-prefix=MLIR
// RUN: cgeist --target aarch64-unknown-linux-gnu %s %stdinclude -emit-llvm -S -o - | FileCheck %s -check-prefix=LLVM
// RUN: cgeist --target aarch64-unknown-linux-gnu %s -nocudalib -nocudainc %stdinclude -S -o - | FileCheck %s -check-prefix=MLIR
// RUN: cgeist --target aarch64-unknown-linux-gnu %s -nocudalib -nocudainc %stdinclude -emit-llvm -S -o - | FileCheck %s -check-prefix=LLVM

// MLIR: llvm.target_triple = "aarch64-unknown-linux-gnu"
// LLVM: target triple = "aarch64-unknown-linux-gnu"
Expand Down
6 changes: 4 additions & 2 deletions tools/cgeist/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,10 @@ int main(int argc, char **argv) {
llvm::DataLayout DL("");
llvm::Triple gpuTriple;
llvm::DataLayout gpuDL("");
parseMLIR(argv[0], files, cfunction, includeDirs, defines, module, triple, DL,
gpuTriple, gpuDL);
if (!parseMLIR(argv[0], files, cfunction, includeDirs, defines, module,
triple, DL, gpuTriple, gpuDL)) {
return 1;
}

auto convertGepInBounds = [](llvm::Module &llvmModule) {
for (auto &F : llvmModule) {
Expand Down

0 comments on commit bc788a0

Please sign in to comment.