Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++17] boost/url, Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file llvm/include/llvm/Support/Casting.h, line 579. #60182

Closed
DimitryAndric opened this issue Jan 21, 2023 · 4 comments
Labels
c++17 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party duplicate Resolved as duplicate

Comments

@DimitryAndric
Copy link
Collaborator

As reported in https://bugs.freebsd.org/269067, compiling boost 1.81.0 using clang with assertions enabled, results in an assertion while compiling boost_1_81_0/libs/url/src/src.cpp:

Starting program: /home/dim/ins/llvmorg-15-init-00019-g9d6a6159730/bin/clang -cc1 -triple x86_64-unknown-freebsd14.0 -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name src.cpp -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/usr0/freebsd/ports/work/usr/ports/devel/boost-libs/work/boost_1_81_0 -D LIBICONV_PLUG -D LIBICONV_PLUG -D LIBICONV_PLUG -D BOOST_ALL_NO_LIB=1 -D BOOST_URL_DYN_LINK=1 -D BOOST_URL_SOURCE -D NDEBUG -O3 -Wall -Wno-inline -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/usr0/freebsd/ports/work/usr/ports/devel/boost-libs/work/boost_1_81_0 -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -pthread -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ src-ba0416.cpp
Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /home/dim/src/llvm/llvm-project/llvm/include/llvm/Support/Casting.h, line 269.

Program received signal SIGABRT, Aborted.
Sent by thr_kill() from pid 88589 and user 1236.
thr_kill () at thr_kill.S:4
4       thr_kill.S: No such file or directory.
(gdb) bt
#0  thr_kill () at thr_kill.S:4
#1  0x0000000806a469c4 in __raise (s=s@entry=6) at /usr/src/lib/libc/gen/raise.c:52
#2  0x0000000806af7779 in abort () at /usr/src/lib/libc/stdlib/abort.c:67
#3  0x0000000806a297a1 in __assert (func=<optimized out>, file=<optimized out>, line=<optimized out>, failedexpr=<optimized out>) at /usr/src/lib/libc/gen/assert.c:51
#4  0x000000000529a5e8 in clang::Sema::BuildDelegatingInitializer(clang::TypeSourceInfo*, clang::Expr*, clang::CXXRecordDecl*) ()
#5  0x0000000005299ec9 in clang::Sema::BuildBaseInitializer(clang::QualType, clang::TypeSourceInfo*, clang::Expr*, clang::CXXRecordDecl*, clang::SourceLocation) ()
#6  0x00000000052988d8 in clang::Sema::BuildMemInitializer(clang::Decl*, clang::Scope*, clang::CXXScopeSpec&, clang::IdentifierInfo*, clang::OpaquePtr<clang::QualType>, clang::DeclSpec const&, clang::SourceLocation, clang::Expr*, clang::SourceLocation) ()
#7  0x000000000529934d in clang::Sema::ActOnMemInitializer(clang::Decl*, clang::Scope*, clang::CXXScopeSpec&, clang::IdentifierInfo*, clang::OpaquePtr<clang::QualType>, clang::DeclSpec const&, clang::SourceLocation, clang::SourceLocation, llvm::ArrayRef<clang::Expr*>, clang::SourceLocation, clang::SourceLocation) ()
#8  0x0000000004f81a04 in clang::Parser::ParseMemInitializer(clang::Decl*) ()
#9  0x0000000004f80e0c in clang::Parser::ParseConstructorInitializer(clang::Decl*) ()
#10 0x0000000004f6540f in clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) ()
#11 0x0000000004f9a164 in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) ()
#12 0x0000000004f645b0 in clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) ()
#13 0x0000000004f64072 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) ()
#14 0x0000000004f629fd in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) ()
#15 0x0000000004f6f1a1 in clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) ()
#16 0x0000000004f6e961 in clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) ()
#17 0x0000000004f935a9 in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributesWithRange&, clang::SourceLocation*) ()
#18 0x0000000004f6214f in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) ()
#19 0x0000000004f6f1a1 in clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) ()
#20 0x0000000004f6e961 in clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) ()
#21 0x0000000004f935a9 in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributesWithRange&, clang::SourceLocation*) ()
#22 0x0000000004f6214f in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) ()
#23 0x0000000004f60874 in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) ()
#24 0x0000000004f5a78d in clang::ParseAST(clang::Sema&, bool, bool) ()
#25 0x0000000004671fc3 in clang::FrontendAction::Execute() ()
#26 0x00000000045fc869 in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) ()
#27 0x0000000004723621 in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) ()
#28 0x000000000202682d in cc1_main(llvm::ArrayRef<char const*>, char const*, void*) ()
#29 0x000000000202408a in ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) ()
#30 0x0000000002023e12 in main ()

Minimized test case:

// clang -cc1 -triple x86_64-- -S -O0 -std=c++17 boost-url-min.cpp

namespace urls {
struct segments_view {
  segments_view();
};
struct segments_encoded_view {
  operator segments_view();
} __trans_tmp_1;
segments_view::segments_view() : segments_view(__trans_tmp_1) {}
} // namespace urls

This reproduces with both the oldest and the newest versions of clang that I have, so it is a very long standing bug. It is also specifically C++17 related, since using -std=c++11 or -std=c++14 makes the assertion disappear.

@DimitryAndric DimitryAndric added c++17 clang:frontend Language frontend issues, e.g. anything involving "Sema" new issue labels Jan 21, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 21, 2023

@llvm/issue-subscribers-c-17

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 21, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented Jan 21, 2023

This looks like a duplicate of: #39319

but the reproducer looks helpful.

@DimitryAndric
Copy link
Collaborator Author

Closing in favor of #39319.

@DimitryAndric DimitryAndric closed this as not planned Won't fix, can't repro, duplicate, stale Jan 21, 2023
shafik added a commit that referenced this issue Dec 8, 2023
…ction if we are going use copy elision

ResolveConstructorOverload needs to check properly if we are going to use copy
elision we can't use a conversion function.

This fixes:

#39319
#60182
#62157
#64885
#65568

Differential Revision: https://reviews.llvm.org/D148474
freebsd-git pushed a commit to freebsd/freebsd-src that referenced this issue Mar 20, 2024
  [Clang] Fix ResolveConstructorOverload to not select a conversion function if we are going use copy elision

  ResolveConstructorOverload needs to check properly if we are going to use copy
  elision we can't use a conversion function.

  This fixes:

  llvm/llvm-project#39319
  llvm/llvm-project#60182
  llvm/llvm-project#62157
  llvm/llvm-project#64885
  llvm/llvm-project#65568

  Differential Revision: https://reviews.llvm.org/D148474

This should fix 'Assertion failed: (isa<To>(Val) && "cast<Ty>() argument
of incompatible type!")' errors when building devel/boost-libs,
specifically libs/url/src/segments_view.cpp.

Bump __FreeBSD_version so this fix can easily be detected from
devel/boost-all/compiled.mk.

PR:		273335
freebsd-git pushed a commit to freebsd/freebsd-src that referenced this issue Mar 23, 2024
  [Clang] Fix ResolveConstructorOverload to not select a conversion function if we are going use copy elision

  ResolveConstructorOverload needs to check properly if we are going to use copy
  elision we can't use a conversion function.

  This fixes:

  llvm/llvm-project#39319
  llvm/llvm-project#60182
  llvm/llvm-project#62157
  llvm/llvm-project#64885
  llvm/llvm-project#65568

  Differential Revision: https://reviews.llvm.org/D148474

This should fix 'Assertion failed: (isa<To>(Val) && "cast<Ty>() argument
of incompatible type!")' errors when building devel/boost-libs,
specifically libs/url/src/segments_view.cpp.

Bump __FreeBSD_version so this fix can easily be detected from
devel/boost-all/compiled.mk.

PR:		273335
(cherry picked from commit bcd401b)
freebsd-git pushed a commit to freebsd/freebsd-src that referenced this issue Mar 23, 2024
  [Clang] Fix ResolveConstructorOverload to not select a conversion function if we are going use copy elision

  ResolveConstructorOverload needs to check properly if we are going to use copy
  elision we can't use a conversion function.

  This fixes:

  llvm/llvm-project#39319
  llvm/llvm-project#60182
  llvm/llvm-project#62157
  llvm/llvm-project#64885
  llvm/llvm-project#65568

  Differential Revision: https://reviews.llvm.org/D148474

This should fix 'Assertion failed: (isa<To>(Val) && "cast<Ty>() argument
of incompatible type!")' errors when building devel/boost-libs,
specifically libs/url/src/segments_view.cpp.

Bump __FreeBSD_version so this fix can easily be detected from
devel/boost-all/compiled.mk.

PR:		273335
(cherry picked from commit bcd401b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++17 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants