brintos

brintos / llvm-project-archived public Read only

0
0
Text · 692 B · 6bf78b5 Raw
41 lines · cpp
1
2// nodefaultlib build: cl -Zi sigsegv.cpp /link /nodefaultlib
3
4#ifdef USE_CRT
5#include <stdio.h>
6#else
7int main();
8extern "C"
9{
10    int _fltused;
11    void mainCRTStartup() { main(); }
12    void printf(const char*, ...) {}
13}
14#endif
15
16void crash(bool crash_self)
17{
18    printf("Before...\n");
19    if(crash_self)
20    {
21        printf("Crashing in 3, 2, 1 ...\n");
22        *(volatile int*)nullptr = 0;
23    }
24    printf("After...\n");
25}
26
27int foo(int x, float y, const char* msg)
28{
29    bool flag = x > y;
30    if(flag)
31        printf("x = %d, y = %f, msg = %s\n", x, y, msg);
32    crash(flag);
33    return x << 1;
34}
35
36int main()
37{
38    foo(10, 3.14, "testing");
39}
40
41