New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 22931 - Assertion `isa<LabelDecl>(D) && "declaration not instantiated in this scope"' failed.
Summary: Assertion `isa<LabelDecl>(D) && "declaration not instantiated in this scope"'...
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: Frontend (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-16 19:24 PDT by rtrieu
Modified: 2015-03-18 16:53 PDT (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rtrieu 2015-03-16 19:24:22 PDT
clang: ../tools/clang/lib/Sema/SemaTemplateInstantiate.cpp:2798: llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *clang::LocalInstantiationScope::findInstantiationOf(const clang::Decl *): Assertion `isa<LabelDecl>(D) && "declaration not instantiated in this scope"' failed.

Commandline:
clang -cc1 -fsyntax-only fs.cpp

Repro:
#define THREAD_ANNOTATION_ATTRIBUTE__(x)   __attribute__((x))

#define EXCLUSIVE_LOCKS_REQUIRED(x) \
      THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x))
#define UNLOCK_FUNCTION(x) \
      THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(x))

struct F {
  void mutex();
};

template <typename A>
class TemplateClass {
 public:
  template <typename B>
  static void Function(F* file)
      EXCLUSIVE_LOCKS_REQUIRED(file->mutex()) UNLOCK_FUNCTION(file->mutex()) {
  }
};

void test() {
  TemplateClass<int> X;
}

Backtrace:
#1 0x14bf78b SignalHandler(int) (/usr/local/bin/clang-3.5+0x14bf78b)
#2 0x7fb9b9bcf340 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)
#3 0x7fb9b90fbcc9 gsignal /build/buildd/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#4 0x7fb9b90ff0d8 abort /build/buildd/eglibc-2.19/stdlib/abort.c:91:0
#5 0x7fb9b90f4b86 __assert_fail_base /build/buildd/eglibc-2.19/assert/assert.c:92:0
#6 0x7fb9b90f4c32 (/lib/x86_64-linux-gnu/libc.so.6+0x2fc32)
#7 0x2427bee clang::LocalInstantiationScope::findInstantiationOf(clang::Decl const*) (/usr/local/bin/clang-3.5+0x2427bee)
#8 0x244568b clang::Sema::FindInstantiatedDecl(clang::SourceLocation, clang::NamedDecl*, clang::MultiLevelTemplateArgumentList const&) (/usr/local/bin/clang-3.5+0x244568b)
#9 0x24282c4 (anonymous namespace)::TemplateInstantiator::TransformDecl(clang::SourceLocation, clang::Decl*) (/usr/local/bin/clang-3.5+0x24282c4)
#10 0x24376a6 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformDeclRefExpr(clang::DeclRefExpr*) (/usr/local/bin/clang-3.5+0x24376a6)
#11 0x242e96c clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformMemberExpr(clang::MemberExpr*) (/usr/local/bin/clang-3.5+0x242e96c)
#12 0x2436b4e clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*) (/usr/local/bin/clang-3.5+0x2436b4e)
#13 0x242c3d4 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCXXMemberCallExpr(clang::CXXMemberCallExpr*) (/usr/local/bin/clang-3.5+0x242c3d4)
#14 0x2423411 clang::Sema::SubstExpr(clang::Expr*, clang::MultiLevelTemplateArgumentList const&) (/usr/local/bin/clang-3.5+0x2423411)
#15 0x24435b4 clang::sema::instantiateTemplateAttribute(clang::Attr const*, clang::ASTContext&, clang::Sema&, clang::MultiLevelTemplateArgumentList const&) (/usr/local/bin/clang-3.5+0x24435b4)
#16 0x241fd6b clang::Sema::InstantiateClass(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/usr/local/bin/clang-3.5+0x241fd6b)
#17 0x24218fb clang::Sema::InstantiateClassTemplateSpecialization(clang::SourceLocation, clang::ClassTemplateSpecializationDecl*, clang::TemplateSpecializationKind, bool) (/usr/local/bin/clang-3.5+0x24218fb)
#18 0x24855cd clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::TypeDiagnoser&) (/usr/local/bin/clang-3.5+0x24855cd)
#19 0x2485390 clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::TypeDiagnoser&) (/usr/local/bin/clang-3.5+0x2485390)
#20 0x2476255 clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, unsigned int) (/usr/local/bin/clang-3.5+0x2476255)
#21 0x20cc797 clang::Sema::ActOnUninitializedDecl(clang::Decl*, bool) (/usr/local/bin/clang-3.5+0x20cc797)
#22 0x1e818ba clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/usr/local/bin/clang-3.5+0x1e818ba)
#23 0x1e7fad6 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/usr/local/bin/clang-3.5+0x1e7fad6)
#24 0x1e7b677 clang::Parser::ParseSimpleDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, bool, clang::Parser::ForRangeInit*) (/usr/local/bin/clang-3.5+0x1e7b677)
#25 0x1e7b2e7 clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) (/usr/local/bin/clang-3.5+0x1e7b2e7)
#26 0x1ee341f clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) (/usr/local/bin/clang-3.5+0x1ee341f)
#27 0x1ee251f clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*) (/usr/local/bin/clang-3.5+0x1ee251f)
#28 0x1ee9bb4 clang::Parser::ParseCompoundStatementBody(bool) (/usr/local/bin/clang-3.5+0x1ee9bb4)
#29 0x1eea583 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/usr/local/bin/clang-3.5+0x1eea583)
#30 0x1e6e3df clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/usr/local/bin/clang-3.5+0x1e6e3df)
#31 0x1e7f9e0 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/usr/local/bin/clang-3.5+0x1e7f9e0)
#32 0x1e6da26 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/usr/local/bin/clang-3.5+0x1e6da26)
#33 0x1e6d46c clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/usr/local/bin/clang-3.5+0x1e6d46c)
#34 0x1e6c645 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/usr/local/bin/clang-3.5+0x1e6c645)
#35 0x1e6bbd1 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) (/usr/local/bin/clang-3.5+0x1e6bbd1)
#36 0x1e67c46 clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/bin/clang-3.5+0x1e67c46)
#37 0x164ce6e clang::FrontendAction::Execute() (/usr/local/bin/clang-3.5+0x164ce6e)
#38 0x161e68c clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/bin/clang-3.5+0x161e68c)
#39 0x16cc0e4 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local/bin/clang-3.5+0x16cc0e4)
#40 0x6e20b2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/local/bin/clang-3.5+0x6e20b2)
#41 0x6e102f main (/usr/local/bin/clang-3.5+0x6e102f)
Comment 1 rtrieu 2015-03-16 19:27:37 PDT
Possibly related to:
https://llvm.org/bugs/show_bug.cgi?id=21870

The same assertion is hit, both through TreeTransform, but there are differences in the backtrace.
Comment 2 rtrieu 2015-03-18 16:53:24 PDT
Fixed in r232675