Skip to content

Commit a2e5a89

Browse files
fadeevalAlexeySachkov
authored andcommitted
Exchange abort() to exit() in llvm-spirv tool by default. (#561)
The behavior is still configurable via source code change Signed-off-by: Aleksander Fadeev <[email protected]>
1 parent 476c2e2 commit a2e5a89

14 files changed

+26
-15
lines changed

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDebug.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@
4242
using namespace SPIRV;
4343

4444
bool SPIRV::SPIRVDbgEnable = false;
45-
bool SPIRV::SPIRVDbgAbortOnError = true;
45+
SPIRV::SPIRVDbgErrorHandlingKinds SPIRV::SPIRVDbgError =
46+
SPIRVDbgErrorHandlingKinds::Exit;
4647
bool SPIRV::SPIRVDbgErrorMsgIncludesSourceInfo = true;

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDebug.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ extern bool SPIRVDbgEnable;
5959
// Include source file and line number in error message.
6060
extern bool SPIRVDbgErrorMsgIncludesSourceInfo;
6161

62-
// Enable assert on error
63-
extern bool SPIRVDbgAbortOnError;
62+
// Enable assert or exit on error
63+
enum class SPIRVDbgErrorHandlingKinds { Abort, Exit, Ignore };
64+
extern SPIRVDbgErrorHandlingKinds SPIRVDbgError;
6465

6566
// Output stream for SPIRV debug information.
6667
inline spv_ostream &spvdbgs() {

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVError.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,19 @@ inline bool SPIRVErrorLog::checkError(bool Cond, SPIRVErrorCode ErrCode,
113113
if (SPIRVDbgErrorMsgIncludesSourceInfo && FileName)
114114
SS << " [Src: " << FileName << ":" << LineNo << " " << CondString << " ]";
115115
setError(ErrCode, SS.str());
116-
if (SPIRVDbgAbortOnError) {
116+
switch (SPIRVDbgError) {
117+
case SPIRVDbgErrorHandlingKinds::Abort:
117118
spvdbgs() << SS.str() << '\n';
118119
spvdbgs().flush();
119120
abort();
121+
break;
122+
case SPIRVDbgErrorHandlingKinds::Exit:
123+
spvdbgs() << SS.str() << '\n';
124+
spvdbgs().flush();
125+
std::exit(ErrCode);
126+
break;
127+
case SPIRVDbgErrorHandlingKinds::Ignore:
128+
break;
120129
}
121130
return Cond;
122131
}

llvm-spirv/test/negative/atomicrmw-unsupported-operation.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: llvm-as < %s -o %t.bc
2-
; RUN: not --crash llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s
2+
; RUN: not llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s
33

44
; CHECK: InvalidInstruction: Can't translate llvm instruction:
55
; CHECK: atomicrmw nand i32 addrspace(1)* @ui, i32 42 acq_rel

llvm-spirv/test/negative/invalid-int-bitwidth.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: llvm-as %s -o %t.bc
2-
; RUN: not --crash llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s
2+
; RUN: not llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s
33

44
; CHECK: InvalidBitWidth: Invalid bit width in input: 128
55

llvm-spirv/test/negative/llvm.fma.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; It either represents intrinsic's semantics with SPIRV instruction(s), or
33
; reports an error.
44
; RUN: llvm-as %s -o %t.bc
5-
; RUN: not --crash llvm-spirv %t.bc 2>&1 | FileCheck %s
5+
; RUN: not llvm-spirv %t.bc 2>&1 | FileCheck %s
66

77
; CHECK: InvalidFunctionCall: Unexpected llvm intrinsic: llvm.fma.f32
88

llvm-spirv/test/negative/unimplemented.spt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020

2121
; Test that we gracefully reject an unimplemented opcode such as OpDPdx.
2222

23-
; RUN: not --crash llvm-spirv %s -to-binary -o %t.spv 2>&1 | FileCheck %s
23+
; RUN: not llvm-spirv %s -to-binary -o %t.spv 2>&1 | FileCheck %s
2424

2525
; CHECK: UnimplementedOpCode: Unimplemented opcode 207

llvm-spirv/test/negative/unsupported-triple.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: llvm-as %s -o %t.bc
2-
; RUN: not --crash llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s
2+
; RUN: not llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s
33

44
; CHECK: InvalidTargetTriple: Expects spir-unknown-unknown or spir64-unknown-unknown. Actual target triple is aarch64
55

llvm-spirv/test/negative/zero-length-array.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: llvm-as %s -o %t.bc
2-
; RUN: not --crash llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s
2+
; RUN: not llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s
33

44
; CHECK: InvalidArraySize: Array size must be at least 1: [0 x i32]
55

llvm-spirv/test/spirv-unknown-extensions.spt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939

4040
1 FunctionEnd
4141

42-
; RUN: not --crash llvm-spirv %s -to-binary -o - 2>&1 | FileCheck %s
42+
; RUN: not llvm-spirv %s -to-binary -o - 2>&1 | FileCheck %s
4343
; CHECK: input SPIR-V module uses unknown extension 'unknown_spirv_extension'
4444

llvm-spirv/test/spirv-version-controls-negative-1.spt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
1 FunctionEnd
2929

30-
; RUN: not --crash llvm-spirv %s -to-binary -o - 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
30+
; RUN: not llvm-spirv %s -to-binary -o - 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
3131
;
3232
; CHECK-ERROR: Invalid SPIR-V module: unsupported SPIR-V version number 'unknown (66560)'. Range of supported/known SPIR-V versions is 1.0 (65536) - 1.3 (66304)
3333

llvm-spirv/test/spirv-version-controls-negative-2.spt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
1 FunctionEnd
2929

30-
; RUN: not --crash llvm-spirv %s -to-binary -o - 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
30+
; RUN: not llvm-spirv %s -to-binary -o - 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
3131
;
3232
; CHECK-ERROR: Invalid SPIR-V module: unsupported SPIR-V version number 'unknown (1024)'. Range of supported/known SPIR-V versions is 1.0 (65536) - 1.3 (66304)
3333

llvm-spirv/test/spirv-version-controls.spt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
; RUN: llvm-spirv %s -to-binary -o %t.spv
3131
; RUN: spirv-val %t.spv
3232
; RUN: llvm-spirv -r %t.spv --spirv-max-version=1.1 -o %t
33-
; RUN: not --crash llvm-spirv -r %t.spv --spirv-max-version=1.0 -o - 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
33+
; RUN: not llvm-spirv -r %t.spv --spirv-max-version=1.0 -o - 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
3434
;
3535
; CHECK-ERROR: Invalid SPIR-V module: incorrect SPIR-V version number 1.1 (65792) - it conflicts with --spirv-max-version which is set to 1.0 (65536)

llvm-spirv/test/transcoding/NoSignedUnsignedWrap.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
;
2424
; Check that translator is able to reject SPIR-V if extension is disallowed
2525
;
26-
; RUN: not --crash llvm-spirv -r %t.spv --spirv-ext=-SPV_KHR_no_integer_wrap_decoration -o - 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID-SPIRV
26+
; RUN: not llvm-spirv -r %t.spv --spirv-ext=-SPV_KHR_no_integer_wrap_decoration -o - 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID-SPIRV
2727
;
2828
; Check that translator is able to skip nsw/nuw attributes if extension is disabled implicitly or explicitly
2929
;

0 commit comments

Comments
 (0)