Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed. #22216

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR22217
Status NEW
Importance P normal
Reported by Kostya Serebryany (kcc@google.com)
Reported on 2015-01-13 13:40:50 -0800
Last modified on 2018-03-19 16:24:51 -0700
Version unspecified
Hardware PC Linux
CC david.majnemer@gmail.com, llvm-bugs@lists.llvm.org, rafael@espindo.la, rnk@google.com, roland@hack.frob.com
Fixed by commit(s)
Attachments a.c (337807 bytes, text/x-csrc)
Blocks
Blocked by
See also
This is clang r225817
Reproducer reduced from glibc sources by creduce
=========================
 int __vdso_clock_gettime;
    extern __typeof ( &__vdso_clock_gettime )      __EI___vdso_clock_gettime __asm__ ( "__vdso_clock_gettime" );
    __typeof ( &__vdso_clock_gettime )      __EI___vdso_clock_gettime        __attribute__ ( ( alias ( "__GI___vdso_clock_gettime" ) ) );
=========================

clang -cc1 -triple x86_64-unknown-linux-gnu -S  b.c -o /dev/null

b.c:3:10: warning: typedef requires a name
         typedef union
         ^~~~~~~
b.c:4:40: warning: attribute '__transparent_union__' is ignored, place it after
"union" to apply attribute to type declaration
        __SOCKADDR_ARG __attribute__ ((__transparent_union__));
                                       ^
clang: llvm/include/llvm/Support/Casting.h:237: typename cast_retty<X, Y
*>::ret_type llvm::cast(Y *) [X = llvm::GlobalAlias, Y = llvm::GlobalValue]:
Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
#0 0x14df5a8 llvm::sys::PrintStackTrace(_IO_FILE*) (llvm_build/bin/clang-
3.6+0x14df5a8)
#1 0x14e0b5b SignalHandler(int) (llvm_build/bin/clang-3.6+0x14e0b5b)
#2 0x7fadc5b7d340 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)
#3 0x7fadc4da6bb9 gsignal /build/buildd/eglibc-
2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#4 0x7fadc4da9fc8 abort /build/buildd/eglibc-2.19/stdlib/abort.c:91:0
#5 0x7fadc4d9fa76 __assert_fail_base /build/buildd/eglibc-
2.19/assert/assert.c:92:0
#6 0x7fadc4d9fb22 (/lib/x86_64-linux-gnu/libc.so.6+0x2fb22)
#7 0x1989fd1 clang::CodeGen::CodeGenModule::checkAliases()
(llvm_build/bin/clang-3.6+0x1989fd1)
#8 0x198a8d6 clang::CodeGen::CodeGenModule::Release() (llvm_build/bin/clang-
3.6+0x198a8d6)
#9 0x1927b20 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(llvm_build/bin/clang-3.6+0x1927b20)
#10 0x1ebf183 clang::ParseAST(clang::Sema&, bool, bool) (llvm_build/bin/clang-
3.6+0x1ebf183)
#11 0x168bfee clang::FrontendAction::Execute() (llvm_build/bin/clang-
3.6+0x168bfee)
#12 0x165cf3c clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(llvm_build/bin/clang-3.6+0x165cf3c)
#13 0x171025a clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(llvm_build/bin/clang-3.6+0x171025a)
#14 0x6cf9b4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*)
(llvm_build/bin/clang-3.6+0x6cf9b4)
#15 0x6ce6f8 main (llvm_build/bin/clang-3.6+0x6ce6f8)
Quuxplusone commented 9 years ago

I think Rafael wrote the alias code.

Quuxplusone commented 9 years ago
reduced a little:
int A;
extern int  B __asm__("A");
int B __attribute__((alias("C")));

seems to be a strange interaction between asm labels and the alias attribute.
Quuxplusone commented 9 years ago
Partially fixed with r226436.

I now have the following example left:
int A;
int C;
extern int B __asm__("A");
extern int B __attribute__((alias("C")));

We need are missing ".set A,C"
Quuxplusone commented 9 years ago
Interestingly, the following works perfectly:

extern int A;
int C;
extern int B __asm__("A");
extern int B __attribute__((alias("C")));

My guess is that the definition of 'A' in #c3 is causing problems.
Quuxplusone commented 9 years ago

Kostya, can you please post the non-reduced, preprocessed source code?

Quuxplusone commented 9 years ago
(In reply to comment #4)
> Interestingly, the following works perfectly:
>
> extern int A;
> int C;
> extern int B __asm__("A");
> extern int B __attribute__((alias("C")));
>
> My guess is that the definition of 'A' in #c3 is causing problems.

Gcc produces invalid assembly for this:

gcc -c ~/llvm/test.c -o test.o
/tmp/ccUnK6Fa.s: Assembler messages:
/tmp/ccUnK6Fa.s:4: Error: `A' can't be equated to common symbol 'C'
Quuxplusone commented 9 years ago
> gcc -c ~/llvm/test.c -o test.o
> /tmp/ccUnK6Fa.s: Assembler messages:
> /tmp/ccUnK6Fa.s:4: Error: `A' can't be equated to common symbol 'C'

I will start by making sure MC is able to diagnose this too.
Quuxplusone commented 9 years ago
(In reply to comment #3)
> Partially fixed with r226436.
>
> I now have the following example left:
> int A;
> int C;
> extern int B __asm__("A");
> extern int B __attribute__((alias("C")));
>
> We need are missing ".set A,C"

gcc also produces invalid assembly for this.
Quuxplusone commented 9 years ago
(In reply to comment #2)
> reduced a little:
> int A;
> extern int  B __asm__("A");
> int B __attribute__((alias("C")));
>
> seems to be a strange interaction between asm labels and the alias attribute.

For this gcc produces:

 gcc -c test.c
test.c:3:5: error: ‘B’ defined both normally and as ‘alias’ attribute
 int B __attribute__((alias("C")));
Quuxplusone commented 9 years ago
(In reply to comment #0)
> This is clang r225817
> Reproducer reduced from glibc sources by creduce
> =========================
>  int __vdso_clock_gettime;
>     extern __typeof ( &__vdso_clock_gettime )      __EI___vdso_clock_gettime
> __asm__ ( "__vdso_clock_gettime" );
>     __typeof ( &__vdso_clock_gettime )      __EI___vdso_clock_gettime
> __attribute__ ( ( alias ( "__GI___vdso_clock_gettime" ) ) );
> =========================
>

GCC errors on this:

test.c:4:33: error: ‘__EI___vdso_clock_gettime’ defined both normally and as
‘alias’ attribute
 __typeof(&__vdso_clock_gettime) __EI___vdso_clock_gettime

can you upload a unreduced .i file?
Quuxplusone commented 9 years ago
in c++ mode, we don't emit an alias for:
extern int A;
int A;
extern int B;
int C;
extern int B __asm__("A");
extern int B __attribute__((alias("C")));
Quuxplusone commented 9 years ago
in c mode, we crash with:
int A;
int C;
extern int B __asm__("A");
extern int B __attribute__((alias("C")));
Quuxplusone commented 9 years ago

Attached a.c (337807 bytes, text/x-csrc): original preprocessed file

Quuxplusone commented 9 years ago
Clang can handle

int *foo  __asm__("bar") __attribute__((nocommon));
extern int zed __asm__("foo") __attribute__((alias("bar")));

producing

@bar = global i32* null, align 8

@foo = alias bitcast (i32** @bar to i32*)

so it looks like we are just not merging the two foo decls correctly:

int *foo __attribute__((nocommon));
extern int *foo __asm__("bar");
Quuxplusone commented 9 years ago
The issue really reduces to

int *foo __attribute__((nocommon));
extern int *foo __asm__("bar");

Where gcc produces a bar and clang produces a foo.

I should have a patch in a minute.
Quuxplusone commented 9 years ago

I think the way to fix this is clear: delay codegen.

There is pushback from John on doing it, so this can easily go down as a fight between what he thinks c/c++/gnu extensions should be and what glibc thinks it can use.

Given my previous work which "ended" with pr16187, I would prefer to not be involved this.