Skip to content

[GNU ObjC] Clang 14 regression: frontend crash in clang::CodeGen::CreateGNUObjCRuntime() building Objective-C++ code #54556

Closed
@triplef

Description

@triplef

The following Objective-C++ code causes a frontend crash with Clang 14.0.0 using the GNU Objective-C runtime on Win64 and Win32 (and possibly other platforms). The same code does not crash with Clang 13.0.1 (both using pre-built binaries from GitHub). It also does not crash using the Apple runtime on macOS.

This seems to happen using various C++ standard library types as value arguments to Objective-C method, but not with pointer arguments or trivial self-defined C++ class types as value arguments. It also happens only with Objective-C instance methods, but not with class methods.

#include <string>

__attribute__((objc_root_class))
@interface Test
-(void)test:(std::string)x;
@end

@implementation Test
-(void)test:(std::string)x {}
@end

int main()
{
	Test *test = NULL;
	[test test:""];
}
Stack dump:
0.      Program arguments: "C:\\Program Files\\LLVM-14\\bin\\clang.exe" -emit-llvm -Xclang -disable-llvm-passes -c clang-14-crash.mm
1.      <eof> parser at end of file
2.      clang-14-crash.mm:12:5: LLVM IR generation of declaration 'main'
3.      clang-14-crash.mm:12:5: Generating code for declaration 'main'
 #0 0x00007ff702ab36e9 clang::CodeGen::CreateGNUObjCRuntime(class clang::CodeGen::CodeGenModule &) (clang.exe+0x11f36e9)
 #1 0x00007ff702a27332 clang::CodeGen::CodeGenFunction::EmitObjCMessageExpr(class clang::ObjCMessageExpr const *, class clang::CodeGen::ReturnValueSlot) (clang.exe+0x1167332)
 #2 0x00007ff702bc4bfb clang::CodeGen::CodeGenFunction::ShouldNullCheckClassCastValue(class clang::CastExpr const *) (clang.exe+0x1304bfb)
 #3 0x00007ff702bc47cb clang::CodeGen::CodeGenFunction::ShouldNullCheckClassCastValue(class clang::CastExpr const *) (clang.exe+0x13047cb)
 #4 0x00007ff702bbfb6f clang::CodeGen::CodeGenFunction::EmitScalarExpr(class clang::Expr const *, bool) (clang.exe+0x12ffb6f)
 #5 0x00007ff702a70c65 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(class clang::Expr const *) (clang.exe+0x11b0c65)
 #6 0x00007ff702b92bd0 clang::CodeGen::CodeGenFunction::EmitStmt(class clang::Stmt const *, class llvm::ArrayRef<class clang::Attr const *>) (clang.exe+0x12d2bd0)
 #7 0x00007ff702b8ebec clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(class clang::CompoundStmt const &, bool, class clang::CodeGen::AggValueSlot) (clang.exe+0x12cebec)
 #8 0x00007ff702a5a3a5 clang::CodeGen::CodeGenFunction::GenerateCode(class clang::GlobalDecl, class llvm::Function *, class clang::CodeGen::CGFunctionInfo const &) (clang.exe+0x119a3a5)
 #9 0x00007ff70294f6b0 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(class clang::GlobalDecl, class llvm::GlobalValue *) (clang.exe+0x108f6b0)
#10 0x00007ff70294f2ef clang::CodeGen::CodeGenModule::EmitGlobalDefinition(class clang::GlobalDecl, class llvm::GlobalValue *) (clang.exe+0x108f2ef)
#11 0x00007ff70294ee1b clang::CodeGen::CodeGenModule::EmitGlobal(class clang::GlobalDecl) (clang.exe+0x108ee1b)
#12 0x00007ff702952334 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(class clang::Decl *) (clang.exe+0x1092334)
#13 0x00007ff704aec6af clang::CodeGenerator::GetModule(void) (clang.exe+0x322c6af)
#14 0x00007ff704ae7a16 clang::BackendConsumer::HandleTopLevelDecl(class clang::DeclGroupRef) (clang.exe+0x3227a16)
#15 0x00007ff703a7fe47 clang::ParseAST(class clang::Sema &, bool, bool) (clang.exe+0x21bfe47)
#16 0x00007ff702f14f87 clang::ASTFrontendAction::ExecuteAction(void) (clang.exe+0x1654f87)
#17 0x00007ff704ae6e78 clang::CodeGenAction::ExecuteAction(void) (clang.exe+0x3226e78)
#18 0x00007ff702f14a02 clang::FrontendAction::Execute(void) (clang.exe+0x1654a02)
#19 0x00007ff702ede802 clang::CompilerInstance::ExecuteAction(class clang::FrontendAction &) (clang.exe+0x161e802)
#20 0x00007ff702f81228 clang::ExecuteCompilerInvocation(class clang::CompilerInstance *) (clang.exe+0x16c1228)
#21 0x00007ff701935c32 clang::CodeGen::TargetCodeGenInfo::testFPKind(class llvm::Value *, unsigned int, class clang::CodeGen::CGBuilderTy &, class clang::CodeGen::CodeGenModule &) const (clang.exe+0x75c32)
#22 0x00007ff701930b67 clang::ChainedDiagnosticConsumer::EndSourceFile(void) (clang.exe+0x70b67)
#23 0x00007ff702dfe917 clang::driver::toolchains::BareMetal::handlesTarget(class llvm::Triple const &) (clang.exe+0x153e917)
#24 0x00007ff70269709f llvm::CrashRecoveryContext::RunSafely(class llvm::function_ref<(void)>) (clang.exe+0xdd709f)
#25 0x00007ff702dfef70 clang::driver::CC1Command::Execute(class llvm::ArrayRef<class llvm::Optional<class llvm::StringRef>>, class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> *, bool *) const (clang.exe+0x153ef70)
#26 0x00007ff702d7d2e0 clang::driver::Compilation::ExecuteCommand(class clang::driver::Command const &, class clang::driver::Command const *&) const (clang.exe+0x14bd2e0)
#27 0x00007ff702d7d62d clang::driver::Compilation::ExecuteJobs(class clang::driver::JobList const &, class llvm::SmallVectorImpl<struct std::pair<int, class clang::driver::Command const *>> &) const (clang.exe+0x14bd62d)
#28 0x00007ff702d64d48 clang::driver::Driver::ExecuteCompilation(class clang::driver::Compilation &, class llvm::SmallVectorImpl<struct std::pair<int, class clang::driver::Command const *>> &) (clang.exe+0x14a4d48)
#29 0x00007ff701932e6b llvm::slpvectorizer::BoUpSLP::BlockScheduling::ReadyList::insert(struct llvm::slpvectorizer::BoUpSLP::ScheduleData *) (clang.exe+0x72e6b)
#30 0x00007ff704887c8c clang::Preprocessor::LexUnexpandedNonComment(class clang::Token &) (clang.exe+0x2fc7c8c)
#31 0x00007ffb3c0554e0 (C:\WINDOWS\System32\KERNEL32.DLL+0x154e0)
#32 0x00007ffb3d7c485b (C:\WINDOWS\SYSTEM32\ntdll.dll+0x485b)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 14.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM-14\bin
clang: note: diagnostic msg:
********************

Preprocessed source and associated run script:
clang-14-crash.zip

@rjmccall I saw you made some changes to the non-Darwin runtime for llvm-14. I’d appreciate if you could take a look at this to see if this is related.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.crashPrefer [crash-on-valid] or [crash-on-invalid]objective-c

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions