[cfe-dev] libclang crashed on nullptr

Xavier Wang weasley.wx at gmail.com
Thu Jul 31 20:48:32 PDT 2014


Hi,

I have found a crash on nullptr when parse Qt header files.

it caused by a dyn_cast on nullptr, at here (Line 9240 in SemaDecl.cpp):

-------------------------
/// FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform
/// any semantic actions necessary after any initializer has been attached.
void
Sema::FinalizeDeclaration(Decl *ThisDecl) {
  // Note that we are no longer parsing the initializer for this declaration.
  ParsingInitForAutoVars.erase(ThisDecl);

  VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDecl);
  if (!VD)
    return;

  checkAttributesAfterMerging(*this, *VD);

  // Static locals inherit dll attributes from their function.
  if (VD->isStaticLocal()) {
    if (FunctionDecl *FD =
            dyn_cast<FunctionDecl>(VD->getParentFunctionOrMethod())) {
// !!!here!!!
------------------------

maybe dyn_cast_or_null is needed? or is there something wrong with it?

the source code is the preprocessed header file for Qt 5.2, it's
5.74MB+, So I can not upload it.

the stack dump is:

> libclang.dll!llvm::isa_impl_cl<clang::FunctionDecl,clang::DeclContext const *>::doit(const clang::DeclContext * Val) Line 94 C++
  libclang.dll!llvm::isa_impl_wrap<clang::FunctionDecl,clang::DeclContext
const *,clang::DeclContext const *>::doit(const clang::DeclContext *
const & Val) Line 122 C++
  libclang.dll!llvm::isa_impl_wrap<clang::FunctionDecl,clang::DeclContext
* const,clang::DeclContext const *>::doit(clang::DeclContext * const &
Val) Line 114 C++
  libclang.dll!llvm::isa<clang::FunctionDecl,clang::DeclContext
*>(clang::DeclContext * const & Val) Line 134 C++
  libclang.dll!llvm::dyn_cast<clang::FunctionDecl,clang::DeclContext>(clang::DeclContext
* Val) Line 278 C++
  libclang.dll!clang::Sema::FinalizeDeclaration(clang::Decl *
ThisDecl) Line 9241 C++
  libclang.dll!clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier
AS, clang::AttributeList * AccessAttrs, const
clang::Parser::ParsedTemplateInfo & TemplateInfo,
clang::ParsingDeclRAIIObject * TemplateDiags) Line 2380 C++
  libclang.dll!clang::Parser::ParseSingleDeclarationAfterTemplate(unsigned
int Context, const clang::Parser::ParsedTemplateInfo & TemplateInfo,
clang::ParsingDeclRAIIObject & DiagsFromTParams, clang::SourceLocation
& DeclEnd, clang::AccessSpecifier AS, clang::AttributeList *
AccessAttrs) Line 173 C++
  libclang.dll!clang::Parser::ParseTemplateDeclarationOrSpecialization(unsigned
int Context, clang::SourceLocation & DeclEnd, clang::AccessSpecifier
AS, clang::AttributeList * AccessAttrs) Line 145 C++
  libclang.dll!clang::Parser::ParseDeclarationStartingWithTemplate(unsigned
int Context, clang::SourceLocation & DeclEnd, clang::AccessSpecifier
AS, clang::AttributeList * AccessAttrs) Line 39 C++
  libclang.dll!clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier
AS, clang::AttributeList * AccessAttrs, const
clang::Parser::ParsedTemplateInfo & TemplateInfo,
clang::ParsingDeclRAIIObject * TemplateDiags) Line 2083 C++
  libclang.dll!clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation
RecordLoc, clang::SourceLocation AttrFixitLoc,
clang::Parser::ParsedAttributesWithRange & Attrs, unsigned int
TagType, clang::Decl * TagDecl) Line 2709 C++
  libclang.dll!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 1639 C++
  libclang.dll!clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec
& DS, const clang::Parser::ParsedTemplateInfo & TemplateInfo,
clang::AccessSpecifier AS, clang::Parser::DeclSpecContext DSContext,
clang::Parser::LateParsedAttrList * LateAttrs) Line 3111 C++
  libclang.dll!clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange
& attrs, clang::ParsingDeclSpec & DS, clang::AccessSpecifier AS) Line
836 C++
  libclang.dll!clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange
& attrs, clang::ParsingDeclSpec * DS, clang::AccessSpecifier AS) Line
904 C++
  libclang.dll!clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange
& attrs, clang::ParsingDeclSpec * DS) Line 762 C++
  libclang.dll!clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>
& Result) Line 559 C++
  libclang.dll!clang::ParseAST(clang::Sema & S, bool PrintStats, bool
SkipFunctionBodies) Line 145 C++
  libclang.dll!clang::ASTFrontendAction::ExecuteAction() Line 514 C++
  libclang.dll!clang::FrontendAction::Execute() Line 415 C++
  libclang.dll!clang::ASTUnit::Parse(llvm::MemoryBuffer *
OverrideMainBuffer) Line 1152 C++
  libclang.dll!clang::ASTUnit::LoadFromCompilerInvocation(bool
PrecompilePreamble) Line 1915 C++
  libclang.dll!clang::ASTUnit::LoadFromCommandLine(const char * *
ArgBegin, const char * * ArgEnd,
llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> Diags,
llvm::StringRef ResourceFilesPath, bool OnlyLocalDecls, bool
CaptureDiagnostics,
llvm::ArrayRef<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,llvm::MemoryBuffer *> > RemappedFiles, bool
RemappedFilesKeepOriginalName, bool PrecompilePreamble,
clang::TranslationUnitKind TUKind, bool CacheCodeCompletionResults,
bool IncludeBriefCommentsInCodeCompletion, bool
AllowPCHWithCompilerErrors, bool SkipFunctionBodies, bool
UserFilesAreVolatile, bool ForSerialization,
std::unique_ptr<clang::ASTUnit,std::default_delete<clang::ASTUnit> > *
ErrAST) Line 2030 C++
  libclang.dll!clang_parseTranslationUnit_Impl(void * UserData) Line 2925 C++
  libclang.dll!llvm::CrashRecoveryContext::RunSafelyOnThread::__l3::<lambda>()
Line 96 C++
  libclang.dll!llvm::function_ref<void
__cdecl(void)>::callback_fn<void <lambda>(void) >(int callable) Line
77 C++
  libclang.dll!llvm::function_ref<void __cdecl(void)>::operator()() Line 85 C++
  libclang.dll!llvm::function_ref<void
__cdecl(void)>::callback_fn<llvm::function_ref<void __cdecl(void)>
>(int callable) Line 77 C++
  libclang.dll!llvm::function_ref<void __cdecl(void)>::operator()() Line 85 C++
  libclang.dll!llvm::function_ref<void
__cdecl(void)>::callback_fn<llvm::function_ref<void __cdecl(void)>
>(int callable) Line 77 C++
  libclang.dll!llvm::function_ref<void __cdecl(void)>::operator()() Line 85 C++
  libclang.dll!llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void
__cdecl(void)> Fn) Line 319 C++
  libclang.dll!RunSafelyOnThread_Dispatch(void * UserData) Line 366 C++
  libclang.dll!ThreadCallback(void * param) Line 81 C++
  [外部代码]
  [下面的框架可能不正确和/或缺失,没有为 kernel32.dll 加载符号]


Anyone can help me?

-- 
regards,
Xavier Wang.




More information about the cfe-dev mailing list