Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Pointer cast from standard address_space to non-standard one causes assert #20134

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR20135
Status NEW
Importance P normal
Reported by dmcdb@trialsoftware.com
Reported on 2014-06-26 12:49:03 -0700
Last modified on 2015-12-01 16:32:53 -0800
Version trunk
Hardware PC Linux
CC carlo.bertolli@gmail.com, llvm-bugs@lists.llvm.org, Matthew.Arsenault@amd.com, me@manueljacob.de
Fixed by commit(s)
Attachments file_20135.txt (891 bytes, text/plain)
Blocks
Blocked by
See also
Created attachment 12706
preprocessed source & associated run script

Clang crashes when a pointer value of the standard address space is casted into
non-standard address space and assigned to a pointer variable of a non-standard
address space.

This occurs only when the source file has .cpp extension. The same source file
with .c extension compiles ok.

Crash backtrace is as follows:

clang: /home/nhaketa/src/llvm-3.5.x/llvm/lib/IR/Instructions.cpp:1085: void
llvm::StoreInst::AssertOK(): Assertion `getOperand(0)->getType() ==
cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a
pointer to Val type!"' failed.
0  clang           0x000000000209afa2 llvm::sys::PrintStackTrace(_IO_FILE*) + 34
1  clang           0x000000000209a844
2  libpthread.so.0 0x0000003a18e0f710
3  libc.so.6       0x0000003a18a32925 gsignal + 53
4  libc.so.6       0x0000003a18a34105 abort + 373
5  libc.so.6       0x0000003a18a2ba4e
6  libc.so.6       0x0000003a18a2bb10 __assert_perror_fail + 0
7  clang           0x0000000002010ccc llvm::StoreInst::AssertOK() + 140
8  clang           0x000000000093613b
clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, llvm::Value*,
bool, unsigned int, clang::QualType, llvm::MDNode*, bool, clang::QualType,
unsigned long) + 219
9  clang           0x00000000009365a1
clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*,
clang::CodeGen::LValue, bool) + 65
10 clang           0x0000000000939a9b
clang::CodeGen::CodeGenFunction::EmitStoreThroughLValue(clang::CodeGen::RValue,
clang::CodeGen::LValue, bool) + 1179
11 clang           0x00000000009435de
clang::CodeGen::CodeGenFunction::EmitBinaryOperatorLValue(clang::BinaryOperator
const*) + 734
12 clang           0x000000000093f4e5
clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*) + 1029
13 clang           0x000000000093fb18
clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) + 24
14 clang           0x0000000000859bcf
clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) + 255
15 clang           0x000000000085a1ff
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
const&, bool, clang::CodeGen::AggValueSlot) + 79
16 clang           0x000000000086af74
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList&,
clang::Stmt const*) + 276
17 clang           0x000000000086cb84
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&) + 836
18 clang           0x000000000088d9e4
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*) + 468
19 clang           0x000000000088edb7
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*) + 503
20 clang           0x00000000008919cd
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) + 1677
21 clang           0x0000000000892320
22 clang           0x00000000008233b3
23 clang           0x000000000081f18c
24 clang           0x00000000009d5d0e clang::ParseAST(clang::Sema&, bool, bool)
+ 302
25 clang           0x000000000082075b clang::CodeGenAction::ExecuteAction() + 59
26 clang           0x0000000000683246 clang::FrontendAction::Execute() + 118
27 clang           0x000000000065ebd0
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 304
28 clang           0x0000000000646d33
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 2115
29 clang           0x000000000063d858 cc1_main(char const**, char const**, char
const*, void*) + 968
30 clang           0x0000000000644192 main + 1362
31 libc.so.6       0x0000003a18a1ed1d __libc_start_main + 253
32 clang           0x000000000063cd65
Stack dump:
0.  Program arguments: /usr/local/bin/clang -cc1 -triple x86_64-unknown-linux-
gnu -emit-llvm -disable-free -main-file-name foo.cpp -mrelocation-model static -
mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-
tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.20.51.0.2 -
coverage-file /home/nhaketa/src/clang-test/foo.ll -resource-dir
/usr/local/bin/../lib/clang/3.5.0 -internal-isystem
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-
gnu/4.9.0/../../../../include/c++/4.9.0 -internal-isystem
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-
gnu/4.9.0/../../../../include/c++/4.9.0/x86_64-unknown-linux-gnu -internal-
isystem /usr/local/bin/../lib/gcc/x86_64-unknown-linux-
gnu/4.9.0/../../../../include/c++/4.9.0/backward -internal-isystem
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-
gnu/4.9.0/../../../../include/x86_64-unknown-linux-gnu/c++/4.9.0 -internal-
isystem /usr/local/include -internal-isystem
/usr/local/bin/../lib/clang/3.5.0/include -internal-externc-isystem /include -
internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-
dir /home/nhaketa/src/clang-test -ferror-limit 19 -fmessage-length 209 -
mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-
show-option -o foo.ll -x c++ foo.cpp
1.  <eof> parser at end of file
2.  foo.cpp:4:6: LLVM IR generation of declaration 'func'
3.  foo.cpp:4:6: Generating code for declaration 'func'
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.5.0 (trunk 211489)
Target: x86_64-unknown-linux-gnu
Thread model: posix
clang: 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: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/foo-2b54c7.ii
clang: note: diagnostic msg: /tmp/foo-2b54c7.sh
clang: note: diagnostic msg:

********************
Quuxplusone commented 10 years ago

Attached file_20135.txt (891 bytes, text/plain): preprocessed source & associated run script

Quuxplusone commented 9 years ago
I had already noticed this when playing with address spaces when targeting the
nvptx backend. Looking at the .ll file compiled using the input .c file, I can
see:

  store i8 addrspace(1)* addrspacecast (i8* getelementptr inbounds ([2 x i8]* @.str, i32 0, i32 0) to i8 addrspace(1)*), i8 addrspace(1)** %p, align 8

The assert error in C++ comes from the fact that the value being stored has
type i8* without addrspace(1) specified.

The addspacecast make it possible to skip the failing assert that we instead
get in C++ compilation. Somehow, the addrspacecast call is not performed when
compiling in C++.