Possible bug in clang when invoked from dll

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible bug in clang when invoked from dll

David Chisnall via cfe-dev
Hi guys,

I'm having an issue with clang/llvm since I upgraded my compiler from VS2013 to VS2015. I'm invoking clang programmatically to compile C++ source files and up till now it has worked fine but since the upgrade and recompiling all the clang/llvm libraries I'm getting some errors deep inside the clang/llvm source without having changed any code on my end. The problem I'm facing right now is an assertion being triggered in an llvm class:

My code is very simple; I literally just invoke the compiler. I've pastebinned example dll code here: http://pastebin.com/wpS6VX5N I would greatly appreciate it if someone could take a quick look to make sure I'm not making a mistake, but I don't think I am.

A weird thing is that when this invocation code is built into a debug dll with optimization disabled (as I need in my project), I hit the previously mentioned assert when running, but it works perfectly when it's compiled straight into a debug executable. If I set the optimization level to O2 instead of disabled on the dll then it also works fine. 

Does anyone have any idea about what could be causing this? 

(I've resent this message from a different address because it seems I'm having some issues receiving emails despite being subscribed to the list)

Assertion failed: HasHungOffUses && "alloc must have hung off uses", file F:\Cla
nggit\llvm\lib\IR\User.cpp, line 44

Here is the complete call stack up till the assertion: 

ucrtbased.dll!___threadid () Unknown
  ucrtbased.dll!___acrt_report_runtime_error () Unknown
  ucrtbased.dll!_abort () Unknown
  ucrtbased.dll!__crt_char_traits<char>::tcsncat_s<char * &,unsigned int const &,char const * const &,unsigned int const >(char * &,unsigned int const &,char const * const &,unsigned int const &&) Unknown
  ucrtbased.dll!__get_wide_winmain_command_line () Unknown
  ucrtbased.dll!__get_wide_winmain_command_line () Unknown
  ucrtbased.dll!__wassert () Unknown
  Plugin_Clang_d.dll!llvm::User::allocHungoffUses(unsigned int N, bool IsPhi) Line 44 C++
> Plugin_Clang_d.dll!llvm::Function::allocHungoffUselist() Line 1234 C++
  Plugin_Clang_d.dll!llvm::Function::setHungoffOperand<0>(llvm::Constant * C) Line 1247 C++
  Plugin_Clang_d.dll!llvm::Function::setPersonalityFn(llvm::Constant * Fn) Line 1205 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::getInvokeDestImpl() Line 722 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::getInvokeDest() Line 1412 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCall(const clang::CodeGen::CGFunctionInfo & CallInfo, const clang::CodeGen::CGCallee & Callee, clang::CodeGen::ReturnValueSlot ReturnValue, const clang::CodeGen::CallArgList & CallArgs, llvm::Instruction * * callOrInvoke) Line 4090 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorCall(const clang::CXXMethodDecl * MD, const clang::CodeGen::CGCallee & Callee, clang::CodeGen::ReturnValueSlot ReturnValue, llvm::Value * This, llvm::Value * ImplicitParam, clang::QualType ImplicitParamTy, const clang::CallExpr * CE, clang::CodeGen::CallArgList * RtlArgs) Line 91 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr(const clang::CallExpr * CE, const clang::CXXMethodDecl * MD, clang::CodeGen::ReturnValueSlot ReturnValue, bool HasQualifier, clang::NestedNameSpecifier * Qualifier, bool IsArrow, const clang::Expr * Base) Line 385 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCXXMemberCallExpr(const clang::CXXMemberCallExpr * CE, clang::CodeGen::ReturnValueSlot ReturnValue) Line 188 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCallExpr(const clang::CallExpr * E, clang::CodeGen::ReturnValueSlot ReturnValue) Line 3870 C++
  Plugin_Clang_d.dll!`anonymous namespace'::ScalarExprEmitter::VisitCallExpr(const clang::CallExpr * E) Line 405 C++
  Plugin_Clang_d.dll!clang::StmtVisitorBase<clang::make_ptr,`anonymous namespace'::ScalarExprEmitter,llvm::Value *>::VisitCXXMemberCallExpr(clang::CXXMemberCallExpr * S) Line 339 C++
  Plugin_Clang_d.dll!clang::StmtVisitorBase<clang::make_ptr,`anonymous namespace'::ScalarExprEmitter,llvm::Value *>::Visit(clang::Stmt * S) Line 339 C++
  Plugin_Clang_d.dll!`anonymous namespace'::ScalarExprEmitter::Visit(clang::Expr * E) Line 260 C++
  Plugin_Clang_d.dll!`anonymous namespace'::ScalarExprEmitter::VisitCastExpr(clang::CastExpr * CE) Line 1501 C++
  Plugin_Clang_d.dll!clang::StmtVisitorBase<clang::make_ptr,`anonymous namespace'::ScalarExprEmitter,llvm::Value *>::VisitImplicitCastExpr(clang::ImplicitCastExpr * S) Line 423 C++
  Plugin_Clang_d.dll!clang::StmtVisitorBase<clang::make_ptr,`anonymous namespace'::ScalarExprEmitter,llvm::Value *>::Visit(clang::Stmt * S) Line 423 C++
  Plugin_Clang_d.dll!`anonymous namespace'::ScalarExprEmitter::Visit(clang::Expr * E) Line 260 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitScalarExpr(const clang::Expr * E, bool IgnoreResultAssign) Line 3621 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(const clang::Expr * E) Line 123 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr(const clang::Expr * Cond, llvm::BasicBlock * TrueBlock, llvm::BasicBlock * FalseBlock, unsigned __int64 TrueCount) Line 1508 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr(const clang::Expr * Cond, llvm::BasicBlock * TrueBlock, llvm::BasicBlock * FalseBlock, unsigned __int64 TrueCount) Line 1430 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitIfStmt(const clang::IfStmt & S) Line 656 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitStmt(const clang::Stmt * S) Line 134 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(const clang::CompoundStmt & S, bool GetLast, clang::CodeGen::AggValueSlot AggSlot) Line 381 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList & Args, const clang::Stmt * Body) Line 990 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl GD, llvm::Function * Fn, const clang::CodeGen::CGFunctionInfo & FnInfo) Line 1161 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl GD, llvm::GlobalValue * GV) Line 3052 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl GD, llvm::GlobalValue * GV) Line 1888 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenModule::EmitDeferred() Line 1360 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenModule::Release() Line 377 C++
  Plugin_Clang_d.dll!`anonymous namespace'::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext & Ctx) Line 261 C++
  Plugin_Clang_d.dll!clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext & C) Line 205 C++
  Plugin_Clang_d.dll!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 159 C++
  Plugin_Clang_d.dll!clang::ASTFrontendAction::ExecuteAction() Line 567 C++
  Plugin_Clang_d.dll!clang::CodeGenAction::ExecuteAction() Line 991 C++
  Plugin_Clang_d.dll!clang::FrontendAction::Execute() Line 468 C++
  Plugin_Clang_d.dll!clang::CompilerInstance::ExecuteAction(clang::FrontendAction & Act) Line 951 C++
  Plugin_Clang_d.dll!clang::ExecuteCompilerInvocation(clang::CompilerInstance * Clang) Line 249 C++
  Plugin_Clang_d.dll!Compiler::compile(const char * * ArgBegin, const char * * ArgEnd, const char * Argv0, ASTVisitor & visitor) Line 536 C++
  Plugin_Clang_d.dll!Compiler::compile(const char * srcFilePath, const char * outputFilePath, Scripta::result & result, const char * * args, unsigned int argsSize) Line 287 C++
  scripta-example.exe!ScriptaPlatform::compile(const char * filePath, const char * outputFile) Line 233 C++
  scripta-example.exe!ScriptaPlatform::load(const char * filename) Line 395 C++
  scripta-example.exe!main() Line 380 C++
  [External Code]

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in clang when invoked from dll

David Chisnall via cfe-dev
I solved this problem and I'll explain in case anyone else using VS2015 runs into the same issue. You need to set SDL to disabled in VS2015 otherwise the hasHungOffUses value gets incorrectly memset to zero after the call to the User operator new. If you disable sdl then clang works as expected. 

On Thu, Mar 9, 2017 at 11:44 PM, Kim R <[hidden email]> wrote:
Hi guys,

I'm having an issue with clang/llvm since I upgraded my compiler from VS2013 to VS2015. I'm invoking clang programmatically to compile C++ source files and up till now it has worked fine but since the upgrade and recompiling all the clang/llvm libraries I'm getting some errors deep inside the clang/llvm source without having changed any code on my end. The problem I'm facing right now is an assertion being triggered in an llvm class:

My code is very simple; I literally just invoke the compiler. I've pastebinned example dll code here: http://pastebin.com/wpS6VX5N I would greatly appreciate it if someone could take a quick look to make sure I'm not making a mistake, but I don't think I am.

A weird thing is that when this invocation code is built into a debug dll with optimization disabled (as I need in my project), I hit the previously mentioned assert when running, but it works perfectly when it's compiled straight into a debug executable. If I set the optimization level to O2 instead of disabled on the dll then it also works fine. 

Does anyone have any idea about what could be causing this? 

(I've resent this message from a different address because it seems I'm having some issues receiving emails despite being subscribed to the list)

Assertion failed: HasHungOffUses && "alloc must have hung off uses", file F:\Cla
nggit\llvm\lib\IR\User.cpp, line 44

Here is the complete call stack up till the assertion: 

ucrtbased.dll!___threadid () Unknown
  ucrtbased.dll!___acrt_report_runtime_error () Unknown
  ucrtbased.dll!_abort () Unknown
  ucrtbased.dll!__crt_char_traits<char>::tcsncat_s<char * &,unsigned int const &,char const * const &,unsigned int const >(char * &,unsigned int const &,char const * const &,unsigned int const &&) Unknown
  ucrtbased.dll!__get_wide_winmain_command_line () Unknown
  ucrtbased.dll!__get_wide_winmain_command_line () Unknown
  ucrtbased.dll!__wassert () Unknown
  Plugin_Clang_d.dll!llvm::User::allocHungoffUses(unsigned int N, bool IsPhi) Line 44 C++
> Plugin_Clang_d.dll!llvm::Function::allocHungoffUselist() Line 1234 C++
  Plugin_Clang_d.dll!llvm::Function::setHungoffOperand<0>(llvm::Constant * C) Line 1247 C++
  Plugin_Clang_d.dll!llvm::Function::setPersonalityFn(llvm::Constant * Fn) Line 1205 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::getInvokeDestImpl() Line 722 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::getInvokeDest() Line 1412 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCall(const clang::CodeGen::CGFunctionInfo & CallInfo, const clang::CodeGen::CGCallee & Callee, clang::CodeGen::ReturnValueSlot ReturnValue, const clang::CodeGen::CallArgList & CallArgs, llvm::Instruction * * callOrInvoke) Line 4090 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorCall(const clang::CXXMethodDecl * MD, const clang::CodeGen::CGCallee & Callee, clang::CodeGen::ReturnValueSlot ReturnValue, llvm::Value * This, llvm::Value * ImplicitParam, clang::QualType ImplicitParamTy, const clang::CallExpr * CE, clang::CodeGen::CallArgList * RtlArgs) Line 91 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr(const clang::CallExpr * CE, const clang::CXXMethodDecl * MD, clang::CodeGen::ReturnValueSlot ReturnValue, bool HasQualifier, clang::NestedNameSpecifier * Qualifier, bool IsArrow, const clang::Expr * Base) Line 385 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCXXMemberCallExpr(const clang::CXXMemberCallExpr * CE, clang::CodeGen::ReturnValueSlot ReturnValue) Line 188 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCallExpr(const clang::CallExpr * E, clang::CodeGen::ReturnValueSlot ReturnValue) Line 3870 C++
  Plugin_Clang_d.dll!`anonymous namespace'::ScalarExprEmitter::VisitCallExpr(const clang::CallExpr * E) Line 405 C++
  Plugin_Clang_d.dll!clang::StmtVisitorBase<clang::make_ptr,`anonymous namespace'::ScalarExprEmitter,llvm::Value *>::VisitCXXMemberCallExpr(clang::CXXMemberCallExpr * S) Line 339 C++
  Plugin_Clang_d.dll!clang::StmtVisitorBase<clang::make_ptr,`anonymous namespace'::ScalarExprEmitter,llvm::Value *>::Visit(clang::Stmt * S) Line 339 C++
  Plugin_Clang_d.dll!`anonymous namespace'::ScalarExprEmitter::Visit(clang::Expr * E) Line 260 C++
  Plugin_Clang_d.dll!`anonymous namespace'::ScalarExprEmitter::VisitCastExpr(clang::CastExpr * CE) Line 1501 C++
  Plugin_Clang_d.dll!clang::StmtVisitorBase<clang::make_ptr,`anonymous namespace'::ScalarExprEmitter,llvm::Value *>::VisitImplicitCastExpr(clang::ImplicitCastExpr * S) Line 423 C++
  Plugin_Clang_d.dll!clang::StmtVisitorBase<clang::make_ptr,`anonymous namespace'::ScalarExprEmitter,llvm::Value *>::Visit(clang::Stmt * S) Line 423 C++
  Plugin_Clang_d.dll!`anonymous namespace'::ScalarExprEmitter::Visit(clang::Expr * E) Line 260 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitScalarExpr(const clang::Expr * E, bool IgnoreResultAssign) Line 3621 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(const clang::Expr * E) Line 123 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr(const clang::Expr * Cond, llvm::BasicBlock * TrueBlock, llvm::BasicBlock * FalseBlock, unsigned __int64 TrueCount) Line 1508 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr(const clang::Expr * Cond, llvm::BasicBlock * TrueBlock, llvm::BasicBlock * FalseBlock, unsigned __int64 TrueCount) Line 1430 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitIfStmt(const clang::IfStmt & S) Line 656 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitStmt(const clang::Stmt * S) Line 134 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(const clang::CompoundStmt & S, bool GetLast, clang::CodeGen::AggValueSlot AggSlot) Line 381 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList & Args, const clang::Stmt * Body) Line 990 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl GD, llvm::Function * Fn, const clang::CodeGen::CGFunctionInfo & FnInfo) Line 1161 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl GD, llvm::GlobalValue * GV) Line 3052 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl GD, llvm::GlobalValue * GV) Line 1888 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenModule::EmitDeferred() Line 1360 C++
  Plugin_Clang_d.dll!clang::CodeGen::CodeGenModule::Release() Line 377 C++
  Plugin_Clang_d.dll!`anonymous namespace'::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext & Ctx) Line 261 C++
  Plugin_Clang_d.dll!clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext & C) Line 205 C++
  Plugin_Clang_d.dll!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 159 C++
  Plugin_Clang_d.dll!clang::ASTFrontendAction::ExecuteAction() Line 567 C++
  Plugin_Clang_d.dll!clang::CodeGenAction::ExecuteAction() Line 991 C++
  Plugin_Clang_d.dll!clang::FrontendAction::Execute() Line 468 C++
  Plugin_Clang_d.dll!clang::CompilerInstance::ExecuteAction(clang::FrontendAction & Act) Line 951 C++
  Plugin_Clang_d.dll!clang::ExecuteCompilerInvocation(clang::CompilerInstance * Clang) Line 249 C++
  Plugin_Clang_d.dll!Compiler::compile(const char * * ArgBegin, const char * * ArgEnd, const char * Argv0, ASTVisitor & visitor) Line 536 C++
  Plugin_Clang_d.dll!Compiler::compile(const char * srcFilePath, const char * outputFilePath, Scripta::result & result, const char * * args, unsigned int argsSize) Line 287 C++
  scripta-example.exe!ScriptaPlatform::compile(const char * filePath, const char * outputFile) Line 233 C++
  scripta-example.exe!ScriptaPlatform::load(const char * filename) Line 395 C++
  scripta-example.exe!main() Line 380 C++
  [External Code]


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev