-
Notifications
You must be signed in to change notification settings - Fork 15k
Open
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.platform:windows
Description
The following code is supposed to read from potentially inaccessible memory, and return the provided default value if the memory is not accessible. It works fine when compiled with with cl (outputs except and done), but crashes when compiled with clang-cl:
#include <stdio.h>
#include <windows.h>
//#define WORKAROUND
int SafeFetch32(const int* adr, int errValue) {
int v = 0;
__try {
#ifdef WORKAROUND
printf("");
#endif
v = *adr;
#ifdef WORKAROUND
printf("");
#endif
}
__except(EXCEPTION_EXECUTE_HANDLER) {
printf("except\n");
v = errValue;
}
return v;
}
int main() {
SafeFetch32(0, -1);
printf("done");
return 0;
}When compiled with -DWORKAROUND, the code generated by clang-cl works as expected.
Clang downloaded with MS Visual Studio 2022 Community:
> clang-cl --version
clang version 15.0.1
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\binNot sure if that's relevant, but the results were collected on Windows 11 21H2.
skoulik and geoff-m
Metadata
Metadata
Assignees
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.platform:windows