llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.37k stars 12.15k forks source link

break out of __finally block fails assert (!BreakContinueStack.empty() && "break stmt not in a loop or switch!") #116925

Open jaykrell opened 1 week ago

jaykrell commented 1 week ago

see also https://github.com/microsoft/compiler-tests/blob/master/seh/seh0043.c

https://github.com/microsoft/compiler-tests/blob/master/seh/seh0048.c

int main()
{
    int a = 10;
    while (1)
    {
        __try {
            a = 20;
            *(volatile char*)0;
            a = 30;
        }
        __finally
        {
            break;
        }
    }

    return a;
}

/*
1.c(18,13): warning: jump out of __finally block has undefined behavior [-Wjump-seh-finally]
            break;;
            ^
Assertion failed: !BreakContinueStack.empty() && "break stmt not in a loop or switch!", file C:\Users\swift-ci\jenkins\workspace\oss-swift-windows-toolchain\llvm-project\clang\lib\CodeGen\CGStmt.cpp, line 1390
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump
2. 1.c:1:5: LLVM IR generation of declaration 'main'
3. 1.c:1:5: Generating code for declaration 'main'
4. 1.c:5:5: LLVM IR generation of compound statement ('{}')
5. 1.c:12:9: LLVM IR generation of compound statement ('{}')
*/
jaykrell commented 1 week ago

More information.

C:\s>type break-in-finally.c
int main()
{
    int a = 10;
    while (a < 100)
    {
        __try {
            a += 10;
printf("1\n");
            *(volatile char*)0;
printf("2\n");
            a += 10;
        }
        __finally
        {
printf("3\n");
            break;
        }
    }
printf("4\n");
    return a;
}
C:\s>cl break-in-finally.c && break-in-finally.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.41.34123 for x64

break-in-finally.c(16): warning C4532: 'break': jump out of __finally block has undefined behavior during 

1
3
4