[PATCH] D156497: [BPF] report fatal error rather than miscompile
Eduard Zingerman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 06:22:21 PDT 2023
eddyz87 added a comment.
I messed up.
@ast is right, I missed the fact that `clang` already exits with return code 1 when any of the conditions reported by `fail(...)` happen, e.g.:
$ cat t.c
struct foo { int a[100]; };
extern void consume(void *);
struct foo bar(struct foo foo) {
consume(&foo);
return foo;
}
$ clang --target=bpf t.c; echo "exit code is $?"
t.c:3:12: error: aggregate returns are not supported
3 | struct foo bar(struct foo foo) {
| ^
1 error generated.
exit code is 1
This happens because `diagnose()` is implemented as follows:
void LLVMContext::diagnose(const DiagnosticInfo &DI) {
...
if (pImpl->DiagHandler &&
(!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
pImpl->DiagHandler->handleDiagnostics(DI))
return;
...
// Otherwise, print the message with a prefix based on the severity.
...
if (DI.getSeverity() == DS_Error)
exit(1);
}
And `fail()` uses `DiagnosticInfoUnsupported` which has `DS_Error` severity. Usage of `diagnostic` in combination with `DiagnosticInfoUnsupported` could be found in other backends as well, e.g. in RISCVISelLowering.cpp. So, it looks like no changes are necessary in the BPF lowering and embedder needs to install diagnostics handler and look for `DS_Error` messages.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156497/new/
https://reviews.llvm.org/D156497
More information about the llvm-commits
mailing list