Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

llvm-gcc: cast of pointer to constant value fails in llvm BitcodeWriter.cpp: 714 #6577

Closed Quuxplusone closed 14 years ago

Quuxplusone commented 14 years ago
Bugzilla Link PR6112
Status RESOLVED FIXED
Importance P normal
Reported by Martijn Rutten (martijn@martijnrutten.com)
Reported on 2010-01-22 03:48:38 -0800
Last modified on 2010-04-28 15:16:47 -0700
Version trunk
Hardware PC Linux
CC baldrick@free.fr, clattner@nondot.org, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments md.ll (199 bytes, text/plain)
Blocks
Blocked by
See also
llvm-gcc (cc1) fails when writing bitcode for the test-suite application
MultiSource/Applications/Burg/main.c with -g and optimization > O0 enabled. The
normal testsuite compilation without -g compiles fine.

See the debug trace below.
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:714 "const Constant *C =
cast<Constant>(V);" fails with 'V' being a pointer type which is not a constant.

How to reproduce:

cd llvm/projects/llvm-test/MultiSource/Applications/Burg
llvm-gcc -c -g -O1 main.c -emit-llvm

llvm-gcc output:

main.c: In function 'main':
main.c:22: warning: return type of 'main' is not 'int'
cc1: /home1/martijn/work/llvm-svn/llvm/include/llvm/Support/Casting.h:199:
typename llvm::cast_retty<To, From>::ret_type llvm::cast(const Y&) [with X =
llvm::Constant, Y = const llvm::Value*]: Assertion `isa<X>(Val) && "cast<Ty>()
argument of incompatible type!"' failed.
main.c: At top level:
main.c:182: internal compiler error: Aborted
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://llvm.org/bugs/> for instructions.

Debug trace:

Starting program: /home1/martijn/work/llvm-svn/install/libexec/gcc/i686-pc-
linux-gnu/4.2.1/cc1 -quiet -iprefix /home1/martijn/work/llvm-svn/llvm-gcc-
obj/gcc/../lib/gcc/i686-pc-linux-gnu/4.2.1/ main.c -emit-llvm-bc -o main.o -
quiet -dumpbase main.c -mtune=generic -auxbase main -g -O1
[Thread debugging using libthread_db enabled]
main.c: In function 'main':
main.c:22: warning: return type of 'main' is not 'int'
cc1: /home1/martijn/work/llvm-svn/llvm/include/llvm/Support/Casting.h:199:
typename llvm::cast_retty<To, From>::ret_type llvm::cast(const Y&) [with X =
llvm::Constant, Y = const llvm::Value*]: Assertion `isa<X>(Val) && "cast<Ty>()
argument of incompatible type!"' failed.

Program received signal SIGABRT, Aborted.
0xb7fe2430 in __kernel_vsyscall ()
(gdb) bt
#0  0xb7fe2430 in __kernel_vsyscall ()
#1  0xb7d614d1 in raise () from /lib/tls/i686/cmov/libc.so.6
#2  0xb7d64932 in abort () from /lib/tls/i686/cmov/libc.so.6
#3  0xb7d5a648 in __assert_fail () from /lib/tls/i686/cmov/libc.so.6
#4  0x08570a9f in llvm::cast_retty<llvm::Constant, llvm::Value
const*>::ret_type llvm::cast<llvm::Constant, llvm::Value const*>(llvm::Value
const* const&)
    ()
#5  0x0856896a in WriteConstants (FirstVal=59, LastVal=176, VE=..., Stream=...,
isGlobal=true)
    at /home1/martijn/work/llvm-svn/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:714
#6  0x08569e5e in WriteModuleConstants (VE=..., Stream=...) at
/home1/martijn/work/llvm-svn/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:894
#7  0x0856cd81 in WriteModule (M=0x91549c8, Stream=...) at
/home1/martijn/work/llvm-svn/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:1474
#8  0x0856d2c1 in llvm::WriteBitcodeToStream (M=0x91549c8, Stream=...) at
/home1/martijn/work/llvm-svn/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:1599
#9  0x0856d146 in llvm::WriteBitcodeToFile (M=0x91549c8, Out=...) at
/home1/martijn/work/llvm-svn/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:1569
#10 0x08564d5b in runOnModule (this=0x9151e00, M=...) at
/home1/martijn/work/llvm-svn/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp:29
#11 0x08ccb336 in llvm::MPPassManager::runOnModule (this=0x91aa790, M=...) at
/home1/martijn/work/llvm-svn/llvm/lib/VMCore/PassManager.cpp:1409
#12 0x08ccb810 in llvm::PassManagerImpl::run (this=0x91ab278, M=...) at
/home1/martijn/work/llvm-svn/llvm/lib/VMCore/PassManager.cpp:1490
#13 0x08ccbaf5 in llvm::PassManager::run (this=0x916ba68, M=...) at
/home1/martijn/work/llvm-svn/llvm/lib/VMCore/PassManager.cpp:1519
#14 0x083ff2ff in llvm_asm_file_end () at ../../llvm-gcc/gcc/llvm-
backend.cpp:955
#15 0x083a8f56 in compile_file (argc=16, argv=0xbffff214) at ../../llvm-
gcc/gcc/toplev.c:1193
#16 do_compile (argc=16, argv=0xbffff214) at ../../llvm-gcc/gcc/toplev.c:2269
#17 toplev_main (argc=16, argv=0xbffff214) at ../../llvm-gcc/gcc/toplev.c:2301
#18 0x080e5aa7 in main (argc=16, argv=0xbffff214) at ../../llvm-gcc/gcc/llvm-
main.cpp:47
(gdb) f 5
#5  0x0856896a in WriteConstants (FirstVal=59, LastVal=176, VE=..., Stream=...,
isGlobal=true)
    at /home1/martijn/work/llvm-svn/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:714
714     const Constant *C = cast<Constant>(V);

(gdb) p *V->VTy->Ty
$1 = {<llvm::AbstractTypeUser> = {_vptr.AbstractTypeUser = 0x90764e8}, ID =
llvm::Type::PointerTyID, Abstract = false, SubclassData = 0, RefCount = 0,
  Context = @0x912ab38, ForwardType = 0x0, AbstractTypeUsers = {<std::_Vector_base<llvm::AbstractTypeUser*, std::allocator<llvm::AbstractTypeUser*> >> = {
      _M_impl = {<std::allocator<llvm::AbstractTypeUser*>> = {<__gnu_cxx::new_allocator<llvm::AbstractTypeUser*>> = {<No data fields>}, <No data fields>},
        _M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}, NumContainedTys = 1, ContainedTys = 0x9188f30}

Environment:

llvm-gcc revision: r94023
llvm revision: r94077
uname -a: Linux martijn 2.6.31-17-generic-pae #54-Ubuntu SMP Thu Dec 10
17:23:29 UTC 2009 i686 GNU/Linux
gcc --version: gcc (Ubuntu 4.4.1-4ubuntu8) 4.4.1
Quuxplusone commented 14 years ago

Is this still a problem on mainline?

Quuxplusone commented 14 years ago
Yes, I can reproduce this with mainline.  The problem is this module level
metadata:

!7 = metadata !{i32 524340, i32 0, metadata !1, metadata !"outFileName",
metadata !"outFileName", metadata !"", metadata !1, i32 14, metadata !8, i1
true, i1 true, i8** %outFileName} ; [ DW_TAG_variable ]

which has i8** %outFileName, which is not allowed.

It seems like the verifier doesn't fully verify metadata, since it didn't
complain :(
Quuxplusone commented 14 years ago
Whats going on here is that there is a module level piece of metadata that
has an internal global variable as an operand.  So far so good.  GlobalOpt
sees that this global variable is only used by one function and turns it
into a local variable of the function.  This results in a global metadata
with an AllocaInst as an operand, which is not allowed.

I'm not sure what the right solution to this problem is.
Quuxplusone commented 14 years ago
By the way, I've enhanced the verifier to catch this kind of problem, but
didn't commit it because it breaks llvm-gcc bootstrap (same problem as in
this PR).
Quuxplusone commented 14 years ago

Attached md.ll (199 bytes, text/plain): reduced testcase .ll

Quuxplusone commented 14 years ago
Ug, this is a really terrible problem.  Pondering on it.  Thank you *very* much
for the reduction + analysis, Duncan.
Quuxplusone commented 14 years ago
Fixed here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20100426/100501.html

CallbackVH to the rescue :-)