[llvm-bugs] [Bug 28137] New: Clang crashes on dllexport class with a default argument constructor

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 15 00:29:40 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28137

            Bug ID: 28137
           Summary: Clang crashes on dllexport class with a default
                    argument constructor
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mattiwatti at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Code to reproduce:

template<typename T> 
constexpr T Ident(T t)
{
    return t;
}

class __declspec(dllexport) B
{
    B(int = 0) {}

    void f()
    {
        Ident(0);
    }
};

Command line used: clang -cc1 -triple x86_64-pc-windows-msvc19
-fms-compatibility -std=c++14 -emit-llvm foo.cpp -o foo.ll. I am using clang
3.9 (trunk 272663) on Windows, and clang 3.8 on Linux.
Compiling the above asserts with DefaultArg && "sema forgot to instantiate
default args".

Stacktrace:

[...snip CRT spew...]
clang.exe!`anonymous namespace'::MicrosoftCXXABI::getAddrOfCXXCtorClosure(const
clang::CXXConstructorDecl * CD, clang::CXXCtorType CT) Line 3864
clang.exe!`anonymous namespace'::MicrosoftCXXABI::EmitCXXConstructors(const
clang::CXXConstructorDecl * D) Line 1199
clang.exe!clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl * D) Line
3795
clang.exe!`anonymous namespace'::CodeGeneratorImpl::EmitDeferredDecls() Line
162
clang.exe!`anonymous
namespace'::CodeGeneratorImpl::HandlingTopLevelDeclRAII::~HandlingTopLevelDeclRAII()
Line 57
clang.exe!`anonymous
namespace'::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef DG) Line
150
clang.exe!clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef D)
Line 120
clang.exe!clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation
PointOfInstantiation, clang::FunctionDecl * Function, bool Recursive, bool
DefinitionRequired, bool AtEndOfTU) Line 3722
clang.exe!clang::Sema::MarkFunctionReferenced(clang::SourceLocation Loc,
clang::FunctionDecl * Func, bool MightBeOdrUse) Line 13076
clang.exe!clang::Sema::MarkAnyDeclReferenced(clang::SourceLocation Loc,
clang::Decl * D, bool MightBeOdrUse) Line 14041
clang.exe!MarkExprReferenced(clang::Sema & SemaRef, clang::SourceLocation Loc,
clang::Decl * D, clang::Expr * E, bool MightBeOdrUse) Line 13975
clang.exe!clang::Sema::MarkDeclRefReferenced(clang::DeclRefExpr * E) Line 14006
clang.exe!clang::Sema::FixOverloadedFunctionReference(clang::Expr * E,
clang::DeclAccessPair Found, clang::FunctionDecl * Fn) Line 13039
clang.exe!FinishOverloadedCallExpr(clang::Sema & SemaRef, clang::Scope * S,
clang::Expr * Fn, clang::UnresolvedLookupExpr * ULE, clang::SourceLocation
LParenLoc, llvm::MutableArrayRef<clang::Expr *> Args, clang::SourceLocation
RParenLoc, clang::Expr * ExecConfig, clang::OverloadCandidateSet *
CandidateSet, clang::OverloadCandidate * * Best, clang::OverloadingResult
OverloadResult, bool AllowTypoCorrection) Line 11346
clang.exe!clang::Sema::BuildOverloadedCallExpr(clang::Scope * S, clang::Expr *
Fn, clang::UnresolvedLookupExpr * ULE, clang::SourceLocation LParenLoc,
llvm::MutableArrayRef<clang::Expr *> Args, clang::SourceLocation RParenLoc,
clang::Expr * ExecConfig, bool AllowTypoCorrection, bool CalleesAddressIsTaken)
Line 11451
clang.exe!clang::Sema::ActOnCallExpr(clang::Scope * S, clang::Expr * Fn,
clang::SourceLocation LParenLoc, llvm::MutableArrayRef<clang::Expr *> ArgExprs,
clang::SourceLocation RParenLoc, clang::Expr * ExecConfig, bool IsExecConfig)
Line 5194
clang.exe!clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr
*,1> LHS) Line 1602
clang.exe!clang::Parser::ParseCastExpression(bool isUnaryExpression, bool
isAddressOfOperand, bool & NotCastExpr, clang::Parser::TypeCastState
isTypeCast) Line 1369
clang.exe!clang::Parser::ParseCastExpression(bool isUnaryExpression, bool
isAddressOfOperand, clang::Parser::TypeCastState isTypeCast) Line 482
clang.exe!clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState
isTypeCast) Line 172
clang.exe!clang::Parser::ParseExpression(clang::Parser::TypeCastState
isTypeCast) Line 122
clang.exe!clang::Parser::ParseExprStatement() Line 403
clang.exe!clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt
*,32> & Stmts, clang::Parser::AllowedContsructsKind Allowed,
clang::SourceLocation * TrailingElseLoc,
clang::Parser::ParsedAttributesWithRange & Attrs) Line 225
clang.exe!clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt
*,32> & Stmts, clang::Parser::AllowedContsructsKind Allowed,
clang::SourceLocation * TrailingElseLoc) Line 116
clang.exe!clang::Parser::ParseCompoundStatementBody(bool isStmtExpr) Line 987
clang.exe!clang::Parser::ParseFunctionStatementBody(clang::Decl * Decl,
clang::Parser::ParseScope & BodyScope) Line 1940
clang.exe!clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod & LM)
Line 558
clang.exe!clang::Parser::LexedMethod::ParseLexedMethodDefs() Line 258
clang.exe!clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass &
Class) Line 485
clang.exe!clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation
RecordLoc, clang::SourceLocation AttrFixitLoc,
clang::Parser::ParsedAttributesWithRange & Attrs, unsigned int TagType,
clang::Decl * TagDecl) Line 3138
clang.exe!clang::Parser::ParseClassSpecifier(clang::tok::TokenKind TagTokKind,
clang::SourceLocation StartLoc, clang::DeclSpec & DS, const
clang::Parser::ParsedTemplateInfo & TemplateInfo, clang::AccessSpecifier AS,
bool EnteringContext, clang::Parser::DeclSpecContext DSC,
clang::Parser::ParsedAttributesWithRange & Attributes) Line 1777
clang.exe!clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec & DS, const
clang::Parser::ParsedTemplateInfo & TemplateInfo, clang::AccessSpecifier AS,
clang::Parser::DeclSpecContext DSContext, clang::Parser::LateParsedAttrList *
LateAttrs) Line 3410
clang.exe!clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange
& attrs, clang::ParsingDeclSpec & DS, clang::AccessSpecifier AS) Line 881
clang.exe!clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange
& attrs, clang::ParsingDeclSpec * DS, clang::AccessSpecifier AS) Line 956
clang.exe!clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange
& attrs, clang::ParsingDeclSpec * DS) Line 808
clang.exe!clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>
& Result) Line 595
clang.exe!clang::ParseAST(clang::Sema & S, bool PrintStats, bool
SkipFunctionBodies) Line 160
clang.exe!clang::ASTFrontendAction::ExecuteAction() Line 558
clang.exe!clang::CodeGenAction::ExecuteAction() Line 851
clang.exe!clang::FrontendAction::Execute() Line 461
clang.exe!clang::CompilerInstance::ExecuteAction(clang::FrontendAction & Act)
Line 877
clang.exe!clang::ExecuteCompilerInvocation(clang::CompilerInstance * Clang)
Line 241
clang.exe!cc1_main(llvm::ArrayRef<char const *> Argv, const char * Argv0, void
* MainAddr) Line 116
clang.exe!ExecuteCC1Tool(llvm::ArrayRef<char const *> argv, llvm::StringRef
Tool) Line 301
clang.exe!main(int argc_, const char * * argv_) Line 382
[...snip CRT spew...]


The crash can be made to go away by doing one of the following:
(1) remove the dllexport attribute
(2) change the constructor to either B(int) or B()
(3) remove the constexpr keyword
(4) make Ident() a non-template function (in that case, constexpr is OK), or
(5) make an explicit specialization i.e. template<> int Ident(int) (constexpr
or not) and instantiate that.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160615/c259cbeb/attachment-0001.html>


More information about the llvm-bugs mailing list