Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] evaluating a variable from an outer scope in a @finally inside a block causes an internal compiler error #43828

Open
DHowett opened this issue Jan 7, 2020 · 5 comments
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party objective-c++

Comments

@DHowett
Copy link
Contributor

DHowett commented Jan 7, 2020

Bugzilla Link 44483
Version 9.0
OS Windows NT
Attachments preprocessed repro, repro.sh
CC @davidchisnall,@dwblaikie,@zygoloid,@rnk

Extended Description

With the following source:

// clang -emit-llvm -S -fblocks --target=i686-pc-windows-msvc repro.mm
int test() {
    int outer;
    auto b = ^() {
        @​try {
        } @​finally {
            outer;
        }
    };
}

the compiler fails with the following stack dump.

Stack dump:
0.      Program arguments: C:\Program Files\LLVM\bin\clang.exe -cc1 -triple i686-pc-windows-msvc19.11.0 -emit-llvm -disable-free -disable-llvm-verifier -discard-value-names -main-file-name repro.mm -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -dwarf-column-info -coverage-notes-file E:\repro.gcno -resource-dir C:\Program Files\LLVM\lib\clang\9.0.0 -internal-isystem C:\Program Files\LLVM\lib\clang\9.0.0\include -internal-isystem C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.23.28105\include -internal-isystem C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um -internal-isystem C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt -internal-isystem C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared -internal-isystem C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um -internal-isystem C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt -internal-isystem C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt -fdeprecated-macro -fdebug-compilation-dir E:\ -ferror-limit 19 -fmessage-length 158 -fblocks -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fobjc-exceptions -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o repro.ll -x objective-c++ repro.mm
1.      <eof> parser at end of file
2.      repro.mm:1:5: LLVM IR generation of declaration 'test'
3.      repro.mm:1:5: Generating code for declaration 'test'
4.      repro.mm:3:18: LLVM IR generation of compound statement ('{}')
 #&#8203;0 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x19d349a C:\Program Files\LLVM\bin\clang.exe 0x19d4903
 #&#8203;1 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1a6eccc C:\Program Files\LLVM\bin\clang.exe 0x18d0c3a
 #&#8203;2 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1a710c4 C:\Program Files\LLVM\bin\clang.exe 0x1a79dc0
 #&#8203;3 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1a7956b C:\Program Files\LLVM\bin\clang.exe 0x1a71626
 #&#8203;4 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1a70b1f C:\Program Files\LLVM\bin\clang.exe 0x1a9ef99
 #&#8203;5 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1a9bf22 C:\Program Files\LLVM\bin\clang.exe 0x1a9a6bc
 #&#8203;6 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1acdf90 C:\Program Files\LLVM\bin\clang.exe 0x1ac390e
 #&#8203;7 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1a0ffdf C:\Program Files\LLVM\bin\clang.exe 0x1a14ebe
 #&#8203;8 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1a12948 C:\Program Files\LLVM\bin\clang.exe 0x1a0e3d6
 #&#8203;9 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1a0e063 C:\Program Files\LLVM\bin\clang.exe 0x1a7966c
#&#8203;10 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1a716b9 C:\Program Files\LLVM\bin\clang.exe 0x1a70b1f
#&#8203;11 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1a79dc0 C:\Program Files\LLVM\bin\clang.exe 0x1995cae
#&#8203;12 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1996599 C:\Program Files\LLVM\bin\clang.exe 0x181cb1d
#&#8203;13 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x181618c C:\Program Files\LLVM\bin\clang.exe 0x1819d61
#&#8203;14 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x181f55d C:\Program Files\LLVM\bin\clang.exe 0x33cbc3f
#&#8203;15 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x33c9719 C:\Program Files\LLVM\bin\clang.exe 0x275b465
#&#8203;16 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1cb3492 C:\Program Files\LLVM\bin\clang.exe 0x1c771cf
#&#8203;17 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x1d09c87 C:\Program Files\LLVM\bin\clang.exe 0x6e87
#&#8203;18 0x00007ff64b3e349a C:\Program Files\LLVM\bin\clang.exe 0x4564 C:\Program Files\LLVM\bin\clang.exe 0x33dda20
@DHowett
Copy link
Contributor Author

DHowett commented Jan 8, 2020

Additional information from a TRUNK build.

Assertion failed: Val && "isa<> used on a null pointer", file E:\src\llvm\include\llvm/Support/Casting.h, line 105

0x00007FF7C1F41FA8 (0x0000000519382838 0x000001A277CBC860 0x000001A277C59918 0xCCCCCCCCCCCCCCCC), llvm::isa<clang::ImplicitParamDecl,clang::VarDecl const *>() + 0x28 bytes(s), E:\src\llvm\include\llvm\Support\Casting.h, line 144
0x00007FF7C2265484 (0x00000005193830D8 0x0000000519385698 0x000001A2782A24E0 0x000001A2782BE800), clang::CodeGen::CodeGenFunction::EmitCapturedLocals() + 0x4B4 bytes(s), E:\src\llvm\tools\clang\lib\CodeGen\CGException.cpp, line 1798 + 0xD byte(s)
0x00007FF7C226464E (0x00000005193830D8 0x0000000519385698 0xCCCCCCCCCCCCCC00 0x000001A2782A24E0), clang::CodeGen::CodeGenFunction::startOutlinedSEHHelper() + 0x6FE bytes(s), E:\src\llvm\tools\clang\lib\CodeGen\CGException.cpp, line 1889
0x00007FF7C2100A62 (0x000001A277CBE330 0x0000000519385698 0x000001A2782A2538 0x0000000519384970), clang::CodeGen::CGObjCRuntime::EmitTryCatchStmt() + 0x562 bytes(s), E:\src\llvm\tools\clang\lib\CodeGen\CGObjCRuntime.cpp, line 203

@DHowett
Copy link
Contributor Author

DHowett commented Jan 8, 2020

David, it looks like we're trying to capture "CXXAbiThisDecl" somewhere south of CGObjCRuntime::EmitTryCatchStmt() for a funclet finally in SEH mode.

EmitTryCatchStmt -> startOutlinedSEHHelper -> EmitCapturedLocals -> CaptureFinder(CXXABIThisDecl) -> CaptureFinder::VisitDeclRefExpr -> refersToEnclosingVariableOrCapture therefore insert ParentThis.

Problem is, CXXAbiThisDecl is null because there is no this decl and we're not in a C++ context with a this.

@rnk
Copy link
Collaborator

rnk commented Jan 15, 2020

I applied a shallow fix, but things just crash later:

diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 53fafab3e0e..7968e446ec8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1675,7 +1675,7 @@ struct CaptureFinder : ConstStmtVisitor {

void VisitDeclRefExpr(const DeclRefExpr *E) {
// If this is already a capture, just make sure we capture 'this'.

  • if (E->refersToEnclosingVariableOrCapture()) {
  • if (ParentThis && E->refersToEnclosingVariableOrCapture()) {
    Captures.insert(ParentThis);
    return;
    }

I seem to recall assuming somewhere that SEH only happens in FunctionDecls, but BlockDecl doesn't inherit from FunctionDecl.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@triplef
Copy link
Member

triplef commented Jan 18, 2022

See also #51899 for an even simpler reproduction without referencing a variable. Basically using @finally will crash the compiler.

@DHowett DHowett changed the title [Windows] evaluating a variable from an outer scope in a @&#8203;finally inside a block causes an internal compiler error [Windows] evaluating a variable from an outer scope in a @finally inside a block causes an internal compiler error Jan 18, 2022
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
triplef added a commit to gnustep/tools-windows-msvc that referenced this issue Sep 27, 2022
@Endilll Endilll added clang:frontend Language frontend issues, e.g. anything involving "Sema" objective-c++ and removed clang Clang issues not falling into any other category labels May 22, 2023
@llvmbot
Copy link
Member

llvmbot commented May 22, 2023

@llvm/issue-subscribers-clang-frontend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party objective-c++
Projects
None yet
Development

No branches or pull requests

5 participants