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 35761 - Clang -O0: "cast<Ty>() argument of incompatible type"
Summary: Clang -O0: "cast<Ty>() argument of incompatible type"
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Sam Parker
URL:
Keywords:
Depends on:
Blocks: release-6.0
  Show dependency tree
 
Reported: 2017-12-27 07:30 PST by Dmitry Babokin
Modified: 2018-01-17 07:50 PST (History)
7 users (show)

See Also:
Fixed By Commit(s): 321991


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Babokin 2017-12-27 07:30:35 PST
clang x86_84, trunk rev 321482.

> cat f.c
namespace a {
typedef int b;
struct c {
  template <typename d, typename e> struct f {
    using g = typename d::template h<e>::i;
  };
};
template <typename j, typename e> using k = typename c::f<j, e>::g;
template <typename j> struct l {
  typedef typename j::m m;
  template <typename d> using n = k<j, d>;
};
}
namespace aa {
template <typename j> struct o {
  typedef a::l<j> p;
  typedef typename p::m q;
  template <typename d> struct h { typedef typename p::template n<d> i; };
};
}
namespace a {
template <class d> class r {
public:
  d &operator[](b);
};
}
namespace aa {
template <typename d> class s {
public:
  typedef d m;
  template <typename> struct h { typedef s i; };
};
}
namespace a {
template <typename d> using t = aa::s<d>;
template <typename d> class ab : public t<d> {};
template <typename d, typename j> struct ac {
  typedef typename aa::o<j>::template h<d>::i ad;
};
template <typename d, typename j = ab<d>> class u {
  typedef ac<d, j> ae;
  typedef typename ae::ad ad;
  typedef aa::o<ad> v;
  typedef typename v::q q;
  typedef b w;

public:
  q af(w);
};
}
bool x;
int y;
struct z {
  char ag : 22;
  bool : 8;
};
struct ah {
  z ai;
};
a::u<int> aj;
a::r<ah> ak;
void al() { ak[2].ai.ag = x | ~~(32767 | aj.af(3)) ^ y; }

> clang++  -std=c++11 -w -O0 -c f.c
clang-6.0: /localdisk2/users/dybaboki/llvm/llvm-trunk-20171227/include/llvm/Support/Casting.h:241: typename std::enable_if<!is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type>::type llvm::cast(const Y &) [X = llvm::ConstantSDNode, Y = llvm::SDValue]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
#0 0x00000000013dfcbf llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x13dfcbf)
#1 0x00000000013dffc6 SignalHandler(int) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x13dffc6)
#2 0x00007f3a3134c5e0 __restore_rt (/lib64/libpthread.so.0+0xf5e0)
#3 0x00007f3a2fec51f7 __GI_raise (/lib64/libc.so.6+0x351f7)
#4 0x00007f3a2fec68e8 __GI_abort (/lib64/libc.so.6+0x368e8)
#5 0x00007f3a2febe266 __assert_fail_base (/lib64/libc.so.6+0x2e266)
#6 0x00007f3a2febe312 (/lib64/libc.so.6+0x2e312)
#7 0x0000000001a846dd (anonymous namespace)::DAGCombiner::visitAND(llvm::SDNode*) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x1a846dd)
#8 0x0000000001a57e45 (anonymous namespace)::DAGCombiner::visit(llvm::SDNode*) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x1a57e45)
#9 0x0000000001a5557c (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x1a5557c)
#10 0x0000000001a541ff llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOpt::Level) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x1a541ff)
#11 0x0000000001b9210f llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x1b9210f)
#12 0x0000000001b901be llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x1b901be)
#13 0x0000000001b8ca82 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x1b8ca82)
#14 0x0000000000851351 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x851351)
#15 0x0000000000c2153e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0xc2153e)
#16 0x0000000000f4775f llvm::FPPassManager::runOnFunction(llvm::Function&) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0xf4775f)
#17 0x0000000000f47a23 llvm::FPPassManager::runOnModule(llvm::Module&) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0xf47a23)
#18 0x0000000000f47f09 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0xf47f09)
#19 0x000000000157505f clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x157505f)
#20 0x0000000001c80ab6 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x1c80ab6)
#21 0x0000000002137a36 clang::ParseAST(clang::Sema&, bool, bool) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x2137a36)
#22 0x0000000001939eb8 clang::FrontendAction::Execute() (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x1939eb8)
#23 0x00000000018fbe81 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x18fbe81)
#24 0x00000000019c4a68 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x19c4a68)
#25 0x00000000007a4daa cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x7a4daa)
#26 0x00000000007a30c9 main (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x7a30c9)
#27 0x00007f3a2feb1c05 __libc_start_main (/lib64/libc.so.6+0x21c05)
#28 0x00000000007a04f2 _start (/localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0+0x7a04f2)
Stack dump:
0.	Program arguments: /localdisk2/users/dybaboki/llvm/bin-trunk-20171227/bin/clang-6.0 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name f.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /users/dybaboki/yarpgen/yarpgen/test_run_dec19_reduce/result/clang/compfail/S_12_2880678421/f.gcno -resource-dir /localdisk2/users/dybaboki/llvm/bin-trunk-20171227/lib/clang/6.0.0 -internal-isystem /users/dybaboki/gcc/bin/lib/gcc/x86_64-pc-linux-gnu/8.0.0/../../../../include/c++/8.0.0 -internal-isystem /users/dybaboki/gcc/bin/lib/gcc/x86_64-pc-linux-gnu/8.0.0/../../../../include/c++/8.0.0/x86_64-pc-linux-gnu -internal-isystem /users/dybaboki/gcc/bin/lib/gcc/x86_64-pc-linux-gnu/8.0.0/../../../../include/c++/8.0.0/backward -internal-isystem /usr/local/include -internal-isystem /localdisk2/users/dybaboki/llvm/bin-trunk-20171227/lib/clang/6.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -w -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /users/dybaboki/yarpgen/yarpgen/test_run_dec19_reduce/result/clang/compfail/S_12_2880678421 -ferror-limit 19 -fmessage-length 204 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o f.o -x c++ f.c
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 'f.c'.
4.	Running pass 'X86 DAG->DAG Instruction Selection' on function '@_Z2alv'
clang-6.0: error: unable to execute command: Aborted (core dumped)
clang-6.0: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 6.0.0 (trunk 321482)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /users/dybaboki/llvm/bin-trunk-20171227/bin
clang-6.0: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang-6.0: note: diagnostic msg: Error generating preprocessed source(s).
Comment 1 Davide Italiano 2018-01-02 06:39:22 PST
%"class.a::u" = type { i8 }
%"class.a::r" = type { i8 }
%struct.ah = type { %struct.z }
%struct.z = type { [3 x i8], i8 }
@x = global i8 0, align 1
@y = global i32 0, align 4
@aj = global %"class.a::u" zeroinitializer, align 1
@ak = global %"class.a::r" zeroinitializer, align 1
define void @_Z2alv() #0 {
entry:
  %0 = load i8, i8* @x, align 1
  %tobool = trunc i8 %0 to i1
  %conv = zext i1 %tobool to i32
  %call = call i32 @_ZN1a1uIiNS_2abIiEEE2afEi(%"class.a::u"* @aj, i32 3)
  %or = or i32 32767, %call
  %neg = xor i32 %or, -1
  %neg1 = xor i32 %neg, -1
  %1 = load i32, i32* @y, align 4
  %xor = xor i32 %neg1, %1
  %or2 = or i32 %conv, %xor
  %conv3 = trunc i32 %or2 to i8
  %call4 = call dereferenceable(4) %struct.ah* @_ZN1a1rI2ahEixEi(%"class.a::r"* @ak, i32 2)
  %ai = getelementptr inbounds %struct.ah, %struct.ah* %call4, i32 0, i32 0
  %2 = bitcast %struct.z* %ai to i24*
  %3 = zext i8 %conv3 to i24
  %bf.load = load i24, i24* %2, align 2
  %bf.value = and i24 %3, 4194303
  %bf.clear = and i24 %bf.load, -4194304
  %bf.set = or i24 %bf.clear, %bf.value
  store i24 %bf.set, i24* %2, align 2
  ret void
}
declare i32 @_ZN1a1uIiNS_2abIiEEE2afEi(%"class.a::u"*, i32) #1
declare dereferenceable(4) %struct.ah* @_ZN1a1rI2ahEixEi(%"class.a::r"*, i32) #1
Comment 2 Davide Italiano 2018-01-02 06:39:42 PST
$ ./llc red.ll
Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file ../include/llvm/Support/Casting.h, line 241.
0  llc                      0x00000001083a094c llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  llc                      0x00000001083a0f49 PrintStackTraceSignalHandler(void*) + 25
2  llc                      0x000000010839c989 llvm::sys::RunSignalHandlers() + 425
3  llc                      0x00000001083a1722 SignalHandler(int) + 354
4  libsystem_platform.dylib 0x00007fff620d8f5a _sigtramp + 26
5  libsystem_platform.dylib 000000000000000000 _sigtramp + 2649911488
6  libsystem_c.dylib        0x00007fff61f03312 abort + 127
7  libsystem_c.dylib        0x00007fff61ecb368 basename_r + 0
8  llc                      0x00000001081a5fb4 std::__1::enable_if<!(is_simple_type<llvm::SDValue>::value), llvm::cast_retty<llvm::ConstantSDNode, llvm::SDValue const>::ret_type>::type llvm::cast<llvm::ConstantSDNode, llvm::SDValue>(llvm::SDValue const&) + 100
9  llc                      0x0000000107ebc0be (anonymous namespace)::DAGCombiner::BackwardsPropagateMask(llvm::SDNode*, llvm::SelectionDAG&) + 1022
10 llc                      0x0000000107e72764 (anonymous namespace)::DAGCombiner::visitAND(llvm::SDNode*) + 6596
11 llc                      0x0000000107e6070d (anonymous namespace)::DAGCombiner::visit(llvm::SDNode*) + 669
12 llc                      0x0000000107e5fe38 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) + 56
13 llc                      0x0000000107e5cfc6 (anonymous namespace)::DAGCombiner::Run(llvm::CombineLevel) + 1286
14 llc                      0x0000000107e5ca48 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOpt::Level) + 104
15 llc                      0x0000000108188eb2 llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 6018
16 llc                      0x0000000108187580 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&) + 336
17 llc                      0x0000000108185ec1 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 10257
Comment 3 Sam Parker 2018-01-02 07:57:56 PST
Patch for review: https://reviews.llvm.org/D41667
Comment 4 Sam Parker 2018-01-08 05:22:19 PST
Fix committed in https://reviews.llvm.org/rL321991
Comment 5 Hans Wennborg 2018-01-17 07:50:52 PST
Merged to 6.0 in r322670.