Y Song via llvm-dev
2019-Oct-30 22:56 UTC
[llvm-dev] pointer arithmetic with address space attribute not working
Hi, I have a case that for pointer with address space attribute, pointer arithmetic is not work. For example, -bash-4.4$ cat test.c #define __user __attribute__((address_space(1))) void __user * test(void __user *arg) { #ifdef ADD return arg + 4; #else return arg; #endif } -bash-4.4$ -bash-4.4$ clang -g -c test.c -bash-4.4$ clang -g -c -DADD test.c clang-10: ../lib/IR/Instructions.cpp:2749: static llvm::CastInst *llvm::CastInst::Create(Instruction::CastOps, llvm::Value *, llvm::Type *, const llvm::Twine &, llvm::Instruction *): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed. Stack dump: 0. Program arguments: /data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disa ble-free -main-file-name test.c -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose -mconstructor-aliases -munwind-t ables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -resource-dir /data/users/yhs/work /llvm-project/llvm/build/install/lib/clang/10.0.0 -D ADD -internal-isystem /usr/local/include -internal-isystem /data/users/yhs/work/llvm-project/llvm/build/i nstall/lib/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/yhs/work/tests/user -f error-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o test.o -x c test.c 1. <eof> parser at end of file 2. test.c:2:15: LLVM IR generation of declaration 'test' 3. test.c:2:15: Generating code for declaration 'test' #0 0x00000000017067bf llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x17067bf) #1 0x0000000001704a50 llvm::sys::RunSignalHandlers() (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x1704a50) #2 0x0000000001706d28 SignalHandler(int) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x1706d28) #3 0x00007fed0c6c3b10 __restore_rt (/usr/local/fbcode/platform007/lib/libpthread.so.0+0x12b10) #4 0x00007fed0b81214f raise (/usr/local/fbcode/platform007/lib/libc.so.6+0x3714f) #5 0x00007fed0b7fb935 abort (/usr/local/fbcode/platform007/lib/libc.so.6+0x20935) #6 0x00007fed0b80a107 __assert_fail_base (/usr/local/fbcode/platform007/lib/libc.so.6+0x2f107) #7 0x00007fed0b80a173 (/usr/local/fbcode/platform007/lib/libc.so.6+0x2f173) #8 0x00000000011b9381 llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::Instruction*) (/data/users/yhs/ work/llvm-project/llvm/build/install/bin/clang-10+0x11b9381) #9 0x0000000001b5177f emitPointerArithmetic(clang::CodeGen::CodeGenFunction&, (anonymous namespace)::BinOpInfo const&, bool) (/data/users/yhs/work/llvm-proje ct/llvm/build/install/bin/clang-10+0x1b5177f) #10 0x0000000001b42b86 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) (/data/users/yhs/ work/llvm-project/llvm/build/install/bin/clang-10+0x1b42b86) #11 0x0000000001b3a245 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/cla ng-10+0x1b3a245) #12 0x00000000019226c8 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/cla ng-10+0x19226c8) For pointer arithmetic failure, the clang tries to create a regular pointer and failed since non-None address space is specified in the type. Is this a bug? Or this is the expected behavior? I am asking since linux kernel has a lot of codes which did pointer arithmetic where pointers have address space attributes. (currently those address spaces are sparse tool checking only.) Thanks, Yonghong
Doerfert, Johannes via llvm-dev
2019-Oct-31 01:18 UTC
[llvm-dev] pointer arithmetic with address space attribute not working
What clang version is that? I tried to reproduce it but failed: https://godbolt.org/z/AM1tPp ________________________________________ From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Y Song via llvm-dev <llvm-dev at lists.llvm.org> Sent: Wednesday, October 30, 2019 17:56 To: LLVM Developers Mailing List Cc: Alexei Starovoitov Subject: [llvm-dev] pointer arithmetic with address space attribute not working Hi, I have a case that for pointer with address space attribute, pointer arithmetic is not work. For example, -bash-4.4$ cat test.c #define __user __attribute__((address_space(1))) void __user * test(void __user *arg) { #ifdef ADD return arg + 4; #else return arg; #endif } -bash-4.4$ -bash-4.4$ clang -g -c test.c -bash-4.4$ clang -g -c -DADD test.c clang-10: ../lib/IR/Instructions.cpp:2749: static llvm::CastInst *llvm::CastInst::Create(Instruction::CastOps, llvm::Value *, llvm::Type *, const llvm::Twine &, llvm::Instruction *): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed. Stack dump: 0. Program arguments: /data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disa ble-free -main-file-name test.c -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose -mconstructor-aliases -munwind-t ables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -resource-dir /data/users/yhs/work /llvm-project/llvm/build/install/lib/clang/10.0.0 -D ADD -internal-isystem /usr/local/include -internal-isystem /data/users/yhs/work/llvm-project/llvm/build/i nstall/lib/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/yhs/work/tests/user -f error-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o test.o -x c test.c 1. <eof> parser at end of file 2. test.c:2:15: LLVM IR generation of declaration 'test' 3. test.c:2:15: Generating code for declaration 'test' #0 0x00000000017067bf llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x17067bf) #1 0x0000000001704a50 llvm::sys::RunSignalHandlers() (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x1704a50) #2 0x0000000001706d28 SignalHandler(int) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x1706d28) #3 0x00007fed0c6c3b10 __restore_rt (/usr/local/fbcode/platform007/lib/libpthread.so.0+0x12b10) #4 0x00007fed0b81214f raise (/usr/local/fbcode/platform007/lib/libc.so.6+0x3714f) #5 0x00007fed0b7fb935 abort (/usr/local/fbcode/platform007/lib/libc.so.6+0x20935) #6 0x00007fed0b80a107 __assert_fail_base (/usr/local/fbcode/platform007/lib/libc.so.6+0x2f107) #7 0x00007fed0b80a173 (/usr/local/fbcode/platform007/lib/libc.so.6+0x2f173) #8 0x00000000011b9381 llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::Instruction*) (/data/users/yhs/ work/llvm-project/llvm/build/install/bin/clang-10+0x11b9381) #9 0x0000000001b5177f emitPointerArithmetic(clang::CodeGen::CodeGenFunction&, (anonymous namespace)::BinOpInfo const&, bool) (/data/users/yhs/work/llvm-proje ct/llvm/build/install/bin/clang-10+0x1b5177f) #10 0x0000000001b42b86 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) (/data/users/yhs/ work/llvm-project/llvm/build/install/bin/clang-10+0x1b42b86) #11 0x0000000001b3a245 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/cla ng-10+0x1b3a245) #12 0x00000000019226c8 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/cla ng-10+0x19226c8) For pointer arithmetic failure, the clang tries to create a regular pointer and failed since non-None address space is specified in the type. Is this a bug? Or this is the expected behavior? I am asking since linux kernel has a lot of codes which did pointer arithmetic where pointers have address space attributes. (currently those address spaces are sparse tool checking only.) Thanks, Yonghong _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Doerfert, Johannes via llvm-dev
2019-Oct-31 02:03 UTC
[llvm-dev] pointer arithmetic with address space attribute not working
I forgot the -DADD flag earlier but the result did not change: https://godbolt.org/z/NPcn22 ________________________________________ From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Doerfert, Johannes via llvm-dev <llvm-dev at lists.llvm.org> Sent: Wednesday, October 30, 2019 20:18 To: LLVM Developers Mailing List; Y Song Cc: Alexei Starovoitov Subject: Re: [llvm-dev] pointer arithmetic with address space attribute not working What clang version is that? I tried to reproduce it but failed: https://godbolt.org/z/AM1tPp ________________________________________ From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Y Song via llvm-dev <llvm-dev at lists.llvm.org> Sent: Wednesday, October 30, 2019 17:56 To: LLVM Developers Mailing List Cc: Alexei Starovoitov Subject: [llvm-dev] pointer arithmetic with address space attribute not working Hi, I have a case that for pointer with address space attribute, pointer arithmetic is not work. For example, -bash-4.4$ cat test.c #define __user __attribute__((address_space(1))) void __user * test(void __user *arg) { #ifdef ADD return arg + 4; #else return arg; #endif } -bash-4.4$ -bash-4.4$ clang -g -c test.c -bash-4.4$ clang -g -c -DADD test.c clang-10: ../lib/IR/Instructions.cpp:2749: static llvm::CastInst *llvm::CastInst::Create(Instruction::CastOps, llvm::Value *, llvm::Type *, const llvm::Twine &, llvm::Instruction *): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed. Stack dump: 0. Program arguments: /data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disa ble-free -main-file-name test.c -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose -mconstructor-aliases -munwind-t ables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -resource-dir /data/users/yhs/work /llvm-project/llvm/build/install/lib/clang/10.0.0 -D ADD -internal-isystem /usr/local/include -internal-isystem /data/users/yhs/work/llvm-project/llvm/build/i nstall/lib/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/yhs/work/tests/user -f error-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o test.o -x c test.c 1. <eof> parser at end of file 2. test.c:2:15: LLVM IR generation of declaration 'test' 3. test.c:2:15: Generating code for declaration 'test' #0 0x00000000017067bf llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x17067bf) #1 0x0000000001704a50 llvm::sys::RunSignalHandlers() (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x1704a50) #2 0x0000000001706d28 SignalHandler(int) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x1706d28) #3 0x00007fed0c6c3b10 __restore_rt (/usr/local/fbcode/platform007/lib/libpthread.so.0+0x12b10) #4 0x00007fed0b81214f raise (/usr/local/fbcode/platform007/lib/libc.so.6+0x3714f) #5 0x00007fed0b7fb935 abort (/usr/local/fbcode/platform007/lib/libc.so.6+0x20935) #6 0x00007fed0b80a107 __assert_fail_base (/usr/local/fbcode/platform007/lib/libc.so.6+0x2f107) #7 0x00007fed0b80a173 (/usr/local/fbcode/platform007/lib/libc.so.6+0x2f173) #8 0x00000000011b9381 llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::Instruction*) (/data/users/yhs/ work/llvm-project/llvm/build/install/bin/clang-10+0x11b9381) #9 0x0000000001b5177f emitPointerArithmetic(clang::CodeGen::CodeGenFunction&, (anonymous namespace)::BinOpInfo const&, bool) (/data/users/yhs/work/llvm-proje ct/llvm/build/install/bin/clang-10+0x1b5177f) #10 0x0000000001b42b86 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) (/data/users/yhs/ work/llvm-project/llvm/build/install/bin/clang-10+0x1b42b86) #11 0x0000000001b3a245 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/cla ng-10+0x1b3a245) #12 0x00000000019226c8 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/cla ng-10+0x19226c8) For pointer arithmetic failure, the clang tries to create a regular pointer and failed since non-None address space is specified in the type. Is this a bug? Or this is the expected behavior? I am asking since linux kernel has a lot of codes which did pointer arithmetic where pointers have address space attributes. (currently those address spaces are sparse tool checking only.) Thanks, Yonghong _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Seemingly Similar Threads
- pointer arithmetic with address space attribute not working
- pointer arithmetic with address space attribute not working
- [LLVMdev] Methods on addrspace pointers
- trivial input provokes failed assertion in Parser.h:322
- trivial input provokes failed assertion in Parser.h:322